app/Services/Media.php
/**
     * Sync the media. Oh sync the media.
     *
     * @param string|null $path
     * @param array       $tags        The tags to sync.
     *                                 Only taken into account for existing records.
     *                                 New records will have all tags synced in regardless.
     * @param bool        $force       Whether to force syncing even unchanged files
     * @param SyncMedia   $syncCommand The SyncMedia command object, to log to console if executed by artisan.
     */
Sync the media. Oh sync the media.
@param string|null $path
@param array       $tags        The tags to sync.
Only taken into account for existing records.
New records will have all tags synced in regardless.
@param bool        $force       Whether to force syncing even unchanged files
@param SyncMedia   $syncCommand The SyncMedia command object, to log to console if executed by artisan.
Sync the media . Oh sync the media . @param string|null $path @param array $tags The tags to sync . Only taken into account for existing records . New records will have all tags synced in regardless . @param bool $force Whether to force syncing even unchanged files @param SyncMedia $syncCommand The SyncMedia command object to log to console if executed by artisan .
public function sync($path = null, $tags = [], $force = false, SyncMedia $syncCommand = null)
    {
        if (!app()->runningInConsole()) {
            set_time_limit(env('APP_MAX_SCAN_TIME', 600));
        }
        $path = $path ?: Setting::get('media_path');
        $this->setTags($tags);
        $results = [
            'good' => [], 
            'bad' => [], 
            'ugly' => [], 
        ];
        $getID3 = new getID3();
        foreach ($this->gatherFiles($path) as $file) {
            $file = new File($file, $getID3);
            $song = $file->sync($this->tags, $force);
            if ($song === true) {
                $results['ugly'][] = $file;
            } elseif ($song === false) {
                $results['bad'][] = $file;
            } else {
                $results['good'][] = $file;
            }
            if ($syncCommand) {
                $syncCommand->logToConsole($file->getPath(), $song);
            }
        }
        $hashes = array_map(function ($f) {
            return self::getHash($f->getPath());
        }, array_merge($results['ugly'], $results['good']));
        Song::whereNotIn('id', $hashes)->delete();
        event(new LibraryChanged());
    }
public function sync ( $ path = null , $ tags = [ ] , $ force = false , SyncMedia $ syncCommand = null ) { if ( ! app ( ) -> runningInConsole ( ) ) { set_time_limit ( env ( 'APP_MAX_SCAN_TIME' , 600 ) ) ; } $ path = $ path ? : Setting :: get ( 'media_path' ) ; $ this -> setTags ( $ tags ) ; $ results = [ 'good' => [ ] , 'bad' => [ ] , 'ugly' => [ ] , ] ; $ getID3 = new getID3 ( ) ; foreach ( $ this -> gatherFiles ( $ path ) as $ file ) { $ file = new File ( $ file , $ getID3 ) ; $ song = $ file -> sync ( $ this -> tags , $ force ) ; if ( $ song === true ) { $ results [ 'ugly' ] [ ] = $ file ; } elseif ( $ song === false ) { $ results [ 'bad' ] [ ] = $ file ; } else { $ results [ 'good' ] [ ] = $ file ; } if ( $ syncCommand ) { $ syncCommand -> logToConsole ( $ file -> getPath ( ) , $ song ) ; } } $ hashes = array_map ( function ( $ f ) { return self :: getHash ( $ f -> getPath ( ) ) ; } , array_merge ( $ results [ 'ugly' ] , $ results [ 'good' ] ) ) ; Song :: whereNotIn ( 'id' , $ hashes ) -> delete ( ) ; event ( new LibraryChanged ( ) ) ; }
Sync the media.
Sync the media .
// Updated or added files // Bad files // Unmodified files // Delete non-existing songs. // Trigger LibraryChanged, so that TidyLibrary handler is fired to, erm, tidy our library.