예제 #1
0
    def ev_nowplaying(self, track):
        self.pyjama.settingsdb.set_value("listenstats_lastlistened", track.id, time.time())

        self.pyjama.settingsdb.increase_value("listenstats_tracks", track.id)
        self.pyjama.settingsdb.increase_value("listenstats_albums", track.album_id)
        self.pyjama.settingsdb.increase_value("listenstats_artists", track.artist_id)

        sql = "SELECT idstr FROM tags WHERE track_id='%s' ORDER BY weight DESC" % track.id
        ret = self.pyjama.db.query(sql)
        if ret != []:
            for item in ret:
                self.pyjama.settingsdb.increase_value("listenstats_tags", item[0])
        else:
            if self.pyjama.verbose:
               print("This track has no tag")

        sql = "SELECT id3genre FROM tracks WHERE tracks.id='%s'" % track.id
        ret = self.pyjama.db.query(sql)
        if ret != []:
            genre_id = ret[0][0]
            #genre = functions.id2genre(genre_id)
            self.pyjama.settingsdb.increase_value("listenstats_genres", genre_id)
            if self.pyjama.verbose:
                print ("Genre: %s" % functions.id2genre(genre_id))

        self.populate_lastlistened()
예제 #2
0
 def cb_enter_notify_event(self, widget, event, source):
     if source == "track":
         if self.trackmenu.populated == False:
             self.populate_trackmenu()
             self.trackmenu.populated = True
     elif source == "album":
         pass
     elif source == "tag":
         if self.tagmenu.populated == False:
             self.populate_tagmenu()
             self.tagmenu.populated = True
     elif source == "id3":
         sql = "SELECT option, value FROM settings WHERE section='listenstats_genres' ORDER BY value DESC"
         ret = self.pyjama.settingsdb.query(sql)
         for (id3, count) in ret:
             print functions.id2genre(id3), ":", count
     elif source == "lastlistened":
         self.populate_lastlistened()
예제 #3
0
    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)