2
from clementine import SongInsertVetoListener
5
class RemoveDuplicatesListener(SongInsertVetoListener):
8
SongInsertVetoListener.__init__(self)
10
def init_listener(self):
11
for playlist in clementine.playlists.GetAllPlaylists():
12
playlist.AddSongInsertVetoListener(self)
14
clementine.playlists.PlaylistAdded.connect(self.playlist_added)
16
def remove_duplicates(self):
17
for playlist in clementine.playlists.GetAllPlaylists():
18
self.remove_duplicates_from(playlist)
20
def playlist_added(self, playlist_id):
21
playlist = clementine.playlists.playlist(playlist_id)
23
playlist.AddSongInsertVetoListener(self)
24
self.remove_duplicates_from(playlist)
26
def AboutToInsertSongs(self, old_songs, new_songs):
30
songs = old_songs + new_songs
32
url = self.url_for_song(song)
34
# don't veto songs without URL (possibly radios)
42
def remove_duplicates_from(self, playlist):
46
songs = playlist.GetAllSongs()
47
for i in range(0, len(songs)):
49
url = self.url_for_song(song)
51
# ignore songs without URL (possibly radios)
58
playlist.RemoveItemsWithoutUndo(indices)
60
def url_for_song(self, song):
61
if not song.filename() == "":
62
return song.filename() + ":" + str(song.beginning_nanosec())
67
script = RemoveDuplicatesListener()
69
script.init_listener()
70
script.remove_duplicates()
b'\\ No newline at end of file'