public function doGet() { Songs::wipeOldPreviews(); FileServer::removeUnused(); FileServer::removeDead(); $limit = 30; while ($limit-- > 0) { set_time_limit(30); (new SelectQuery(TSongs::_NAME))->select(TSongs::FILE_NAME, TSongs::FILE_ID, TSongs::ID)->where(TSongs::PEAKS_ID . " IS NULL")->where(TSongs::FILE_ID . " IS NOT NULL")->limit(1)->eachRow(function ($row) { Logger::printf("Creating peaks for file: %s", $row[TSongs::FILE_NAME]); $peaks = WaveformGenerator::generate(FileServer::getFileUsingId($row[TSongs::FILE_ID])); $file_id = FileServer::registerByContent(json_encode($peaks), "application/json"); SongDao::updateSongUsingId($row[TSongs::ID], [TSongs::PEAKS_ID => $file_id]); }); sleep(1); } }
/** * @param $play_count * @return mixed */ public function updateAndGetPlayCount($play_count) { if ($play_count > $this->track_data[TSongs::T_PLAYED]) { SongDao::updateSongUsingId($this->track_id, ["times_played" => $play_count]); return $play_count; } return $this->track_data[TSongs::T_PLAYED]; }
public static function wipeOldPreviews() { foreach (SongDao::getListOfUnusedPreviews() as $song) { Logger::printf("Wiping old track preview (file id %s)", $song[TSongs::PREVIEW_ID]); FileServer::unregister($song[TSongs::PREVIEW_ID]); SongDao::updateSongUsingId($song[TSongs::ID], [TSongs::PREVIEW_ID => null]); } }