Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (56 sloc) 2.675 kB
229bf37 Primeira versão do plugin
Fonini authored
1 # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
2 #
3 # Copyright (C) 2010 Jonnas Fonini <contato@fonini.net>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # The Rhythmbox authors hereby grant permission for non-GPL compatible
11 # GStreamer plugins to be used and distributed together with GStreamer
12 # and Rhythmbox. This permission is above and beyond the permissions granted
13 # by the GPL license by which Rhythmbox is covered. If you modify this code
14 # you may extend this exception to your version of the code, but you are not
15 # obligated to do so. If you do not wish to do so, delete this exception
16 # statement from your version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27 import urllib
28 import re
29 import rb
30 import HTMLParser
31
32 from unicodedata import normalize
33
34
35 class VagalumeParser (object):
36 def __init__(self, artist, title):
37 self.artist = artist
38 self.title = title
39
40
41 def search(self, callback, *data):
42 artist = normalize('NFKD', self.artist.decode('utf-8')).encode('ASCII','ignore')
43 title = normalize('NFKD', self.title.decode('utf-8')).encode('ASCII','ignore')
44
45 artist = urllib.quote(artist.replace('(', '').replace(')', '').replace(' ', '-').replace('\'', ''))
46 title = urllib.quote(title.replace('(', '').replace(')', '').replace(' ', '-').replace('\'', ''))
47
48 url = 'http://vagalume.uol.com.br/%s/%s.html' % (artist, title)
49
50 loader = rb.Loader()
51 loader.get_url (url, self.got_lyrics, callback, *data)
52
53 def got_lyrics(self, lyric, callback, *data):
54 lyric = re.sub('<[Bb][Rr][^>]*>', '', lyric)
55
56 if re.search('<div class="tab_original">([^<]*)', lyric) is not None:
57 body = re.split('<div class="tab_original">([^<]*)', lyric)[1]
58
59 pars = HTMLParser.HTMLParser()
60 body = pars.unescape(body)
61
62 title = re.split('<h1>(.*)</h1>', lyric)[1]
63 artist = re.split('<h2 class="head"><a href=(.*)>(.*)</a></h2>', lyric)[2]
64
65 title = "%s - %s\n\n" % (artist, title)
66 lyric = title + body
67 lyric += "\n\nLyrics provided by vagalume.com.br"
68
69 callback(lyric, *data)
70 else:
71 callback (None, *data)
72
Something went wrong with that request. Please try again.