Skip to content

Commit

Permalink
Added Artist DeDup
Browse files Browse the repository at this point in the history
  • Loading branch information
plamere committed Feb 15, 2016
1 parent f7cf348 commit e8287ce
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
18 changes: 18 additions & 0 deletions server/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@
},
}
},
{
"name" : "ArtistDeDup",
"display": "artist de-dup",
"class": plugs.ArtistDeDup,
"type" : "filter",
"description": "Ensure only unique artists appear in the track stream",
"help" : """ This component will remove any tracks with duplicate
artists from the stream. """,
"params": {
"source": {
"type" : "port",
"optional" : False,
"port": "green",
"max_inputs": 1,
"description": "the source of the tracks",
},
}
},
{
"name" : "comment",
"display": "comment",
Expand Down
53 changes: 47 additions & 6 deletions server/plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,37 @@ def get_day_of_week():
day = now().weekday()
return days[day]

class ArtistDeDup(object):
'''
Remove any duplicate artists in the stream
:param source: the stream source
'''

def __init__(self, source):
self.name = 'artist dedupped ' + source.name
self.source = source
self.history = set()

def next_track(self):
track = None
while True:
track = self.source.next_track()
if track:
tinfo = pbl.tlib.get_track(track)
artist_name = '(none)'
if 'artist' in tinfo:
artist_name = tinfo['artist']

if artist_name in self.history:
continue
else:
self.history.add(artist_name)
break
else:
break
return track

if __name__ == '__main__':

def date_to_epoch(date):
Expand All @@ -951,9 +982,19 @@ def date_to_epoch(date):
save = PlaylistSaveToNew(p1, 'test', 'day-of-month')
pbl.show_source(save)

dec1 = date_to_epoch("2015-12-01")
src = DatedPlaylistSource("extender test", None, 'plamere',
order_by_date_added=False,
tracks_added_since=-1, tracks_added_before=dec1)

pbl.show_source(src)
if False:
dec1 = date_to_epoch("2015-12-01")
src = DatedPlaylistSource("extender test", None, 'plamere',
order_by_date_added=False,
tracks_added_since=-1, tracks_added_before=dec1)
pbl.show_source(src)

if True:
print 'with dedup'
src = pbl.PlaylistSource("extender test", None, 'plamere')
src = ArtistDeDup(src)
pbl.show_source(src)

print 'no dedup'
src = pbl.PlaylistSource("extender test", None, 'plamere')
pbl.show_source(src)

0 comments on commit e8287ce

Please sign in to comment.