Author: duncan
Date: Thu Nov 15 00:58:02 2007
New Revision: 10122

Log:
Quite a few errors in this module, hopefully this fixes some of them


Modified:
   branches/rel-1-7/freevo/src/audio/plugins/freevo_scrobbler.py
   branches/rel-1/freevo/src/audio/plugins/freevo_scrobbler.py

Modified: branches/rel-1-7/freevo/src/audio/plugins/freevo_scrobbler.py
==============================================================================
--- branches/rel-1-7/freevo/src/audio/plugins/freevo_scrobbler.py       
(original)
+++ branches/rel-1-7/freevo/src/audio/plugins/freevo_scrobbler.py       Thu Nov 
15 00:58:02 2007
@@ -31,7 +31,7 @@
 import md5 , time
 import config
 
-URL = "http://post.audioscrobbler.com/?hs=true&p=1.1&c=xms&v=0.7";
+URL = 'http://post.audioscrobbler.com/?hs=true&p=1.1&c=xms&v=0.7'
 
 
 class Scrobbler:
@@ -47,22 +47,23 @@
         pass
 
     def send_handshake(self):
-        url = URL + "&u=%s" % self.username
+        url = URL + '&u=%s' % (self.username, self.md5_pass)
         resp = None
 
         try:
             resp = urllib2.urlopen(url);
         except Exception,e:
-            print "Server not responding, handshake failed.",e
+            print 'Server not responding, handshake failed: %s' % (e)
             return False
 
         # check response
-        lines = resp.read().rstrip().split("\n")
+        lines = resp.read().rstrip().split('\n')
         status = lines.pop(0)
 
-        if status.startswith("UPDATE"): print "Please update: %s" % status
+        if status.startswith('UPDATE'):
+            print 'Please update: %s' % status
 
-        if status == "UPTODATE" or status.startswith("UPDATE"):
+        if status == 'UPTODATE' or status.startswith('UPDATE'):
             challenge = lines.pop(0)
 
             hasher = md5.new()
@@ -71,69 +72,74 @@
             self.password_hash = hasher.hexdigest()
 
             self.submit_url = lines.pop(0)
-            print "Handshake SUCCESS"
+            print 'Handshake SUCCESS'
 
         try: self.interval_time = int(lines.pop(0).split()[1])
         except: pass
 
-        if status == "UPTODATE" or status.startswith("UPDATE"): return True
-        elif status == "BADUSER": print "Handshake failed: bad user"
-        else: print "Handshake failed: %s" % status; return False
+        if status == 'UPTODATE' or status.startswith('UPDATE'):
+            return True
+        elif status == 'BADUSER':
+            print 'Handshake failed: bad user'
+            return False
+        else:
+            print 'Handshake failed: %s' % status;
+            return False
 
     def submit_song(self, info):
         data = {
-                        'u': self.username,
-                        's': self.password_hash
-                }
-        if not info['length']<=30*1000 or not info['title']=="" or not 
info['artist']=="":
-            print ("Sending song: " + info['artist'] + " - " + info['title'])
+            'u': self.username,
+            's': self.password_hash
+        }
+        if info['length'] > 30*1000 and info['title'] and info['artist']:
+            _debug_('Sending song: %r - %r' % (info['artist'], info['title']))
             i = 0
-            stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
-            data["a[%d]" % i] = info['artist'].encode('utf-8')
-            data["t[%d]" % i] = info['title'].encode('utf-8')
-            data["l[%d]" % i] = str(info['length']).encode('utf-8')
-            data["b[%d]" % i] = info['album'].encode('utf-8')
-            data["m[%d]" % i] = ""
-            data["i[%d]" % i] = stamp
+            stamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
+            data['a[%d]' % i] = info['artist'].encode('utf-8')
+            data['t[%d]' % i] = info['title'].encode('utf-8')
+            data['l[%d]' % i] = str(info['length']).encode('utf-8')
+            data['b[%d]' % i] = info['album'].encode('utf-8')
+            data['m[%d]' % i] = ''
+            data['i[%d]' % i] = stamp
 
-            (host, file) = self.submit_url[7:].split("/")
-            url = "http://"; + host + "/" + file
+            (host, file) = self.submit_url[7:].split('/')
+            url = 'http://' + host + '/' + file
             resp = None
             try:
                 data_str = urllib.urlencode(data)
                 resp = urllib2.urlopen(url, data_str)
                 resp_save = resp.read()
-            except Exception,e:
-                print "Audioscrobbler server not responding, will try later.",e
+            except Exception, e:
+                print 'Audioscrobbler server not responding, will try later: 
%s' % (e)
 
-            lines = resp_save.rstrip().split("\n")
+            lines = resp_save.rstrip().split('\n')
 
             try: (status, interval) = lines
             except:
                 try: status = lines[0]
                 except:
-                    print "Status incorrect"
+                    _debug_('Status incorrect')
                     return False
             else: self.interval_time = int(interval.split()[1])
 
-            if status == "BADAUTH":
-                print "Authentication failed: invalid username or bad 
password."
+            if status == 'BADAUTH':
+                print 'Authentication failed: invalid username or bad 
password.'
                 print url
                 print data
 
-            elif status == "OK":
-                print "Submit succesfull"
+            elif status == 'OK':
+                print 'Submit successful'
                 return True
 
-            elif status.startswith("FAILED"):
-                print "FAILED response from server: %s" % status
-                print "Dumping full response:"
+            elif status.startswith('FAILED'):
+                print 'FAILED response from server: %s' % status
+                print 'Dumping full response:'
                 print resp_save
             else:
-                print "Unknown response from server: %s" % status
-                print "Dumping full response:"
+                print 'Unknown response from server: %s' % status
+                print 'Dumping full response:'
                 print resp_save
         else:
-            print "Song not accepted!"
+            print 'Song not accepted!'
 
         return False

Modified: branches/rel-1/freevo/src/audio/plugins/freevo_scrobbler.py
==============================================================================
--- branches/rel-1/freevo/src/audio/plugins/freevo_scrobbler.py (original)
+++ branches/rel-1/freevo/src/audio/plugins/freevo_scrobbler.py Thu Nov 15 
00:58:02 2007
@@ -31,7 +31,7 @@
 import md5 , time
 import config
 
-URL = "http://post.audioscrobbler.com/?hs=true&p=1.1&c=xms&v=0.7";
+URL = 'http://post.audioscrobbler.com/?hs=true&p=1.1&c=xms&v=0.7'
 
 
 class Scrobbler:
@@ -47,22 +47,23 @@
         pass
 
     def send_handshake(self):
-        url = URL + "&u=%s" % self.username
+        url = URL + '&u=%s' % (self.username, self.md5_pass)
         resp = None
 
         try:
             resp = urllib2.urlopen(url);
         except Exception,e:
-            print "Server not responding, handshake failed.",e
+            print 'Server not responding, handshake failed: %s' % (e)
             return False
 
         # check response
-        lines = resp.read().rstrip().split("\n")
+        lines = resp.read().rstrip().split('\n')
         status = lines.pop(0)
 
-        if status.startswith("UPDATE"): print "Please update: %s" % status
+        if status.startswith('UPDATE'):
+            print 'Please update: %s' % status
 
-        if status == "UPTODATE" or status.startswith("UPDATE"):
+        if status == 'UPTODATE' or status.startswith('UPDATE'):
             challenge = lines.pop(0)
 
             hasher = md5.new()
@@ -71,69 +72,74 @@
             self.password_hash = hasher.hexdigest()
 
             self.submit_url = lines.pop(0)
-            print "Handshake SUCCESS"
+            print 'Handshake SUCCESS'
 
         try: self.interval_time = int(lines.pop(0).split()[1])
         except: pass
 
-        if status == "UPTODATE" or status.startswith("UPDATE"): return True
-        elif status == "BADUSER": print "Handshake failed: bad user"
-        else: print "Handshake failed: %s" % status; return False
+        if status == 'UPTODATE' or status.startswith('UPDATE'):
+            return True
+        elif status == 'BADUSER':
+            print 'Handshake failed: bad user'
+            return False
+        else:
+            print 'Handshake failed: %s' % status;
+            return False
 
     def submit_song(self, info):
         data = {
-                        'u': self.username,
-                        's': self.password_hash
-                }
-        if not info['length']<=30*1000 or not info['title']=="" or not 
info['artist']=="":
-            print ("Sending song: " + info['artist'] + " - " + info['title'])
+            'u': self.username,
+            's': self.password_hash
+        }
+        if info['length'] > 30*1000 and info['title'] and info['artist']:
+            _debug_('Sending song: %r - %r' % (info['artist'], info['title']))
             i = 0
-            stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
-            data["a[%d]" % i] = info['artist'].encode('utf-8')
-            data["t[%d]" % i] = info['title'].encode('utf-8')
-            data["l[%d]" % i] = str(info['length']).encode('utf-8')
-            data["b[%d]" % i] = info['album'].encode('utf-8')
-            data["m[%d]" % i] = ""
-            data["i[%d]" % i] = stamp
+            stamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
+            data['a[%d]' % i] = info['artist'].encode('utf-8')
+            data['t[%d]' % i] = info['title'].encode('utf-8')
+            data['l[%d]' % i] = str(info['length']).encode('utf-8')
+            data['b[%d]' % i] = info['album'].encode('utf-8')
+            data['m[%d]' % i] = ''
+            data['i[%d]' % i] = stamp
 
-            (host, file) = self.submit_url[7:].split("/")
-            url = "http://"; + host + "/" + file
+            (host, file) = self.submit_url[7:].split('/')
+            url = 'http://' + host + '/' + file
             resp = None
             try:
                 data_str = urllib.urlencode(data)
                 resp = urllib2.urlopen(url, data_str)
                 resp_save = resp.read()
-            except Exception,e:
-                print "Audioscrobbler server not responding, will try later.",e
+            except Exception, e:
+                print 'Audioscrobbler server not responding, will try later: 
%s' % (e)
 
-            lines = resp_save.rstrip().split("\n")
+            lines = resp_save.rstrip().split('\n')
 
             try: (status, interval) = lines
             except:
                 try: status = lines[0]
                 except:
-                    print "Status incorrect"
+                    _debug_('Status incorrect')
                     return False
             else: self.interval_time = int(interval.split()[1])
 
-            if status == "BADAUTH":
-                print "Authentication failed: invalid username or bad 
password."
+            if status == 'BADAUTH':
+                print 'Authentication failed: invalid username or bad 
password.'
                 print url
                 print data
 
-            elif status == "OK":
-                print "Submit succesfull"
+            elif status == 'OK':
+                print 'Submit successful'
                 return True
 
-            elif status.startswith("FAILED"):
-                print "FAILED response from server: %s" % status
-                print "Dumping full response:"
+            elif status.startswith('FAILED'):
+                print 'FAILED response from server: %s' % status
+                print 'Dumping full response:'
                 print resp_save
             else:
-                print "Unknown response from server: %s" % status
-                print "Dumping full response:"
+                print 'Unknown response from server: %s' % status
+                print 'Dumping full response:'
                 print resp_save
         else:
-            print "Song not accepted!"
+            print 'Song not accepted!'
 
         return False

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to