app/Services/Media.php
/**
     * Sync media using a watch record.
     *
     * @param WatchRecordInterface $record      The watch record.
     * @param SyncMedia|null       $syncCommand The SyncMedia command object, to log to console if executed by artisan.
     */
Sync media using a watch record.
@param WatchRecordInterface $record      The watch record.
@param SyncMedia|null       $syncCommand The SyncMedia command object, to log to console if executed by artisan.
Sync media using a watch record . @param WatchRecordInterface $record The watch record . @param SyncMedia|null $syncCommand The SyncMedia command object to log to console if executed by artisan .
public function syncByWatchRecord(WatchRecordInterface $record, SyncMedia $syncCommand = null)
    {
        Log::info("New watch record received: '$record'");
        $path = $record->getPath();
        if ($record->isFile()) {
            Log::info("'$path' is a file.");
            if ($record->isDeleted()) {
                if ($song = Song::byPath($path)) {
                    $song->delete();
                    Log::info("$path deleted.");
                    event(new LibraryChanged());
                } else {
                    Log::info("$path doesn't exist in our database--skipping.");
                }
            }
            elseif ($record->isNewOrModified()) {
                $result = (new File($path))->sync($this->tags);
                Log::info($result instanceof Song ? "Synchronized $path" : "Invalid file $path");
            }
            return;
        }
        Log::info("'$path' is a directory.");
        if ($record->isDeleted()) {
            if ($count = Song::inDirectory($path)->delete()) {
                Log::info("Deleted $count song(s) under $path");
                event(new LibraryChanged());
            } else {
                Log::info("$path is empty--no action needed.");
            }
        } elseif ($record->isNewOrModified()) {
            foreach ($this->gatherFiles($path) as $file) {
                (new File($file))->sync($this->tags);
            }
            Log::info("Synced all song(s) under $path");
        }
    }
public function syncByWatchRecord ( WatchRecordInterface $ record , SyncMedia $ syncCommand = null ) { Log :: info ( " New watch record received: ' $ record ' " ) ; $ path = $ record -> getPath ( ) ; if ( $ record -> isFile ( ) ) { Log :: info ( " ' $ path ' is a file. " ) ; if ( $ record -> isDeleted ( ) ) { if ( $ song = Song :: byPath ( $ path ) ) { $ song -> delete ( ) ; Log :: info ( " $ path  deleted. " ) ; event ( new LibraryChanged ( ) ) ; } else { Log :: info ( " $ path  doesn't exist in our database--skipping. " ) ; } } elseif ( $ record -> isNewOrModified ( ) ) { $ result = ( new File ( $ path ) ) -> sync ( $ this -> tags ) ; Log :: info ( $ result instanceof Song ? " Synchronized  $ path " : " Invalid file  $ path " ) ; } return ; } Log :: info ( " ' $ path ' is a directory. " ) ; if ( $ record -> isDeleted ( ) ) { if ( $ count = Song :: inDirectory ( $ path ) -> delete ( ) ) { Log :: info ( " Deleted  $ count  song(s) under  $ path " ) ; event ( new LibraryChanged ( ) ) ; } else { Log :: info ( " $ path  is empty--no action needed. " ) ; } } elseif ( $ record -> isNewOrModified ( ) ) { foreach ( $ this -> gatherFiles ( $ path ) as $ file ) { ( new File ( $ file ) ) -> sync ( $ this -> tags ) ; } Log :: info ( " Synced all song(s) under  $ path " ) ; } }
Sync media using a watch record.
Sync media using a watch record .
// If the file has been deleted... // ...and it has a record in our database, remove it. // Otherwise, it's a new or changed file. Try to sync it in. // File format etc. will be handled by File::sync(). // Record is a directory. // The directory is removed. We remove all songs in it.