def draw(self, data1, data2, data3, data4): # # Setting label # try: #markup = self.pyjama.window.markuplbCaption.replace("TEXT", _("Showing infos and albums concerning '%s'") % data1[0]['artist_name']) txt = _("Showing infos and albums concerning '%s'") % data1[0]['artist_name'] except KeyError: print ("Artist not in database, yet.") dia = clWidgets.MyDialog(_('Artist non existant.'), self.pyjama.window.get_toplevel(), gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT), gtk.STOCK_DIALOG_WARNING, _('This artist is not in the database.\nPerhaps you are using a old local database\nor Jamendo did not update their dump, yet')) dia.run() dia.destroy() # self.pyjama.window.lbCaption.set_markup(markup) self.pyjama.window.LayoutInfo.set_text(txt) self.pyjama.window.LayoutInfo.set_image("personal.png") artistinfos = data1 self.toolbar = self.pyjama.layouts.toolbars['artist'] for albuminfo in self.albuminfos: self.albuminfos[albuminfo].destroy() self.albuminfos = {} img = artistinfos[0]['artist_image'] name = artistinfos[0]['artist_name'] artistID = artistinfos[0]['artist_id'] #genre = artistinfos[0]['artist_genre'] country = artistinfos[0]['artist_country'] #link = artistinfos[0]['artist_link'] url = artistinfos[0]['artist_url'] albums = artistinfos[0]['artist_albumcount'] md5hash = hashlib.md5(img).hexdigest() fh = os.path.join(self.pyjama.home, "images", md5hash) if not os.path.exists(fh) and img != "": try: urllib.urlretrieve(img, fh) except IOError: print ("Could not load image") return None #self.toolbar.ibDonate.tag = url #stf #self.toolbar.sbGotoWebArtist.tag = url #stf self.image_artist.clear() if img == "" or img == None: pixbuf = self.image_artist.render_icon(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_DIALOG, detail=None) self.image_artist.set_from_pixbuf(pixbuf) else: self.image_artist.set_from_file(fh) content = [functions.decode_htmlentities(name), country, albums, url] x = 0 infos = self.ArtistInfos captions = self.ArtistCaptions for x in xrange(0, len(infos)): #self.window.layout['artist'].move(self.labels[infos[x]], xspace, y) if self.pyjama.nocolor and infos[x] != "url": self.ArtistLabels[infos[x]].set_markup("<span><b>%s: %s</b></span>" % (captions[x], content[x])) elif infos[x] == "url": self.ArtistLabels[infos[x]].set_label(url) else: self.ArtistLabels[infos[x]].set_markup("<span foreground=\"white\"><b>%s: %s</b></span>" % (captions[x], content[x])) #self.labels[infos[x]].set_line_wrap(True) #y+=yspace #### ARTIST'S ALBUMS #### threads = {} albums = [] counter = 0 for album in artistinfos: albums.append(str(artistinfos[counter]['album_id'])) ## todo ## ## Replace Image-URL with constants!!!! ## # artistinfos[counter]['album_image'] = "http://imgjam.com/albums/%s/covers/1.100.jpg" % artistinfos[counter]['album_id'] artistinfos[counter]['album_image'] = "http://api.jamendo.com/get2/image/album/redirect/?id=%s&imagesize=%i" % (artistinfos[counter]['album_id'], 100) threads[counter] = clThreadedDownload.Download(self.pyjama, artistinfos[counter]['album_image'], counter) threads[counter].start() counter += 1 ## i added another loop ## so that threaded download ## won't collide with ## creating the albuminfos counter = 0 for album in artistinfos: self.albuminfos[counter] = clWidgets.AlbumInfo(self.pyjama, artistinfos[counter]) self.albuminfos[counter].show() self.put(self.albuminfos[counter], 1, 1) counter += 1 ### Add Artist's Tracks to List ### self.pyjama.window.TVListFrame.get_label_widget().set_markup(_("Tracks of the artist '<b>%s</b>'" % name)) self.pyjama.window.tvList.clear() tracks = self.pyjama.db.artisttracks(artistID) for track in tracks: results = [name, track.album_name, track.numalbum, track.name, track.license, artistID, track.album_id, track.id] self.pyjama.window.tvList.add_item(results) # ### this is more than slow since # ### every artists' album is requested # ### on its own, need multiple cross- joins!!! # for album in albums: # tracks = self.db.albumtracks(album) # for track in tracks: # results = [tracks[track]['artist_name'], tracks[track]['album_name'], tracks[track]['numalbum'], tracks[track]['name'], tracks[track]['license'], tracks[track]['artist_id'], tracks[track]['album_id'], tracks[track]['id']] # self.window.tvList.add_item(results) self.arrange_artistdetail() self.pyjama.Events.raise_event("showing_artist_page", artistinfos) self.show() self.pyjama.window.toolbar.lbMoreAlbumsFromThisArtist2.hide() self.pyjama.window.toolbar.lbAppendAlbum.hide()
def draw(self, data1, data2, data3, data4): # # Setting label # # markup = self.pyjama.window.markuplbCaption.replace("TEXT", _("Show album infos for '%s'") % data1['name']) txt = _("Showing album infos for '%s'") % data1['name'] # self.pyjama.window.lbCaption.set_markup(markup) self.pyjama.window.LayoutInfo.set_text(txt) self.pyjama.window.LayoutInfo.set_image("cd.png") #self.toolbar = self.pyjama.layouts.toolbars['album'] albuminfos = data1 tracks = self.pyjama.db.albumtracks(albuminfos['id']) track_count = len(tracks) if track_count == 0: print ("Album not in database, yet.") print albuminfos['public_date'] dia = clWidgets.MyDialog(_('Album non existant.'), self.pyjama.window.get_toplevel(), gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT), gtk.STOCK_DIALOG_WARNING, _('This album is not in the database.\nPerhaps Jamendo did not unloack that album, yet\n or you are using a old local database.')) dia.run() dia.destroy() self.pyjama.window.toolbar.on_bHistoryBack_clicked(None) return None #tags = albuminfos['id3genre'] genre = albuminfos['id3genre'] #desc = albuminfos['desc_str'] #referrer_count = albuminfos['referrer_count'] #playlisted_count = albuminfos['playlisted_count'] #favourited_count = albuminfos['favourited_count'] #lowfi_count = albuminfos['lowfi_count'] releasedate = albuminfos['public_date'] lengths = albuminfos['lengths'] #license_id = albuminfos['license_id'] #review_num = albuminfos['review_num'] review_note = albuminfos['review_note'] #review_num_week = albuminfos['review_num_week'] #review_note_week = albuminfos['review_note_week'] name = albuminfos['name'] artist_id = albuminfos['artist_id'] artist_name = tracks[0].artist_name album_id = albuminfos['id'] #img = albuminfos['images'][0]['url'] img = albuminfos['root_images'] + "1.200.jpg" url = self.pyjama.settings.get_value("URLs", "ALBUM_URL").replace("URL", "%s" % album_id) albuminfos['tracks'] = tracks self.pyjama.window.TVListFrame.get_label_widget().set_markup(_("Tracks of the album '<b>%s</b>'" % data1['name'])) self.pyjama.window.tvList.clear() for track in tracks: results = [artist_name, name, track.numalbum,track.name, track.license, artist_id, album_id, track.id] self.pyjama.window.tvList.add_item(results) self.pyjama.window.toolbar.lbAppendAlbum.tag = tracks #self.tracks = tracks md5hash = hashlib.md5(img).hexdigest() fh = os.path.join(self.pyjama.home, "images", md5hash) if not os.path.exists(fh): try: urllib.urlretrieve(img, fh) except IOError: print ("Could not load image") return None self.image_album.clear() if img == "" or img == None: pixbuf = self.image_album.render_icon(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_DIALOG, detail=None) self.image_album.set_from_pixbuf(pixbuf) else: self.image_album.set_from_file(fh) content = [ name, functions.decode_htmlentities(artist_name), track_count, functions.sec2time(lengths), functions.id2genre(genre), releasedate, review_note, url ] x = 0 infos = self.AlbumInfos namen = self.AlbumCaptions for x in xrange(0, len(infos)): if infos[x] == "review_note": if self.pyjama.nocolor: self.AlbumLabels[infos[x]].set_markup("<span><b>%s: </b></span>" % (namen[x])) else: self.AlbumLabels[infos[x]].set_markup("<span foreground=\"white\"><b>%s: </b></span>" % (namen[x])) self.rtRating.set_rating(content[x]) elif infos[x] == "url": self.AlbumLabels[infos[x]].set_label(url) else: if self.pyjama.nocolor: self.AlbumLabels[infos[x]].set_markup("<span><b>%s: %s</b></span>" % (namen[x], content[x])) else: self.AlbumLabels[infos[x]].set_markup("<span foreground=\"white\"><b>%s: %s</b></span>" % (namen[x], content[x])) # NEW ATTRIBUTE 'FLAG' IN STOCKBUTTON # NEED TO USE THIS FOR OTHER BUTTONS # HERE, TOO! #self.toolbar.sbGotoWeb.tag = url #stf self.pyjama.window.toolbar.lbMoreAlbumsFromThisArtist2.tag = artist_id self.pyjama.window.toolbar.lbMoreAlbumsFromThisArtist2.set_tooltip_text(_("Showing informations and albums from '%s'") % artist_name) self.pyjama.window.toolbar.lbMoreAlbumsFromThisArtist2.show() self.pyjama.window.toolbar.lbAppendAlbum.show() self.pyjama.window.toolbar.lbArtistsAlbumsToPlaylist.hide() self.pyjama.window.toolbar.Separator2.show() #self.toolbar.sbDownloadAlbum.tag = album_id for albuminfo in self.albuminfos: self.albuminfos[albuminfo].destroy() self.albuminfos = {} ### Similar Album's ### threads = {} counter = 0 albums_dic = {} num = self.pyjama.settings.get_value("PYJAMA", "similar_albums", 5) ## This hack prevents the jamendo class from aborting the query # with a "to fast" message - there should be a better solution self.pyjama.jamendo.last_query_hack() ret = self.pyjama.jamendo.get_similar_albums( album_id, num ) if ret is not None and ret != [] and ret != -1 and num > 0: ALBUM_ID = 0 ALBUM_NAME = 1 ARTIST_ID = 2 ARTIST_NAME=3 # get infos fo the returnes albums: albums = self.pyjama.db.multiple_albuminfos(ret) if albums is not None and albums != []: for album in albums: #image = "http://imgjam.com/albums/%s/covers/1.100.jpg" % album[ALBUM_ID] image = "http://api.jamendo.com/get2/image/album/redirect/?id=%s&imagesize=%i" % (album[ALBUM_ID], 100) threads[counter] = clThreadedDownload.Download(self.pyjama, image, counter) threads[counter].start() albums_dic[counter] = {'arist_id':album[ARTIST_ID], 'album_id':album[ALBUM_ID], 'artist_name':album[ARTIST_NAME], 'album_name':album[ALBUM_NAME], 'album_image':image} counter += 1 ## i added another loop ## so that threaded download ## won't collide with ## creating the albuminfos counter = 0 for album in albums: self.albuminfos[counter] = clWidgets.AlbumInfo(self.pyjama, albums_dic[counter]) self.albuminfos[counter].show() self.put(self.albuminfos[counter], 1, 1) counter += 1 self.lblSimilar.set_markup(_("<b>Similar Albums:</b>")) elif ret == -1: print ("Some Problems with Jamendo") elif ret == []: self.lblSimilar.set_markup(_("<b>No similar albums found</b>")) self.arrange_albumdetail() # self.set_size(self.pyjama.window.scrolledwindow_width-20,230)#350)#y+200 self.pyjama.Events.raise_event("showing_album_page", albuminfos)