import cgi, cgitb
from datetime import datetime
import hashlib
+import itertools
import numbers
import os
import random
+import re
import subprocess
-from xbmcjson import XBMC
import urllib
+from xbmcjson import XBMC
from yattag import Doc
import youtube_dl
return doc.getvalue ()
class Search:
+ ANY_SEARCH_PROPERTIES = [ 'title', 'album', 'artist' ]
+
def __init__ (self, term = '', prop = 'title'):
self.term = term
self.prop = prop
if (term != ''):
- res = xbmc.AudioLibrary.GetSongs (filter={'operator': "contains", 'field': self.prop, 'value': self.term}, properties=SONG_PROPERTIES, sort={'order': 'ascending', 'method': 'artist'})['result']
- if 'songs' in res:
- self.results = songs(res['songs'])
- else:
- self.results = []
+ self.results = self.get_search_results ()
+
+ def get_search_results (self):
+ if (self.term == ''):
+ return {}
+
+ if (self.prop != 'any'):
+ res = xbmc.AudioLibrary.GetSongs (filter={'operator': "contains", 'field': self.prop, 'value': self.term}, properties=SONG_PROPERTIES, sort={'order': 'ascending', 'method': 'artist'})['result']
+ if 'songs' in res:
+ return songs(res['songs'])
+ else:
+ return []
+ else:
+ all_songs = [xbmc.AudioLibrary.GetSongs (filter={'operator': "contains", 'field': p, 'value': self.term}, properties=SONG_PROPERTIES, sort={'order': 'ascending', 'method': 'artist'})['result']
+ for p
+ in self.ANY_SEARCH_PROPERTIES]
+ # does not remove duplicates...
+ return list (itertools.chain.from_iterable ([res['songs'] for res in all_songs if 'songs' in res]))
def show_quick_search (self, thereal=False):
doc, tag, text = Doc(defaults = {'searchfield': self.prop}).tagtext()
else:
doc.stag ('input', type = 'text', name = 'searchterm', value = self.term)
with doc.select (name = 'searchfield'):
- for prop in ['title', 'artist', 'album']:
+ for prop in ['title', 'artist', 'album', 'any']:
with doc.option (value = prop):
text (prop)
with tag ('button', type = 'submit', name = 'searchgo', value = '1'):