Commits

Vladimir Kolev committed 551b1b7

Last.FM Scrobbling and loving a track works (after refactoring missing parameters)

Scrobbling is not enabled if there is no username/password or the username or password are wrong - ErrorMessage is displayed.

Comments (0)

Files changed (3)

             play_stop_image.set_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_MENU)
             self.staticon.change_playbutton(play_stop_image)
             self.play_button.set_stock_id(gtk.STOCK_MEDIA_STOP)
+            self.scrobbled = 0
 
             self.songinfo.set_markup(
                 _("<b>Playing:</b> {artist} - {title}").format(artist = glib.markup_escape_text(song.get_artist()),
             self.downloads.get_song(path).resume_download()
 
     def on_love_song(self, button):
-        if self.current_song == None:
+        if self.playlist.playing_song == None:
             info = guihelpers.InfoDialog(self.window,
                     _("There is no song to be loved.\n A song should be playing"))
             info.show_all()
         else:
             try:
-                track = self.lastfm.get_track(self.current_song['ArtistName'],
-                                          self.current_song['SongName'])
+                track = self.lastfm.get_track(self.playlist.playing_song.get_artist(),
+                                          self.playlist.playing_song.get_title())
                 track.love()
             except pylast.MalformedResponseError, e:
                 pass

lib/guihelpers.py

         try:
             if self.scrobble.get_active():
                 lastfm_pass = None
-                if config()['lastpass'] == self.lastpass.get_text():
-                    lastfm_pass = self.lastpass.get_text()
-                else:
+                if config()['lastpass'] == pylast.md5(self.lastpass.get_text()) or self.lastpass.get_text() != "":
                     lastfm_pass = pylast.md5(self.lastpass.get_text())
                 
-                self.lastfm = pylast.LastFMNetwork(api_key = env().LASTFM_KEY,
-                                              api_secret = env().LASTFM_SECRET,
-                                              username = self.lastuser.get_text(),
-                                              password_hash = lastfm_pass )
-                self.app.lovebutton.set_sensitive(True)
-                config()['scrobbling'] = 1
-                config()['lastuser'] = self.lastuser.get_text()
-                config()['lastpass'] = pylast.md5(self.lastpass.get_text())
+                    self.lastfm = pylast.LastFMNetwork(api_key = env().LASTFM_KEY,
+                                                  api_secret = env().LASTFM_SECRET,
+                                                  username = self.lastuser.get_text(),
+                                                  password_hash = lastfm_pass )
+                    self.app.lovebutton.set_sensitive(True)
+                    config()['scrobbling'] = 1
+                    config()['lastuser'] = self.lastuser.get_text()
+                    config()['lastpass'] = pylast.md5(self.lastpass.get_text())
+                else:
+                    raise pylast.WSError(None, None, None)
             else:
                 config()['scrobbling'] = 0
                 self.app.lovebutton.set_sensitive(False)
         self.app.player.set_state(gst.STATE_PLAYING)
         if self.app.lastfm != "":
             if self.app.scrobbled == 0:
-                self.lastfm.scrobble(self.song.get_artist(),
+                self.app.lastfm.scrobble(self.song.get_artist(),
                                     self.song.get_title(),
                                     int(time.time()))
-                self.lastfm.update_now_playing(self.song.get_artist(),
+                self.app.lastfm.update_now_playing(self.song.get_artist(),
                                               self.song.get_title())
                 self.app.scrobbled = 1
             else: