/** * Passes metadata from $file_path into $query builder. * If $file_path is invalid audio file throws exception. * * @param $file_path * @param UpdateQuery $query * @param string $file_name to be used for file type detection */ private function loadMetadataFromSongIntoQuery($file_path, UpdateQuery $query, $file_name = null) { /** @var Metadata $metadata */ $metadata = FFProbe::read($file_path, $file_name)->getOrThrow(InvalidAudioFileException::class); $query->set(TSongs::T_ARTIST, $metadata->meta_artist)->set(TSongs::T_YEAR, $metadata->meta_date)->set(TSongs::T_TITLE, $metadata->meta_title)->set(TSongs::T_NUMBER, $metadata->meta_track_number)->set(TSongs::DISC, $metadata->meta_disc_number)->set(TSongs::BITRATE, $metadata->bitrate)->set(TSongs::LENGTH, $metadata->duration)->set(TSongs::A_ARTIST, $metadata->meta_album_artist)->set(TSongs::T_GENRE, $metadata->meta_genre)->set(TSongs::T_ALBUM, $metadata->meta_album)->set(TSongs::T_COMMENT, $metadata->meta_comment)->set(TSongs::IS_COMP, $metadata->is_compilation)->set(TSongs::FORMAT, $metadata->format_name); }
public static function changeCover($song_id, $cover_file) { $song_ids = explode(",", $song_id); $song_objects = (new SelectQuery(TSongs::_NAME))->where(TSongs::ID, $song_ids)->where(TSongs::USER_ID, self::$me->getId())->fetchAll(); // Delete exists covers foreach ($song_objects as $song) { if ($song[TSongs::C_SMALL_ID]) { FileServer::unregister($song[TSongs::C_SMALL_ID]); } if ($song[TSongs::C_MID_ID]) { FileServer::unregister($song[TSongs::C_MID_ID]); } if ($song[TSongs::C_BIG_ID]) { FileServer::unregister($song[TSongs::C_BIG_ID]); } } $covers = FFProbe::readTempCovers($cover_file)->getOrThrow(ControllerException::class, "Image file is corrupted"); $query = (new UpdateQuery(TSongs::_NAME))->where(TSongs::ID, $song_ids)->where(TSongs::USER_ID, self::$me->getId()); $full_cover_id = FileServer::register($covers[0]); $middle_cover_id = FileServer::register($covers[1]); $small_cover_id = FileServer::register($covers[2]); $query->set(TSongs::C_SMALL_ID, $small_cover_id)->set(TSongs::C_MID_ID, $middle_cover_id)->set(TSongs::C_BIG_ID, $full_cover_id); $query->returning(implode(",", [TSongs::ID, TSongs::C_SMALL_ID, TSongs::C_MID_ID, TSongs::C_BIG_ID])); return $query->fetchAll(); }