1. Vladimir Kolev
  2. gSharkDown

Commits

Damián Nohales  committed 0245e6a

Fixed the Last.fm preferences checking.

  • Participants
  • Parent commits 62bc781
  • Branches default

Comments (0)

Files changed (3)

File lib/SharkDown.py

View file
             pynotify.init("gSharkDown")
             
         # Scrobbling initialization
-        self.lastfm = ""
+        self.lastfm = None
         if int(config()['scrobbling']) == 1 and env().HAVE_PYLAST:
             try:
                 self.lastfm = pylast.LastFMNetwork(api_key = env().LASTFM_KEY,

File lib/guihelpers.py

View file
         try:
             if self.scrobble.get_active():
                 lastfm_pass = None
-                if config()['lastpass'] == pylast.md5(self.lastpass.get_text()) or self.lastpass.get_text() != "":
+                lastfm_user = self.lastuser.get_text().strip()
+                
+                # Check username
+                if lastfm_user == "":
+                    raise Exception(_("The Last.fm username must not be empty."))
+                
+                # Check password
+                if config()['lastpass'] == self.lastpass.get_text() and config()["lastuser"] == lastfm_user:
+                    lastfm_pass = self.lastpass.get_text()
+                elif 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())
                 else:
-                    raise pylast.WSError(None, None, None)
+                    raise Exception(_("The Last.fm password must not be empty."))
+            
+                lastfm = pylast.LastFMNetwork(api_key = env().LASTFM_KEY,
+                                              api_secret = env().LASTFM_SECRET,
+                                              username = lastfm_user,
+                                              password_hash = lastfm_pass )
+                self.app.lastfm = lastfm
+                self.app.lovebutton.set_sensitive(True)
+                config()['scrobbling'] = 1
+                config()['lastuser'] = lastfm_user
+                config()['lastpass'] = lastfm_pass
             else:
+                self.app.lastfm = None
                 config()['scrobbling'] = 0
                 self.app.lovebutton.set_sensitive(False)
                 
             self.lastuser.select_region(0, -1)
             self.lastuser.grab_focus()
             self.lastpass.set_text("")
+        except Exception as e:
+            ErrorMessage(self.prefs, e.args[0])
+            self.lastuser.select_region(0, -1)
+            self.lastuser.grab_focus()
+            self.lastpass.set_text("")
         
     def on_cancel(self, widget, data = None):
         """

File lib/tfuncs.py

View file
         print "[Playing]", self.song.get_id(), play_url
         self.app.player.set_property('uri', play_url)
         self.app.player.set_state(gst.STATE_PLAYING)
-        if self.app.lastfm != "":
+        if self.app.lastfm != None:
             if self.app.scrobbled == 0:
                 self.app.lastfm.scrobble(self.song.get_artist(),
                                     self.song.get_title(),
             print e.args
             
     def fill_results(self, results):
-        print threading.current_thread()
         self.app.entry.set_sensitive(True)
         self.app.result.clear()
         if results:
         gobject.idle_add(self.open_viewer, lyrics)
         
     def open_viewer(self, lyrics):
-        print threading.current_thread()
         self.app.lyrics_button.set_sensitive(True)
         self.app.lyrics_button.set_label(_("Lyrics"))
         if "ERROR:" in lyrics: