Help with a "cleanPlaylists" function #185
Answered
by
Chimildic
ladywhiskers
asked this question in
Помощь с алгоритмом
-
I have the below function which used to work, but doesn't seem to anymore. The function runs with no errors, but my playlists remain unchanged. I think that I have some syntax error or similar but I can't see where. I want each of my "genre" playlists to be shuffled, have any songs I don't like removed, and remove any songs that are in the banned tracks playlist. function cleanPlaylists (){
let savedTracks = Source.getSavedTracks();
let bannedTracks = Source.getPlaylistTracks ('banned', '4Ep4JuDSqaIvd2OzraWRSt')
// ambient playlist
let ambienttracks = Source.getPlaylistTracks ('ambient', '64El4b1kDhX3qrCA88fjyh')
Filter.removeTracks (ambienttracks,savedTracks,true)
Filter.removeTracks (ambienttracks, bannedTracks)
Order.shuffle(ambienttracks);
Filter.dedupTracks(ambienttracks);
Playlist.saveWithUpdate({
id: '64El4b1kDhX3qrCA88fjyh',
name: 'ambient',
tracks: ambienttracks,
});
// blues playlist
let bluestracks = Source.getPlaylistTracks ('blues', '0UpGdnBwPgvvlvKCbcXQYK')
Filter.removeTracks (bluestracks,savedTracks,true)
Filter.removeTracks (bluestracks, bannedTracks)
Order.shuffle(bluestracks)
Filter.dedupTracks(bluestracks);
Playlist.saveWithUpdate({
id: '0UpGdnBwPgvvlvKCbcXQYK',
name: 'blues',
tracks: bluestracks,
});
//classical playlist
let classicaltracks = Source.getPlaylistTracks ('classical', '7z1jB6Gn8AQpkF0rz5lQjE')
Filter.removeTracks (classicaltracks,savedTracks,true)
Filter.removeTracks (classicaltracks, bannedTracks)
Order.shuffle(classicaltracks);
Filter.dedupTracks(classicaltracks);
Playlist.saveWithUpdate({
id: '7z1jB6Gn8AQpkF0rz5lQjE',
name: 'classical',
tracks: classicaltracks,
});
//comedy playlist
let comedytracks = Source.getPlaylistTracks ('comedy', '63B3UYXi1ACArH4SEx1y2q')
Filter.removeTracks (comedytracks,savedTracks,true)
Filter.removeTracks (comedytracks, bannedTracks)
Filter.dedupTracks(comedytracks);
Order.shuffle(comedytracks);
Playlist.saveWithUpdate({
id: '63B3UYXi1ACArH4SEx1y2q',
name: 'comedy',
tracks: comedytracks,
});
//country playlist
let countrytracks = Source.getPlaylistTracks ('country', '1wME3PNynoAuAwKSuJaloR')
Filter.removeTracks (countrytracks,savedTracks,true)
Filter.removeTracks (countrytracks, bannedTracks)
Filter.dedupTracks(countrytracks);
Order.shuffle(countrytracks);
Playlist.saveWithUpdate({
id: '1wME3PNynoAuAwKSuJaloR',
name: 'country',
tracks: countrytracks,
});
//dance playlist
let dancetracks = Source.getPlaylistTracks ('dance', '7svSwOpZzuIrZsCCLqg6kU')
Filter.removeTracks (dancetracks,savedTracks,true)
Filter.removeTracks (dancetracks, bannedTracks)
Order.shuffle(dancetracks);
Filter.dedupTracks(dancetracks);
Playlist.saveWithUpdate({
id: '7svSwOpZzuIrZsCCLqg6kU',
name: 'dance',
tracks: dancetracks,
});
//electronic playlist
let electronictracks = Source.getPlaylistTracks ('electronic', '5r1zG9WvnKFxwHk9VmAn8A')
Filter.removeTracks (electronictracks,savedTracks,true)
Filter.removeTracks (electronictracks, bannedTracks)
Filter.dedupTracks(electronictracks);
Order.shuffle(electronictracks);
Playlist.saveWithUpdate({
id: '5r1zG9WvnKFxwHk9VmAn8A',
name: 'electronic',
tracks: electronictracks,
});
//folk playlist
let folktracks = Source.getPlaylistTracks ('folk', '1Q6m8XApK0zAbwVH0ectYT')
Filter.removeTracks (folktracks,savedTracks,true)
Filter.removeTracks (folktracks, bannedTracks)
Filter.dedupTracks(folktracks);
Order.shuffle(folktracks);
Playlist.saveWithUpdate({
id: '1Q6m8XApK0zAbwVH0ectYT',
name: 'folk',
tracks: folktracks,
});
//hip hop playlist
let hiphoptracks = Source.getPlaylistTracks ('hip hop', '6x1Q2oWb9H9GRMWfNSQ4eO')
Filter.removeTracks (hiphoptracks,savedTracks,true)
Filter.removeTracks (hiphoptracks, bannedTracks)
Filter.dedupTracks(hiphoptracks);
Order.shuffle(hiphoptracks);
Playlist.saveWithUpdate({
id: '6x1Q2oWb9H9GRMWfNSQ4eO',
name: 'hip hop',
tracks: hiphoptracks,
});
//industrial playlist
let industrialtracks = Source.getPlaylistTracks ('industrial', '2NxGvboWamKpj8i15G9kBy')
Filter.removeTracks (industrialtracks,savedTracks,true)
Filter.removeTracks (industrialtracks, bannedTracks)
Filter.dedupTracks(industrialtracks);
Order.shuffle(industrialtracks);
Playlist.saveWithUpdate({
id: '2NxGvboWamKpj8i15G9kBy',
name: 'industrial',
tracks: industrialtracks,
});
//jazz playlist
let jazztracks = Source.getPlaylistTracks ('jazz', '2Akowh50Sw4eCSASAESvHc')
Filter.removeTracks (jazztracks,savedTracks,true)
Filter.removeTracks (jazztracks, bannedTracks)
Filter.dedupTracks(jazztracks);
Order.shuffle(jazztracks);
Playlist.saveWithUpdate({
id: '2Akowh50Sw4eCSASAESvHc',
name: 'jazz',
tracks: jazztracks,
});
//k-pop playlist
let kpoptracks = Source.getPlaylistTracks ('k-pop', '1jC7leQk3c43KDNtyziGAZ')
Filter.removeTracks (kpoptracks,savedTracks,true)
Filter.removeTracks (kpoptracks, bannedTracks)
Filter.dedupTracks(kpoptracks);
Order.shuffle(kpoptracks);
Playlist.saveWithUpdate({
id: '1jC7leQk3c43KDNtyziGAZ',
name: 'k-pop',
tracks: kpoptracks,
});
//metal playlist
let metaltracks = Source.getPlaylistTracks('metal', '3cTHe5TB8FwKrZIE5tWPLM');
Filter.removeTracks(metaltracks, savedTracks, true);
Filter.removeTracks (metaltracks, bannedTracks)
Order.shuffle(metaltracks);
Filter.dedupTracks(metaltracks);
Playlist.saveWithUpdate({
id: '3cTHe5TB8FwKrZIE5tWPLM',
tracks: metaltracks,
});
//pop playlist
let poptracks = Source.getPlaylistTracks ('pop', '62CddfRp98yf0IAKDCj9kg')
Filter.removeTracks (poptracks,savedTracks,true)
Filter.removeTracks (poptracks, bannedTracks)
Filter.dedupTracks(poptracks);
Order.shuffle(poptracks);
Playlist.saveWithUpdate({
id: '62CddfRp98yf0IAKDCj9kg',
name: 'pop',
tracks: poptracks,
});
//psychedelic playlist
let psychtracks = Source.getPlaylistTracks ('psychedelic', '2bGI851Hi3Cu3L4IULWVhZ')
Filter.removeTracks (psychtracks,savedTracks,true)
Filter.removeTracks (psychtracks, bannedTracks)
Filter.dedupTracks(psychtracks);
Order.shuffle(psychtracks);
Playlist.saveWithUpdate({
id: '2bGI851Hi3Cu3L4IULWVhZ',
name: 'psychedelic',
tracks: psychtracks,
});
//punk playlist
let punktracks = Source.getPlaylistTracks ('punk', '4J1joP0DTl95V0zCNLrPx7')
Filter.removeTracks (punktracks,savedTracks,true)
Filter.removeTracks (punktracks, bannedTracks)
Filter.dedupTracks(punktracks);
Order.shuffle(punktracks);
Playlist.saveWithUpdate({
id: '4J1joP0DTl95V0zCNLrPx7',
name: 'punk',
tracks: punktracks,
});
//r&b playlist
let rbtracks = Source.getPlaylistTracks ('r&b', '77EzpASw5ac94h9ZelvDT2')
Filter.removeTracks (rbtracks,savedTracks,true)
Filter.removeTracks (rbtracks, bannedTracks)
Filter.dedupTracks(rbtracks);
Order.shuffle(rbtracks);
Playlist.saveWithUpdate({
id: '77EzpASw5ac94h9ZelvDT2',
name: 'r&b',
tracks: rbtracks,
});
//regional music playlist
let regionaltracks = Source.getPlaylistTracks ('regional music', '75aIk2CdenbQaGVqGieXcz')
Filter.removeTracks (regionaltracks,savedTracks,true)
Filter.removeTracks (regionaltracks, bannedTracks)
Filter.dedupTracks(regionaltracks);
Order.shuffle(regionaltracks);
Playlist.saveWithUpdate({
id: '75aIk2CdenbQaGVqGieXcz',
name: 'regional music',
tracks: regionaltracks,
});
//rock playlist
let rocktracks = Source.getPlaylistTracks ('rock', '1VpM1XzTfC1pqtt3n3KfzS')
Filter.removeTracks (rocktracks,savedTracks,true)
Filter.removeTracks (rocktracks, bannedTracks)
Filter.dedupTracks(rocktracks);
Order.shuffle(rocktracks);
Playlist.saveWithUpdate({
id: '1VpM1XzTfC1pqtt3n3KfzS',
name: 'rock',
tracks: rocktracks,
});
//ska playlist
let skatracks = Source.getPlaylistTracks ('ska', '6keS7FMAYAnB2f9zOOmoe0')
Filter.removeTracks (skatracks,savedTracks,true)
Filter.removeTracks (skatracks, bannedTracks)
Filter.dedupTracks(skatracks);
Order.shuffle(skatracks);
Playlist.saveWithUpdate({
id: '6keS7FMAYAnB2f9zOOmoe0',
name: 'ska',
tracks: skatracks,
});
//soundtracks playlist
let soundtrackstracks = Source.getPlaylistTracks ('soundtracks', '1xSddmzIL7kBW6ye1SXDfL')
Filter.removeTracks (soundtrackstracks,savedTracks,true)
Filter.removeTracks (soundtrackstracks, bannedTracks)
Filter.dedupTracks(soundtrackstracks);
Order.shuffle(soundtrackstracks);
Playlist.saveWithUpdate({
id: '1xSddmzIL7kBW6ye1SXDfL',
name: 'soundtracks',
tracks: soundtrackstracks,
});
} |
Beta Was this translation helpful? Give feedback.
Answered by
Chimildic
May 3, 2022
Replies: 1 comment 5 replies
-
Do you run function in editor mode? If there are no errors, should works. I did refactoring in order to do more readable code. function cleanPlaylists() {
let savedTracks = Cache.read('SavedTracks');
let banTracks = Source.getPlaylistTracks('', '4Ep4JuDSqaIvd2OzraWRSt');
update('64El4b1kDhX3qrCA88fjyh', 'ambient');
update('0UpGdnBwPgvvlvKCbcXQYK', 'blues');
update('7z1jB6Gn8AQpkF0rz5lQjE', 'classical');
update('63B3UYXi1ACArH4SEx1y2q', 'comedy');
update('1wME3PNynoAuAwKSuJaloR', 'country');
update('7svSwOpZzuIrZsCCLqg6kU', 'dance');
update('5r1zG9WvnKFxwHk9VmAn8A', 'electronic');
update('1Q6m8XApK0zAbwVH0ectYT', 'folk');
update('6x1Q2oWb9H9GRMWfNSQ4eO', 'hip hop');
update('2NxGvboWamKpj8i15G9kBy', 'industrial');
update('2Akowh50Sw4eCSASAESvHc', 'jazz');
update('1jC7leQk3c43KDNtyziGAZ', 'k-pop');
update('3cTHe5TB8FwKrZIE5tWPLM', 'metal');
update('62CddfRp98yf0IAKDCj9kg', 'pop');
update('2bGI851Hi3Cu3L4IULWVhZ', 'psychedelic');
update('4J1joP0DTl95V0zCNLrPx7', 'punk');
update('77EzpASw5ac94h9ZelvDT2', 'r&b');
update('75aIk2CdenbQaGVqGieXcz', 'regional music');
update('1VpM1XzTfC1pqtt3n3KfzS', 'rock');
update('6keS7FMAYAnB2f9zOOmoe0', 'ska');
update('1xSddmzIL7kBW6ye1SXDfL', 'soundtracks');
function update(id, name) {
let tracks = Source.getPlaylistTracks('', id)
Filter.removeTracks(tracks, savedTracks, true)
Filter.removeTracks(tracks, banTracks)
Filter.dedupTracks(tracks);
Order.shuffle(tracks);
Playlist.saveWithUpdate({
id: id,
name: name,
tracks: tracks,
});
}
} |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
ladywhiskers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you run function in editor mode? If there are no errors, should works.
I did refactoring in order to do more readable code.