Skip to content

Commit

Permalink
Updated artist and track filters w/ invert
Browse files Browse the repository at this point in the history
  • Loading branch information
plamere committed Feb 19, 2016
1 parent 906fc4b commit 3532cc2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
25 changes: 22 additions & 3 deletions server/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,13 @@
"type" : "filter",
"description": "removes track from a stream",
"help": """ This component takes two input streams. It produces a
stream of tracks that consist of the tracks on the green input
stream with the tracks on the red input stream removed""",
stream of tracks from the green input
stream with the tracks on the red input stream removed. If the
<b>invert</b> flag is set, the filter is inverted, that is, it will
produce a stream of tracks that consist of the tracks on the green
input stream with the tracks that are <b> not </b> on the red
stream.
""",
"params": {
"true_source": {
"type" : "port",
Expand All @@ -441,6 +446,12 @@
"max_inputs" : 1,
"description": "the tracks to be removed",
},
"invert": {
"type": "bool",
"default": False,
"optional" : True,
"description": "if set, only tracks on both input streams will be passed through"
},
}
},
{
Expand All @@ -452,7 +463,9 @@
"help": """ This component takes two input streams. It produces a
stream of tracks that consist of the tracks on the green input
stream with the tracks by artists of the tracks on the red input
stream removed""",
stream removed. If the <b>invert</b> parameter is set, the sense of
the filter is reverse, i.e. the component will produce only tracks
from the green stream that are by artists on the red stream """,
"params": {
"true_source": {
"type" : "port",
Expand All @@ -468,6 +481,12 @@
"max_inputs" : 1,
"description": "the tracks (by artist) to be removed",
},
"invert": {
"type": "bool",
"default": False,
"optional" : True,
"description": "if set, only tracks by artists on the red stream will be passed through"
},
}
},
{
Expand Down
25 changes: 20 additions & 5 deletions server/plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ class TrackFilter(object):
'''
produces tracks on the true source that are not on the false source
'''
def __init__(self, true_source, false_source):
self.name = 'tracks in ' + true_source.name + ' that are not in ' + \
def __init__(self, true_source, false_source, invert=False):
prep = ' that are also in ' if invert else 'that are not in '
self.name = 'tracks in ' + true_source.name + prep + \
false_source.name
self.true_source = true_source
self.false_source = false_source
self.bad_tracks = set()
self.invert = invert
self.debug = False

def next_track(self):
while True:
Expand All @@ -121,8 +124,13 @@ def next_track(self):
while True:
track = self.true_source.next_track()
if track:
if track not in self.bad_tracks:
if self.invert and (track in self.bad_tracks):
return track
elif (not self.invert) and (track not in self.bad_tracks):
return track
else:
if self.debug:
print 'filtered out', tlib.get_tn(track)
else:
break
return None
Expand All @@ -131,12 +139,14 @@ class ArtistFilter(object):
'''
produces tracks on the true source that are not by artists the false source
'''
def __init__(self, true_source, false_source):
def __init__(self, true_source, false_source, invert=False):
self.name = 'tracks in ' + true_source.name + ' that are not by ' + \
'artists in' + false_source.name
self.true_source = true_source
self.false_source = false_source
self.bad_artists = set()
self.invert = invert
self.debug = False

def next_track(self):
while True:
Expand All @@ -151,8 +161,13 @@ def next_track(self):
track = self.true_source.next_track()
if track:
tinfo = pbl.tlib.get_track(track)
if tinfo['artist'] not in self.bad_artists:
if self.invert and (tinfo['artist'] in self.bad_artists):
return track
elif (not self.invert) and (tinfo['artist'] not in self.bad_artists):
return track
else:
if self.debug:
print 'filtered out', tlib.get_tn(track)
else:
break
return None
Expand Down

0 comments on commit 3532cc2

Please sign in to comment.