home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / rhythmbox / plugins / lyrics / AstrawebParser.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.9 KB  |  66 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import urllib
  5. import re
  6. import rb
  7.  
  8. class AstrawebParser(object):
  9.     
  10.     def __init__(self, artist, title):
  11.         self.artist = artist
  12.         self.title = title
  13.  
  14.     
  15.     def search(self, callback, *data):
  16.         wartist = re.sub('%20', '+', urllib.quote(self.artist))
  17.         wtitle = re.sub('%20', '+', urllib.quote(self.title))
  18.         wurl = 'http://search.lyrics.astraweb.com/?word=%s+%s' % (wartist, wtitle)
  19.         loader = rb.Loader()
  20.         loader.get_url(wurl, self.got_results, callback, *data)
  21.  
  22.     
  23.     def got_results(self, result, callback, *data):
  24.         if result is None:
  25.             callback(None, *data)
  26.             return None
  27.         results = re.sub('\n', '', re.sub('\r', '', result))
  28.         if re.search('(<tr><td bgcolor="#BBBBBB".*)(More Songs >)', results) is not None:
  29.             body = re.split('(<tr><td bgcolor="#BBBBBB".*)(More Songs >)', results)[1]
  30.             entries = re.split('<tr><td bgcolor="#BBBBBB"', body)
  31.             entries.pop(0)
  32.             print 'found %d entries; looking for [%s,%s]' % (len(entries), self.title.lower().strip(), self.artist.lower().strip())
  33.             for entry in entries:
  34.                 url = re.split('(\\/display[^"]*)', entry)[1]
  35.                 artist = re.split('(Artist:.*html">)([^<]*)', entry)[2]
  36.                 title = re.split('(\\/display[^>]*)([^<]*)', entry)[2][1:]
  37.                 print 'checking [%s,%s]' % (title.lower().strip(), artist.lower().strip())
  38.                 if title.lower().find(self.title.lower().strip()) != -1:
  39.                     if artist.lower().find(self.artist.lower().strip()) != -1:
  40.                         loader = rb.Loader()
  41.                         loader.get_url('http://display.lyrics.astraweb.com' + url, self.parse_lyrics, callback, *data)
  42.                         return None
  43.                     continue
  44.                 artist.lower().find(self.artist.lower().strip()) != -1
  45.             
  46.         
  47.         callback(None, *data)
  48.  
  49.     
  50.     def parse_lyrics(self, result, callback, *data):
  51.         if result is None:
  52.             callback(None, *data)
  53.             return None
  54.         result = re.sub('\n', '', re.sub('\r', '', result))
  55.         artist_title = re.split('(<title>Lyrics: )([^<]*)', result)[2]
  56.         artist = artist_title.split(' - ')[0]
  57.         title = artist_title.split(' - ')[1]
  58.         title = '%s - %s\n\n' % (artist, title)
  59.         lyrics = re.split('(<font face=arial size=2>)(.*)(<\\/font><br></td><td*)', result)[2]
  60.         lyrics = title + lyrics
  61.         lyrics = re.sub('<[Bb][Rr][^>]*>', '\n', lyrics)
  62.         lyrics += '\n\nLyrics provided by lyrics.astraweb.com'
  63.         callback(lyrics, *data)
  64.  
  65.  
  66.