app/Models/File.php
/**
     * Sync the song with all available media info against the database.
     *
     * @param array $tags  The (selective) tags to sync (if the song exists)
     * @param bool  $force Whether to force syncing, even if the file is unchaged
     *
     * @return bool|Song A Song object on success,
     *                   true if file exists but is unmodified,
     *                   or false on an error.
     */
Sync the song with all available media info against the database.
@param array $tags  The (selective) tags to sync (if the song exists)
@param bool  $force Whether to force syncing, even if the file is unchaged

@return bool|Song A Song object on success,
true if file exists but is unmodified,
or false on an error.
Sync the song with all available media info against the database . @param array $tags The ( selective ) tags to sync ( if the song exists ) @param bool $force Whether to force syncing even if the file is unchaged @return bool|Song A Song object on success true if file exists but is unmodified or false on an error .
public function sync($tags, $force = false)
    {
        if (!$this->isNewOrChanged() && !$force) {
            return true;
        }
        if (!$info = $this->getInfo()) {
            return false;
        }
        if ($this->isChanged() || $force) {
            $info = array_intersect_key($info, array_flip($tags));
            $artist = isset($info['artist']) ? Artist::get($info['artist']) : $this->song->album->artist;
            $album = isset($info['album']) ? Album::get($artist, $info['album']) : $this->song->album;
        } else {
            $album = Album::get(Artist::get($info['artist']), $info['album']);
        }
        if (!empty($info['cover']) && !$album->has_cover) {
            try {
                $album->generateCover($info['cover']);
            } catch (Exception $e) {
                Log::error($e);
            }
        }
        $info['album_id'] = $album->id;
        array_forget($info, ['artist', 'album', 'cover']);
        $song = Song::updateOrCreate(['id' => $this->hash], $info);
        $song->save();
        return $song;
    }
public function sync ( $ tags , $ force = false ) { if ( ! $ this -> isNewOrChanged ( ) && ! $ force ) { return true ; } if ( ! $ info = $ this -> getInfo ( ) ) { return false ; } if ( $ this -> isChanged ( ) || $ force ) { $ info = array_intersect_key ( $ info , array_flip ( $ tags ) ) ; $ artist = isset ( $ info [ 'artist' ] ) ? Artist :: get ( $ info [ 'artist' ] ) : $ this -> song -> album -> artist ; $ album = isset ( $ info [ 'album' ] ) ? Album :: get ( $ artist , $ info [ 'album' ] ) : $ this -> song -> album ; } else { $ album = Album :: get ( Artist :: get ( $ info [ 'artist' ] ) , $ info [ 'album' ] ) ; } if ( ! empty ( $ info [ 'cover' ] ) && ! $ album -> has_cover ) { try { $ album -> generateCover ( $ info [ 'cover' ] ) ; } catch ( Exception $ e ) { Log :: error ( $ e ) ; } } $ info [ 'album_id' ] = $ album -> id ; array_forget ( $ info , [ 'artist' , 'album' , 'cover' ] ) ; $ song = Song :: updateOrCreate ( [ 'id' => $ this -> hash ] , $ info ) ; $ song -> save ( ) ; return $ song ; }
Sync the song with all available media info against the database.
Sync the song with all available media info against the database .
// If the file is not new or changed and we're not forcing update, don't do anything. // If the file is invalid, don't do anything. // This is a changed file, or the user is forcing updates. // We cater for the tags by removing those not specified. // Remove these values from the info array, so that we can just use the array as model's input data.