Permalink
Browse files

Functionnal Album search

  • Loading branch information...
1 parent a3bd00c commit 2898260ac68a337953d1c702788deaa074d61077 sho committed Mar 9, 2012
View
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -29,6 +29,7 @@ def __init__(self):
self.TYPE_SEARCH = 262144
def to_string(self, flag):
+ if not flag: return "No Flag"
if flag == self.TYPE_NODE: return "node"
elif flag == self.TYPE_TRACK: return "track"
elif flag == self.TYPE_PLAYLIST: return "playlist"
@@ -84,6 +84,10 @@ def make_XbmcListItem(self):
self.get_image(),
self.get_url(),
)
+ item.setInfo('music', infoLabels = {
+ 'genre': self.get_genre(),
+ 'year': self.get_year()
+ })
return item
'''
@@ -14,13 +14,16 @@
#
# You should have received a copy of the GNU General Public License
# along with xbmc-qobuz. If not, see <http://www.gnu.org/licenses/>.
-import sys
+import sys
+import qobuz
from debug import info, warn, error
from flag import NodeFlag
from node import Node
-import qobuz
+from product import Node_product
from constants import Mode
-from search.albums import Search_albums
+import pprint
+
+#from search.artists import Search_artists
class Node_search(Node):
@@ -36,21 +39,20 @@ def get_label(self):
return "Searching albums"
elif self.search_type == 'songs':
return "Searching for songs"
-
+
def set_search_type(self, st):
print "Set search type: " + st
self.search_type = st
def get_search_type(self):
return self.search_type
-
def make_url(self, mode = Mode.VIEW):
url = sys.argv[0] + '?mode=' + str(mode) + '&nt=' + str(self.get_type())
url += '&search-type=' + self.search_type
return url
-
- def _get_xbmc_items(self, list, lvl, flag):
+
+ def _get_xbmc_items(self, p_list, lvl, flag):
stype = self.get_search_type()
search = None
limit = None
@@ -61,6 +63,7 @@ def _get_xbmc_items(self, list, lvl, flag):
heading = qobuz.lang(30013)
self.set_content_type('songs')
elif stype == 'albums':
+ from qobuz.search.albums import Search_albums
print "Searching albums"
search = Search_albums()
limit = qobuz.addon.getSetting('albumsearchlimit')
@@ -82,14 +85,21 @@ def _get_xbmc_items(self, list, lvl, flag):
return False
query.strip()
print "Query: " + query
- search.search(query, limit)
- slist = search.get_items()
- if len(slist) < 1:
- qobuz.gui.notification(36000, 35001)
- self._get_xbmc_items(list, lvl, flag)
- return False
- list.extend(slist)
- return True
+ data = search.search(query, limit).get_data()
+ if self.search_type == 'albums':
+ for json_product in data:
+ json_product = json_product['product']
+ artist = json_product['artist']
+ print "Artist: " + artist.encode('utf8', 'ignore')
+ json_product['artist'] = { }
+ json_product['artist']['name'] = artist
+ print pprint.pformat(json_product)
+ product = Node_product()
+ product.set_data(json_product)
+ item = product.make_XbmcListItem()
+ self.attach_context_menu(item, product)
+ p_list.append((product.get_url(), item, product.is_folder()))
+ return p_list
def _get_keyboard(self, default = "", heading = "", hidden = False):
import xbmc
@@ -17,7 +17,6 @@
import qobuz
from debug import log, info, warn
-from utils.icacheable import ICacheable
'''
Class QobuzSearchAlbums
@@ -26,17 +25,17 @@ class Search_albums():
def __init__(self):
self._raw_data = []
-
+
def get_data(self):
return self._raw_data
-
+
def search(self, query, limit = 100):
self._raw_data = qobuz.api.search_albums(query, limit)
return self
-
- def search_by_artist(self,id, limit = 100):
- self._raw_data = qobuz.api.get_albums_from_artist(id, limit)
+
+ def search_by_artist(self, p_id, limit = 100):
+ self._raw_data = qobuz.api.get_albums_from_artist(p_id, limit)
return self
-
+
def length(self):
return len(self._raw_data)
@@ -19,14 +19,12 @@
from constants import *
from debug import log, info, warn
-#from tag.track import TagTrack
-from tag.search import TagSearch
import qobuz
###############################################################################
# Class QobuzSearchTracks
###############################################################################
-class QobuzSearchTracks():
+class Search_tracks():
def __init__(self):
self._raw_data = {}
@@ -39,20 +37,6 @@ def length(self):
if not self._raw_data['results']:
return 0
return len(self._raw_data['results']['tracks'])
-
- def get_items(self):
- list = []
- data = self._raw_data
- if not data:
- return list
- if not 'results' in data:
- return list
- ts = TagSearch(data['results'])
- childs = ts.get_childs()
- for track in childs:
- item = track.getXbmcItem('playlist', 0, 'fanArt')
- u = qobuz.boot.build_url(MODE_SONG, int(track.id))
- list.append((u, item, False))
- return list
+
@@ -55,7 +55,7 @@ def set_cache_path(self, path, name, id):
hash = hashlib.new('SHA1')
hash.update(self.cache_object_path)
digest = hash.hexdigest()
- newdir = digest[0:2]
+ newdir = digest[0:1]
print "NEWdir: " + newdir
self.cache_path = os.path.join(path, newdir)
self.cache_object_path = digest

0 comments on commit 2898260

Please sign in to comment.