Exemplo n.º 1
0
    def send_tags(self, method, info, tags, sk):
        """Sends tags to last.fm. method is one of:
        album.addtags, artist.addtags or track.addtags
        info_dict is the artist, track and album info
        tags is a comma delimited list of no more than 10 tags"""

        #All methods require these parameters:
        #tags (Required) : A comma delimited list of user supplied tags to apply
        #to this album. Accepts a maximum of 10 tags.
        #api_key (Required) : A Last.fm API key.
        #api_sig (Required)
        #sk (Required)
        #artist (Required) : The artist name in question

        post_values = {
            "method": method,
            "tags": tags,
            "api_key": self.api_key,
            "sk": sk,
            "artist": info['Artist']
        }

        #these methods require additional info:
        #album.addTags -> album
        #track.addTags -> track
        if method == "album.addtags":
            post_values['album'] = info['Album']
        if method == "track.addtags":
            post_values['track'] = info['Track']
        post_values['api_sig'] = self.create_api_sig(post_values)
        conn = HttpRequest(self.url, urllib.urlencode(post_values))
        response = conn.connect()
Exemplo n.º 2
0
    def send_tags(self, method, info, tags, sk):
        """Sends tags to last.fm. method is one of:
        album.addtags, artist.addtags or track.addtags
        info_dict is the artist, track and album info
        tags is a comma delimited list of no more than 10 tags"""
        
        #All methods require these parameters:
        #tags (Required) : A comma delimited list of user supplied tags to apply
        #to this album. Accepts a maximum of 10 tags.
        #api_key (Required) : A Last.fm API key.
        #api_sig (Required)
        #sk (Required)
        #artist (Required) : The artist name in question

        post_values = {
            "method" : method,
            "tags" : tags,
            "api_key" : self.api_key,
            "sk" : sk,
            "artist" : info['Artist']}

        #these methods require additional info:
        #album.addTags -> album
        #track.addTags -> track
        if method == "album.addtags":
            post_values['album'] = info['Album']
        if method == "track.addtags":
            post_values['track'] = info['Track']
        post_values['api_sig'] = self.create_api_sig(post_values)
        conn = HttpRequest(self.url, urllib.urlencode(post_values))
        response = conn.connect()
Exemplo n.º 3
0
 def _send_post(self, post_values):
     req = HttpRequest(url=self.submission_url, data=post_values, timeout=10)
     success, msg = req.connect()
     if success:
         self.deletion_ids.extend(self.del_ids)    
         return True
     else:
         self.parent.write_info(_("There was an error sending data to last.fm:") +
                                "\n" + "\n".join(msg))
         return False
Exemplo n.º 4
0
 def handshake(self):
     self.timestamp = self.create_timestamp()
     self.authentication_code = self.create_authentication_code()
     self.url += r"/?" + self.encode_url()
     
     req = HttpRequest(url=self.url, timeout=10)
     success, response = req.connect()
        
     if success:
         self.session_id = response[1]
         self.submission_url = response[3]
         
     msg = req.handshake_response(response[0])
     return response[0], msg
Exemplo n.º 5
0
 def get_user_top_tags(self, username, limit=15):
     #method user.getTopTags
     #Params
     #user (Required) : The user name
     #limit (Optional) : Limit the number of tags returned
     #api_key (Required) : A Last.fm API key.
     encoded_values = urllib.urlencode({
         "method": "user.gettoptags",
         "user": username,
         "limit": limit,
         "api_key": self.api_key
     })
     url = self.url + "?" + encoded_values
     conn = HttpRequest(url)
     xml_doc = conn.connect(xml=True)
     return self.parse_xml_doc(xml_doc, "name")
Exemplo n.º 6
0
 def get_popular_tags(self, method, info_dict):
     """method is either artist.gettoptags or track.gettoptags"""
     #Params
     #track (Optional) : The track name in question
     #artist (Required) : The artist name in question
     #api_key (Required) : A Last.fm API key.
     dict = {"method" : method,
          "artist" : info_dict['Artist'],
          "api_key" : self.api_key}
     if method == "track.gettoptags":
         dict['track'] = info_dict['Track']
     encoded_values = urllib.urlencode(dict)
     url = self.url + "?" + encoded_values
     conn = HttpRequest(url) 
     xml_doc = conn.connect(xml=True)
     return self.parse_xml_doc(xml_doc, "name")
Exemplo n.º 7
0
 def get_user_top_tags(self, username, limit=15):
     #method user.getTopTags
     #Params
     #user (Required) : The user name
     #limit (Optional) : Limit the number of tags returned 
     #api_key (Required) : A Last.fm API key.
     encoded_values = urllib.urlencode(
         {"method" : "user.gettoptags",
          "user" : username,
          "limit" : limit,
          "api_key" : self.api_key}
         )
     url = self.url + "?" + encoded_values
     conn = HttpRequest(url) 
     xml_doc = conn.connect(xml=True)
     return self.parse_xml_doc(xml_doc, "name")
Exemplo n.º 8
0
 def _send_post(self, post_values):
     req = HttpRequest(url=self.submission_url, data=post_values, timeout=10)
     success, msg = req.connect()
     if success:
         self.deletion_ids.extend(self.del_ids)    
         return True
     else:
         if msg[0] == "BADSESSION":
             self.bad_session_count += 1
             server_response, message = self.handshake()
             if server_response == "OK" and self.bad_session_count <= 3:
                 return self._send_post(post_values)
             else:
                 self.parent.write_info(_("Error during handshake."))
         self.parent.write_info(_("There was an error sending data to last.fm:") +
                                "\n" + "\n".join(msg))
         return False
Exemplo n.º 9
0
 def set_user_image(self):
     webservice = webservices.LastfmWebService()
     url = "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=%s&api_key=%s"
     request = HttpRequest(url=url % (self.username, webservice.api_key), timeout=10)
     msg = request.connect(xml=True)
     image_url = webservice.parse_xml(msg, "image")
     if image_url is None:
         return
     if not os.path.exists(self.HOME_DIR + os.path.basename(image_url)):
         request = HttpRequest(image_url)
         request.retrieve(image_url, self.HOME_DIR + os.path.basename(image_url),
                          self.tree.get_widget("user_thumb"))
     else:
         image = gtk.gdk.pixbuf_new_from_file_at_size(self.HOME_DIR +
                                                      os.path.basename(image_url),
                                                      100, 40)
         self.tree.get_widget("user_thumb").set_from_pixbuf(image)
Exemplo n.º 10
0
 def get_popular_tags(self, method, info_dict):
     """method is either artist.gettoptags or track.gettoptags"""
     #Params
     #track (Optional) : The track name in question
     #artist (Required) : The artist name in question
     #api_key (Required) : A Last.fm API key.
     dict = {
         "method": method,
         "artist": info_dict['Artist'],
         "api_key": self.api_key
     }
     if method == "track.gettoptags":
         dict['track'] = info_dict['Track']
     encoded_values = urllib.urlencode(dict)
     url = self.url + "?" + encoded_values
     conn = HttpRequest(url)
     xml_doc = conn.connect(xml=True)
     return self.parse_xml_doc(xml_doc, "name")
Exemplo n.º 11
0
 def set_user_image(self):
     webservice = webservices.LastfmWebService()
     url = "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=%s&api_key=%s"
     request = HttpRequest(url=url % (self.username, webservice.api_key),
                           timeout=10)
     msg = request.connect(xml=True)
     image_url = webservice.parse_xml(msg, "image")
     if image_url is None:
         return
     if not os.path.exists(self.HOME_DIR + os.path.basename(image_url)):
         request = HttpRequest(image_url)
         request.retrieve(image_url,
                          self.HOME_DIR + os.path.basename(image_url),
                          self.tree.get_widget("user_thumb"))
     else:
         image = gtk.gdk.pixbuf_new_from_file_at_size(
             self.HOME_DIR + os.path.basename(image_url), 100, 40)
         self.tree.get_widget("user_thumb").set_from_pixbuf(image)
Exemplo n.º 12
0
 def _send_post(self, post_values):
     req = HttpRequest(url=self.submission_url,
                       data=post_values,
                       timeout=10)
     success, msg = req.connect()
     if success:
         self.deletion_ids.extend(self.del_ids)
         return True
     else:
         if msg[0] == "BADSESSION":
             self.bad_session_count += 1
             server_response, message = self.handshake()
             if server_response == "OK" and self.bad_session_count <= 3:
                 return self._send_post(post_values)
             else:
                 self.parent.write_info(_("Error during handshake."))
         self.parent.write_info(
             _("There was an error sending data to last.fm:") + "\n" +
             "\n".join(msg))
         return False
Exemplo n.º 13
0
 def handshake(self):
     self.handshake_attempts += 1
     self.timestamp = self.create_timestamp()
     self.authentication_code = self.create_authentication_code()
     self.url = self.base_url + r"/?" + self.encode_url()
     req = HttpRequest(url=self.url, timeout=10)
     success, response = req.connect()
     print req.handshake_response(response[0])
     if success:
         self.session_id = response[1]
         status = response[0]
         self.submission_url = response[3]
         if status != "OK":
             if self.handshake_attempts <= 3:
                 print "Handshake error attempt %d of 3" % self.handshake_attempts
                 return self.handshake()
             else:
                 return "FAILED", "Failed to make a handshake with Last.fm"
         else:
             self.handshake_attempts = 0
     msg = req.handshake_response(response[0])
     return response[0], msg
Exemplo n.º 14
0
 def handshake(self):
     self.handshake_attempts += 1
     self.timestamp = self.create_timestamp()
     self.authentication_code = self.create_authentication_code()
     self.url = self.base_url + r"/?" + self.encode_url()
     req = HttpRequest(url=self.url, timeout=10)
     success, response = req.connect()
     print req.handshake_response(response[0])
     if success:
         self.session_id = response[1]
         status = response[0]
         self.submission_url = response[3]
         if status != "OK":
             if self.handshake_attempts <= 3:
                 print "Handshake error attempt %d of 3" % self.handshake_attempts
                 return self.handshake()
             else:
                 return "FAILED", "Failed to make a handshake with Last.fm"
         else:
             self.handshake_attempts = 0
     msg = req.handshake_response(response[0])
     return response[0], msg