Skip to content

Commit

Permalink
When importing online libraries, and there's more than one account pe…
Browse files Browse the repository at this point in the history
…r service, store the account used to import a track in the track object's comment.
  • Loading branch information
mherger committed Sep 20, 2020
1 parent 5949ad5 commit 21270bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Slim/Plugin/OnlineLibraryBase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ sub initOnlineTracksTable { if (main::SCANNER && !$main::wipe) {
$dbh->do(qq{
CREATE TEMPORARY TABLE online_tracks (url TEXT PRIMARY KEY);
});

$dbh->do('DROP TABLE IF EXISTS online_mapping');
$dbh->do(qq{
CREATE TABLE online_mapping (id INTEGER PRIMARY KEY, account char(128));
});
} }

sub deleteRemovedTracks { if (main::SCANNER && !$main::wipe) {
Expand Down Expand Up @@ -108,11 +113,13 @@ sub isImportEnabled {
}

sub storeTracks {
my ($class, $tracks, $libraryId) = @_;
my ($class, $tracks, $libraryId, $accountId) = @_;

return unless $tracks && ref $tracks;

my $dbh = Slim::Schema->dbh();
my $checkComment_sth = $dbh->prepare_cached("SELECT id FROM comments WHERE track = ? AND value = ?") if $accountId;
my $insertAccountInComment_sth = $dbh->prepare_cached("INSERT OR IGNORE INTO comments (track, value) VALUES (?, ?)") if $accountId;
my $insertTrackInLibrary_sth = $dbh->prepare_cached("INSERT OR IGNORE INTO library_track (library, track) VALUES (?, ?)") if $libraryId;
my $insertTrackInTempTable_sth = $dbh->prepare_cached("INSERT OR IGNORE INTO online_tracks (url) VALUES (?)") if main::SCANNER && !$main::wipe;

Expand All @@ -127,6 +134,15 @@ sub storeTracks {
integrateRemote => 1,
});

if ($checkComment_sth) {
$checkComment_sth->execute($trackObj->id, $accountId);
my $data = $checkComment_sth->fetchall_arrayref([0]);

if (!$data || !ref $data || !scalar @$data) {
$insertAccountInComment_sth->execute($trackObj->id, $accountId);
}
}

if ($insertTrackInLibrary_sth) {
$insertTrackInLibrary_sth->execute($libraryId, $trackObj->id);
}
Expand Down
4 changes: 3 additions & 1 deletion Slim/Plugin/WiMP/Importer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ sub scanAlbums { if (main::SCANNER) {
main::INFOLOG && $log->is_info && $log->info("Reading albums for $account...");
$progress->update(string('PLUGIN_TIDAL_PROGRESS_READ_ALBUMS', $account));

my $accountName = "tidal:$account" if scalar @$accounts > 1;

my $albumsResponse = $http->get(Slim::Networking::SqueezeNetwork::Sync->url(sprintf(ALBUMS_URL, $account)));
my $albums = eval { from_json($albumsResponse->content) } || [];

Expand All @@ -111,7 +113,7 @@ sub scanAlbums { if (main::SCANNER) {

$class->storeTracks([
map { _prepareTrack($_, $album) } @$tracks
]);
], undef, $accountName);
}

Slim::Schema->forceCommit;
Expand Down

0 comments on commit 21270bc

Please sign in to comment.