Skip to content

Commit

Permalink
Added by_name flag to the track filter
Browse files Browse the repository at this point in the history
  • Loading branch information
plamere committed Feb 19, 2016
1 parent 0d8ccf7 commit ce8cbd2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 11 additions & 1 deletion server/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@
"type" : "filter",
"description": "Remove any duplicate tracks in the stream",
"help" : """ This component will remove any duplicate tracks from
the stream. If <b> By Name </b> is set, then tracks dedupped by
the stream.
If <b> By Name </b> is set, then tracks dedupped by
artist and title, otherwise, they are dedupped based upon their
track id""",
"params": {
Expand Down Expand Up @@ -430,6 +431,8 @@
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.
If <b> By Name </b> is set, then tracks are matched by name in
addition to the regular ID match
""",
"params": {
"true_source": {
Expand All @@ -452,6 +455,13 @@
"optional" : True,
"description": "if set, only tracks on both input streams will be passed through"
},
"by_name": {
"display" : "By name",
"type" : "bool",
"optional" : True,
"default": False,
"description": " if True also match by name in addition to the regular ID match",
},
}
},
{
Expand Down
21 changes: 15 additions & 6 deletions server/plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TrackFilter(object):
'''
produces tracks on the true source that are not on the false source
'''
def __init__(self, true_source, false_source, invert=False):
def __init__(self, true_source, false_source, invert=False, by_name=False):
prep = ' that are also in ' if invert else ' that are not in '
self.name = 'tracks in ' + true_source.name + prep + \
false_source.name
Expand All @@ -112,25 +112,34 @@ def __init__(self, true_source, false_source, invert=False):
self.bad_tracks = set()
self.invert = invert
self.debug = False
self.by_name = by_name

def next_track(self):
while True:
bad_track = self.false_source.next_track()
self.bad_tracks.add(bad_track)
if bad_track:
self.bad_tracks.add(bad_track)
if self.by_name:
bad_track_name = pbl.tlib.get_tn(bad_track).lower()
self.bad_tracks.add(bad_track_name)
else:
break

while True:
track = self.true_source.next_track()
if track:
if self.invert and (track in self.bad_tracks):
if self.by_name:
track_name = pbl.tlib.get_tn(track).lower()
else:
track_name = track

if self.invert and ((track in self.bad_tracks) or (track_name in self.bad_tracks)):
return track
elif (not self.invert) and (track not in self.bad_tracks):
elif (not self.invert) and ((track not in self.bad_tracks) and (track_name not in self.bad_tracks)):
return track
else:
if self.debug:
print 'filtered out', tlib.get_tn(track)
print 'filtered out', pbl.tlib.get_tn(track)
else:
break
return None
Expand Down Expand Up @@ -168,7 +177,7 @@ def next_track(self):
return track
else:
if self.debug:
print 'filtered out', tlib.get_tn(track)
print 'filtered out', pbl.tlib.get_tn(track)
else:
break
return None
Expand Down

0 comments on commit ce8cbd2

Please sign in to comment.