error("Media path hasn't been configured. Exiting.");
return;
}
if (!$record = $this->argument('record')) {
$this->syncAll();
return;
}
$this->syngle($record);
}
/**
* Sync all files in the configured media path.
*/
protected function syncAll()
{
$this->info('Koel syncing started. All we need now is just a little patience…');
Media::sync(null, $this);
$this->output->writeln("Completed! {$this->synced} new or updated song(s), "
."{$this->ignored} unchanged song(s), "
."and {$this->invalid} invalid file(s).");
}
/**
* SYNc a sinGLE file or directory. See my awesome pun?
*
* @param string|FSWatchRecord $record An fswatch record, in this format:
* " ::::"
* The fswatch command should look like this:
* ``` bash
* $ fswatch -0x --event-flag-separator="::" $MEDIA_PATH \
* | xargs -0 -n1 -I record php artisan koel:sync record
* ```
*
* @link https://github.com/emcrisostomo/fswatch/wiki/How-to-Use-fswatch
*/
public function syngle($record)
{
Media::syncFSWatchRecord($record, $this);
}
/**
* Log a song's sync status to console.
*/
public function logToConsole($path, $result)
{
$name = basename($path);
if ($result === true) {
if ($this->option('verbose')) {
$this->line("$name has no changes – ignoring");
}
++$this->ignored;
} elseif ($result === false) {
if ($this->option('verbose')) {
$this->error("$name is not a valid media file");
}
++$this->invalid;
} else {
if ($this->option('verbose')) {
$this->info("$name synced");
}
++$this->synced;
}
}
}