2015-03-11, 13:39
Trying to exclude my genre tagged karaoke files from the DB query of ErlendSBs scipt Last.FM Playlist Generator PM.
PLEASE... Could anybody with the knowledge of python help me modify this script so that it doesn't load my genre tagged karaoke files?
Think this is the query part of the script :
-----------------------------------------------------------
#xbmc.executehttpapi("setresponseformat(openRecordSet;<recordset>;closeRecordSet;</recordset>;openRecord;<record>;closeRecord;</record>;openField;<field>;closeField;</field>)");
#print WebHTML
similarTracks = re.findall("<track>.+?<name>(.+?)</name>.+?<match>(.+?)</match>.+?<artist>.+?<name>(.+?)</name>.+?</artist>.+?</track>", WebHTML, re.DOTALL )
random.shuffle(similarTracks)
foundArtists = []
countTracks = len(similarTracks)
print "[LFM PLG(PM)] Count: " + str(countTracks)
for similarTrackName, matchValue, similarArtistName in similarTracks:
#print "Looking for: " + similarTrackName + " - " + similarArtistName + " - " + matchValue
similarTrackName = similarTrackName.replace("+"," ").replace("("," ").replace(")"," ").replace(""","''").replace("&","and")
similarArtistName = similarArtistName.replace("+"," ").replace("("," ").replace(")"," ").replace(""","''").replace("&","and")
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": { "properties": ["title", "artist", "album", "file", "thumbnail", "duration", "fanart"], "limits": {"end":1}, "sort": {"method":"random"}, "filter": { "and":[{"field":"title","operator":"contains","value":"%s"},{"field":"artist","operator":"contains","value":"%s"}] } }, "id": 1}' % (similarTrackName, similarArtistName))
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
# separate the records
if json_response.has_key('result') and json_response['result'] != None and json_response['result'].has_key('songs'):
count = 0
for item in json_response['result']['songs']:
count += 1
artist = ""
if (len(item["artist"]) > 0):
artist = item["artist"][0]
trackTitle = item["title"]
album = item["album"]
trackPath = item["file"]
thumb = item["thumbnail"]
duration = int(item["duration"])
fanart = item["fanart"]
log("[LFM PLG(PM)] Found: " + str(trackTitle) + " by: " + str(artist))
if ((self.allowtrackrepeat == "true" or self.allowtrackrepeat == 1) or (trackPath not in self.addedTracks)):
if ((self.preferdifferentartist != "true" and self.preferdifferentartist != 1) or (eval(matchValue) < 0.2 and similarArtistName not in foundArtists)):
listitem = self.getListItem(trackTitle,artist,album,thumb,fanart,duration)
xbmc.PlayList(0).add(url=trackPath, listitem=listitem)
#xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Playlist.Add", "params": { "item": {"file": "%s"}, "playlistid": 0 }, "id": 1}' % trackPath)
self.addedTracks += [trackPath]
xbmc.executebuiltin("Container.Refresh")
self.countFoundTracks += 1
if (similarArtistName not in foundArtists):
foundArtists += [similarArtistName]
if (self.countFoundTracks >= self.numberoftrackstoadd):
break
if (self.countFoundTracks == 0):
time.sleep(3)
#self.firstRun = 1
log("[LFM PLG(PM)] None found")
xbmc.executebuiltin("Notification(" + self.SCRIPT_NAME+",No similar tracks were found)")
return False
xbmc.executebuiltin('SetCurrentPlaylist(0)')
------------------------------------------------------------
Thanks!
PLEASE... Could anybody with the knowledge of python help me modify this script so that it doesn't load my genre tagged karaoke files?
Think this is the query part of the script :
-----------------------------------------------------------
#xbmc.executehttpapi("setresponseformat(openRecordSet;<recordset>;closeRecordSet;</recordset>;openRecord;<record>;closeRecord;</record>;openField;<field>;closeField;</field>)");
#print WebHTML
similarTracks = re.findall("<track>.+?<name>(.+?)</name>.+?<match>(.+?)</match>.+?<artist>.+?<name>(.+?)</name>.+?</artist>.+?</track>", WebHTML, re.DOTALL )
random.shuffle(similarTracks)
foundArtists = []
countTracks = len(similarTracks)
print "[LFM PLG(PM)] Count: " + str(countTracks)
for similarTrackName, matchValue, similarArtistName in similarTracks:
#print "Looking for: " + similarTrackName + " - " + similarArtistName + " - " + matchValue
similarTrackName = similarTrackName.replace("+"," ").replace("("," ").replace(")"," ").replace(""","''").replace("&","and")
similarArtistName = similarArtistName.replace("+"," ").replace("("," ").replace(")"," ").replace(""","''").replace("&","and")
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": { "properties": ["title", "artist", "album", "file", "thumbnail", "duration", "fanart"], "limits": {"end":1}, "sort": {"method":"random"}, "filter": { "and":[{"field":"title","operator":"contains","value":"%s"},{"field":"artist","operator":"contains","value":"%s"}] } }, "id": 1}' % (similarTrackName, similarArtistName))
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
# separate the records
if json_response.has_key('result') and json_response['result'] != None and json_response['result'].has_key('songs'):
count = 0
for item in json_response['result']['songs']:
count += 1
artist = ""
if (len(item["artist"]) > 0):
artist = item["artist"][0]
trackTitle = item["title"]
album = item["album"]
trackPath = item["file"]
thumb = item["thumbnail"]
duration = int(item["duration"])
fanart = item["fanart"]
log("[LFM PLG(PM)] Found: " + str(trackTitle) + " by: " + str(artist))
if ((self.allowtrackrepeat == "true" or self.allowtrackrepeat == 1) or (trackPath not in self.addedTracks)):
if ((self.preferdifferentartist != "true" and self.preferdifferentartist != 1) or (eval(matchValue) < 0.2 and similarArtistName not in foundArtists)):
listitem = self.getListItem(trackTitle,artist,album,thumb,fanart,duration)
xbmc.PlayList(0).add(url=trackPath, listitem=listitem)
#xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Playlist.Add", "params": { "item": {"file": "%s"}, "playlistid": 0 }, "id": 1}' % trackPath)
self.addedTracks += [trackPath]
xbmc.executebuiltin("Container.Refresh")
self.countFoundTracks += 1
if (similarArtistName not in foundArtists):
foundArtists += [similarArtistName]
if (self.countFoundTracks >= self.numberoftrackstoadd):
break
if (self.countFoundTracks == 0):
time.sleep(3)
#self.firstRun = 1
log("[LFM PLG(PM)] None found")
xbmc.executebuiltin("Notification(" + self.SCRIPT_NAME+",No similar tracks were found)")
return False
xbmc.executebuiltin('SetCurrentPlaylist(0)')
------------------------------------------------------------
Thanks!