Exemplo n.º 1
0
 def get_songs(self):
     ''' do some tricky stuff to get the songs of an artist account '''
     if self.__get_artist_id() and self.__get_playlist_id():
         #xml_page = try_open(uris.mediaBase[0] + str(self.artistID) + uris.mediaBase[1] + str(self.playlistID) + uris.mediaBase[2] + str(self.uid) + uris.mediaBase[3])
         xml_page = try_open(uris.mediaBase[0] + str(self.playlistID) + uris.mediaBase[1] + str(self.artistID) + uris.mediaBase[2] + str(self.uid))
         if xml_page:
             xml = xml_page.read()
             #print xml
             xml_struct = minidom.parseString(xml)
             song_list = xml_struct.getElementsByTagName('song')
             xml_page.close()
             for song in song_list:
                 # trickery to get the songs - one http request for each song :-/
                 song_plays = song.getElementsByTagName('stats')[0].getAttribute('plays')
                 songID = song.getAttribute('songId')
                 resp = try_open(uris.songBase[0] + str(songID) + uris.songBase[1])
                 xml2 = resp.read()
                 #print xml2
                 this_xml = minidom.parseString(xml2)
                 # add to mopy rdf
                 track = mopy.mo.Track(os.path.join(uris.dbtune, 'uid',self.uid+'.rdf#'+songID))
                 try:
                     track.plays.set(int(song_plays))
                 except ValueError:
                     pass # sometimes we get empty string '' which throws ValueError
                 try:
                     song_title = this_xml.getElementsByTagName('title')[0].firstChild.nodeValue
                 except (AttributeError, IndexError):
                     pass
                 else:
                     track.title.set(song_title)
                 try:
                     song_image = this_xml.getElementsByTagName('small')[0].firstChild.nodeValue
                 except (AttributeError, IndexError):
                     pass
                 else:
                     img = mopy.foaf.Image(song_image)
                     track.depiction.set(img)
                 try:
                     song_avas = this_xml.getElementsByTagName('rtmp')[0].firstChild.nodeValue
                 except (AttributeError, IndexError):
                     pass
                 else:
                     avas = mopy.mo.MusicalItem(song_avas)
                     track.available_as.set(avas)
                     self.mi.add(avas)
                 self.subject.made.add(track)
                 self.mi.add(track)
Exemplo n.º 2
0
 def get_page(self):
     if self.url != None:
         resp = try_open(self.url, try_num=0, limit=3)
         if resp==None:
             raise MyspaceException, 'failed to open url '+str(self.url)
         self.html = resp.read()
         self.soup = BS(self.html)
         resp.close()
     else:
         self.html = None