def parse_uktop40(): "Parses the top 40 songs from uktop40.com rss feed" url = r'http://www.uktop40.co.uk/official_top_40.rss' log.debug('Fetching %s...' % url) obj = urllib2.urlopen(url, timeout=config.webservices_timeout) response = obj.read() obj.close() soup = BeautifulSoup(response) songs = [x.text for x in soup.find_all('title')][2:] songs = [x.split(') ', 1)[1] for x in songs] songs = [utils.trim_between(utils.trim_between(x), '[', ']') for x in songs] songs = [utils.convert_html_entities(x) for x in songs] songs = [x.strip() for x in songs] return songs
def parse_uktop40(): "Parses the top 40 songs from uktop40.com rss feed" url = r'http://www.uktop40.co.uk/official_top_40.rss' log.debug('Fetching %s...' % url) obj = urllib2.urlopen(url, timeout=config.webservices_timeout) response = obj.read() obj.close() soup = BeautifulSoup(response) songs = [x.text for x in soup.find_all('title')][2:] songs = [x.split(') ', 1)[1] for x in songs] songs = [ utils.trim_between(utils.trim_between(x), '[', ']') for x in songs ] songs = [utils.convert_html_entities(x) for x in songs] songs = [x.strip() for x in songs] return songs
def parse(song, artist): "Function searches the web for song lyrics. returns a generator." s = '%s - %s' % (artist.strip(), song.strip()) if utils.isHebrew(song) or utils.isHebrew(artist): log.debug("Grabbing lyrics for %s from shironet.co.il..." % s) gen = parse_shironet(s) for lyrics in gen: yield lyrics else: # if english log.debug("Grabbing lyrics for %s from LyricsMode..." % song) gen = parse_LyricsMode(song, artist) for lyrics in gen: yield lyrics # lets try trim the ()'s or []'s _song = song _artist = artist song = utils.trim_between(_song) song = utils.trim_between(song, '[', ']') if song != _song: log.debug("Trimming %s --> %s" % (_song, song)) artist = utils.trim_between(_artist) artist = utils.trim_between(artist, '[', ']') if artist != _artist: log.debug("Trimming %s --> %s" % (_artist, artist)) ''' The following situation may happen: >>> song = "Train - 50 Ways To Say Goodbye" >>> artist = "Train" ''' x, y = utils.parse_title_from_filename(song) if artist: if artist.lower() == x.lower(): log.debug("Trimming %s --> %s" % (song, y)) song = y if artist.lower() == y.lower(): log.debug("Trimming %s --> %s" % (song, x)) song = x else: log.debug("Setting artist name from nothing to %s" % y) song, artist = x, y if artist != _artist or song != _song: s = '%s - %s' % (artist.strip(), song.strip()) log.debug("Grabbing lyrics for %s from LyricsMode..." % song) gen = parse_LyricsMode(song, artist) for lyrics in gen: yield lyrics log.debug("Grabbing lyrics for %s from OnlyLyrics..." % song) try: gen = parse_onlylyrics(song, artist) except socket.error: return for lyrics in gen: yield lyrics if len(artist.split()) == 2: flipped_artist = " ".join(artist.split(' ')[::-1]) log.debug("Grabbing lyrics for %s from OnlyLyrics (flipping last and first name)..." % song) try: gen = parse_onlylyrics(song, flipped_artist) except socket.error: return for lyrics in gen: yield lyrics log.debug("Grabbing lyrics for %s from ChartLyrics..." % song) try: gen = parse_ChartLyrics(song, artist) except socket.error: return for lyrics in gen: yield lyrics return
def parse(song, artist): "Function searches the web for song lyrics. returns a generator." s = '%s - %s' % (artist.strip(), song.strip()) if utils.isHebrew(song) or utils.isHebrew(artist): log.debug("Grabbing lyrics for %s from shironet.co.il..." % s) gen = parse_shironet(s) for lyrics in gen: yield lyrics else: # if english log.debug("Grabbing lyrics for %s from LyricsMode..." % song) gen = parse_LyricsMode(song, artist) for lyrics in gen: yield lyrics # lets try trim the ()'s or []'s _song = song _artist = artist song = utils.trim_between(_song) song = utils.trim_between(song, '[', ']') if song != _song: log.debug("Trimming %s --> %s" % (_song, song)) artist = utils.trim_between(_artist) artist = utils.trim_between(artist, '[', ']') if artist != _artist: log.debug("Trimming %s --> %s" % (_artist, artist)) ''' The following situation may happen: >>> song = "Train - 50 Ways To Say Goodbye" >>> artist = "Train" ''' x, y = utils.parse_title_from_filename(song) if artist: if artist.lower() == x.lower(): log.debug("Trimming %s --> %s" % (song, y)) song = y if artist.lower() == y.lower(): log.debug("Trimming %s --> %s" % (song, x)) song = x else: log.debug("Setting artist name from nothing to %s" % y) song, artist = x, y if artist != _artist or song != _song: s = '%s - %s' % (artist.strip(), song.strip()) log.debug("Grabbing lyrics for %s from LyricsMode..." % song) gen = parse_LyricsMode(song, artist) for lyrics in gen: yield lyrics log.debug("Grabbing lyrics for %s from OnlyLyrics..." % song) try: gen = parse_onlylyrics(song, artist) except socket.error: return for lyrics in gen: yield lyrics if len(artist.split()) == 2: flipped_artist = " ".join(artist.split(' ')[::-1]) log.debug( "Grabbing lyrics for %s from OnlyLyrics (flipping last and first name)..." % song) try: gen = parse_onlylyrics(song, flipped_artist) except socket.error: return for lyrics in gen: yield lyrics log.debug("Grabbing lyrics for %s from ChartLyrics..." % song) try: gen = parse_ChartLyrics(song, artist) except socket.error: return for lyrics in gen: yield lyrics return