Skip to content

Commit

Permalink
finessed discogs artist matching; added artwork refresh CLI
Browse files Browse the repository at this point in the history
fixes #418
  • Loading branch information
RocketMan committed Aug 31, 2023
1 parent f800b90 commit ecd0c1a
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 24 deletions.
1 change: 1 addition & 0 deletions config/controller_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'export' => ZK\Controllers\ExportPlaylist::class,
'afile' => ZK\Controllers\ExportAfile::class,
'opensearch' => ZK\Controllers\OpenSearch::class,
'artwork' => ZK\Controllers\ArtworkControl::class,
'cache' => ZK\Controllers\CacheControl::class,
'daily' => ZK\Controllers\RunDaily::class,
'print' => ZK\Controllers\PrintTags::class,
Expand Down
93 changes: 93 additions & 0 deletions controllers/ArtworkControl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Zookeeper Online
*
* @author Jim Mason <jmason@ibinx.com>
* @copyright Copyright (C) 1997-2023 Jim Mason <jmason@ibinx.com>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* version 3, along with this program. If not, see
* http://www.gnu.org/licenses/
*
*/

namespace ZK\Controllers;

use ZK\Engine\Engine;
use ZK\Engine\IArtwork;
use ZK\Engine\ILibrary;
use ZK\Engine\IPlaylist;
use ZK\Engine\PlaylistEntry;
use ZK\Engine\PlaylistObserver;

use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;

class ArtworkControl implements IController {
protected $verbose = false;

protected function refreshList($playlist) {
$count = 0;
$imageApi = Engine::api(IArtwork::class);
Engine::api(IPlaylist::class)->getTracksWithObserver($playlist,
(new PlaylistObserver())->on('spin', function($entry) use($imageApi, &$count) {
if(!$entry->getTag() && $entry->getCreated()) {
$artist = PlaylistEntry::swapNames($entry->getArtist());
if($this->verbose)
echo " deleting $artist\n";
$imageApi->deleteArtistArt($artist);
$count++;
}
})
);

if($count) {
echo "$count images queued for reload (please wait)\n";
PushServer::lazyLoadImages($playlist);
} else
echo "No artist artwork found. No change.\n";
}

public function processRequest() {
if(php_sapi_name() != "cli") {
http_response_code(400);
return;
}

// The heavy lifting is done by the push notification server.
// If it is not enabled, there is no point in proceeding.
if(!Engine::param('push_enabled', true)) {
echo "Push notification is disabled. No change.\n";
return;
}

$this->verbose = $_REQUEST["verbose"] ?? false;

switch($_REQUEST["action"] ?? "") {
case "reload":
if($tag = $_REQUEST["tag"] ?? null) {
echo "Album queued for reload (please wait)\n";
PushServer::lazyReloadAlbum($tag, $_REQUEST["master"] ?? 1);
break;
} else if($list = $_REQUEST["list"] ?? null) {
$this->refreshList($list);
break;
}
// fall through...
default:
echo "Usage: zk artwork:reload {tag|list}=id [master=0]\n";
break;
}
}
}
Loading

0 comments on commit ecd0c1a

Please sign in to comment.