Skip to content

Commit

Permalink
Added artist separation component
Browse files Browse the repository at this point in the history
  • Loading branch information
plamere committed Feb 17, 2016
1 parent 586dc06 commit 3a9456b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
35 changes: 35 additions & 0 deletions server/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,41 @@
},
}
},
{
"name" : "ArtistSeparation",
"display": "artist separation",
"class": plugs.ArtistSeparation,
"type" : "filter",
"description": "Enforces a specified separation of artists in the track stream",
"help" : """ This component will guarantee that artists will not
appear closer together than the given <b>min separation</b> in the
track stream. If <b>reorder</b> is set, then tracks may be reordered
to enforce the separation, otherwise, if <b>reorder</b> is not set,
then offending tracks are removed from the stream.""",
"params": {
"source": {
"type" : "port",
"optional" : False,
"port": "green",
"max_inputs": 1,
"description": "the source of the tracks",
},
"min_separation": {
"type" : "number",
"optional" : True,
"default" : 4,
"display" : "minimum artist separation",
"description": "minimum number of tracks between tracks by the same artist"
},
"reorder": {
"type" : "bool",
"optional" : True,
"default" : True,
"display": "reorder",
"description": "if true, tracks may be reordered to enforce artist separation, otherwise, offendind tracks are simply deleted from the stream",
},
}
},
{
"name" : "comment",
"display": "comment",
Expand Down
60 changes: 60 additions & 0 deletions server/plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,66 @@ def next_track(self):
break
return track

class ArtistSeparation(object):
'''
enforces a minimum separation of artists
'''

def __init__(self, source, min_separation=4, reorder=True):
self.name = 'artist separated ' + source.name
self.source = source
self.history = []
self.lookaside = []
self.min_separation = min_separation
self.reorder = reorder

def _separation(self, artist):
for i, partist in enumerate(reversed(self.history)):
if artist == partist:
return i
return -1

def _get_artist_name(self, track):
tinfo = pbl.tlib.get_track(track)
artist_name = '(none)'
if 'artist' in tinfo:
artist_name = tinfo['artist']
return artist_name

def _check_from_lookaside(self):
for track in self.lookaside:
artist_name = self._get_artist_name(track)
sep = self._separation(artist_name)
if sep >= self.min_separation or sep == -1:
self.lookaside.remove(track)
return track
return None


def _next_track(self):
track = self._check_from_lookaside()
if track == None:
track = self.source.next_track()
return track

def next_track(self):
track = None
while True:
track = self._next_track()
if track:
artist_name = self._get_artist_name(track)
sep = self._separation(artist_name)
if sep >= self.min_separation or sep == -1:
self.history.append(artist_name)
break
else:
if self.reorder:
self.lookaside.append(track)
continue
else:
break
return track

if __name__ == '__main__':

def date_to_epoch(date):
Expand Down
3 changes: 2 additions & 1 deletion web/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ <h2> Available Components</h2>
<div class="container-fluid col-sm-offset-2 col-sm-8">
<h2> Version Info </h2>

<h3> Alpha V3.3 - February 15, 2016 </h3>
<h3> Alpha V3.3 - February 15,17 2016 </h3>
<ul>
<li> Added component detail page (accessible via the about page) </li>
<li> Added Artist De-Dup component</li>
<li> Added Artist Separation component</li>
</ul>
<h3> Alpha V3.2 - February 14, 2016 </h3>
<ul>
Expand Down

0 comments on commit 3a9456b

Please sign in to comment.