[booblyrics] new backend parolesmusique
This commit is contained in:
parent
0628802b72
commit
05fab92a48
6 changed files with 239 additions and 1 deletions
3
modules/parolesmusique/__init__.py
Normal file
3
modules/parolesmusique/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from .backend import ParolesmusiqueBackend
|
||||
|
||||
__all__ = ['ParolesmusiqueBackend']
|
||||
46
modules/parolesmusique/backend.py
Normal file
46
modules/parolesmusique/backend.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013 Julien Veyssier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from weboob.capabilities.lyrics import ICapLyrics
|
||||
from weboob.tools.backend import BaseBackend
|
||||
|
||||
from .browser import ParolesmusiqueBrowser
|
||||
|
||||
from urllib import quote_plus
|
||||
|
||||
__all__ = ['ParolesmusiqueBackend']
|
||||
|
||||
|
||||
class ParolesmusiqueBackend(BaseBackend, ICapLyrics):
|
||||
NAME = 'parolesmusique'
|
||||
MAINTAINER = u'Julien Veyssier'
|
||||
EMAIL = 'julien.veyssier@aiur.fr'
|
||||
VERSION = '0.f'
|
||||
DESCRIPTION = 'paroles-musique lyrics website'
|
||||
LICENSE = 'AGPLv3+'
|
||||
BROWSER = ParolesmusiqueBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
return self.create_browser()
|
||||
|
||||
def get_lyrics(self, id):
|
||||
return self.browser.get_lyrics(id)
|
||||
|
||||
def iter_lyrics(self, criteria, pattern):
|
||||
return self.browser.iter_lyrics(criteria,pattern.encode('utf-8'))
|
||||
50
modules/parolesmusique/browser.py
Normal file
50
modules/parolesmusique/browser.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013 Julien Veyssier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage, HomePage
|
||||
|
||||
|
||||
__all__ = ['ParolesmusiqueBrowser']
|
||||
|
||||
|
||||
class ParolesmusiqueBrowser(BaseBrowser):
|
||||
DOMAIN = 'www.paroles-musique.com'
|
||||
PROTOCOL = 'http'
|
||||
ENCODING = 'utf-8'
|
||||
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
||||
PAGES = {
|
||||
'http://www.paroles-musique.com': HomePage,
|
||||
'http://www.paroles-musique.com/lyrics-paroles-0-.*,0.php': SongResultsPage,
|
||||
'http://www.paroles-musique.com/lyrics-paroles-.*-0,0.php': ArtistResultsPage,
|
||||
'http://www.paroles-musique.com/paroles-.*p[0-9]*': SonglyricsPage,
|
||||
'http://www.paroles-musique.com/paroles-.*-lyrics,a[0-9]*': ArtistSongsPage,
|
||||
}
|
||||
|
||||
def iter_lyrics(self, criteria, pattern):
|
||||
self.location('http://www.paroles-musique.com')
|
||||
assert self.is_on_page(HomePage)
|
||||
return self.page.iter_lyrics(criteria,pattern)
|
||||
|
||||
def get_lyrics(self, id):
|
||||
self.location('http://www.paroles-musique.com/paroles-%s' % id)
|
||||
assert self.is_on_page(SonglyricsPage)
|
||||
return self.page.get_lyrics(id)
|
||||
93
modules/parolesmusique/pages.py
Normal file
93
modules/parolesmusique/pages.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013 Julien Veyssier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.capabilities.lyrics import SongLyrics
|
||||
from weboob.capabilities.base import NotAvailable, NotLoaded
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
|
||||
__all__ = ['SongResultsPage','SonglyricsPage', 'ArtistResultsPage', 'ArtistSongsPage', 'HomePage']
|
||||
|
||||
|
||||
class HomePage(BasePage):
|
||||
def iter_lyrics(self,criteria,pattern):
|
||||
self.browser.select_form(name='rechercher')
|
||||
if criteria == 'artist':
|
||||
self.browser['termes_a'] = pattern
|
||||
else:
|
||||
self.browser['termes_t'] = pattern
|
||||
self.browser.submit()
|
||||
assert self.browser.is_on_page(SongResultsPage) or self.browser.is_on_page(ArtistResultsPage)
|
||||
for lyr in self.browser.page.iter_lyrics():
|
||||
yield lyr
|
||||
|
||||
class ArtistResultsPage(BasePage):
|
||||
def iter_lyrics(self):
|
||||
for link in self.parser.select(self.document.getroot(),'div.cont_cat table a.std'):
|
||||
artist = unicode(link.text_content())
|
||||
self.browser.location('http://www.paroles-musique.com%s'%link.attrib.get('href',''))
|
||||
assert self.browser.is_on_page(ArtistSongsPage)
|
||||
for lyr in self.browser.page.iter_lyrics(artist):
|
||||
yield lyr
|
||||
|
||||
|
||||
class ArtistSongsPage(BasePage):
|
||||
def iter_lyrics(self,artist):
|
||||
for link in self.parser.select(self.document.getroot(),'div.cont_catA div.art_scroll a'):
|
||||
href = link.attrib.get('href','')
|
||||
if href.startswith('./paroles'):
|
||||
title = unicode(link.text)
|
||||
id = href.replace('./paroles-','')
|
||||
songlyrics = SongLyrics(id, title)
|
||||
songlyrics.artist = artist
|
||||
songlyrics.content = NotLoaded
|
||||
yield songlyrics
|
||||
|
||||
|
||||
class SongResultsPage(BasePage):
|
||||
def iter_lyrics(self):
|
||||
first = True
|
||||
for tr in self.parser.select(self.document.getroot(),'div.cont_cat table tr'):
|
||||
if first:
|
||||
first = False
|
||||
continue
|
||||
artist = NotAvailable
|
||||
links = self.parser.select(tr,'a.std')
|
||||
title = unicode(links[0].text)
|
||||
id = links[0].attrib.get('href','').replace('/paroles-','')
|
||||
artist = unicode(links[1].text)
|
||||
songlyrics = SongLyrics(id, title)
|
||||
songlyrics.artist = artist
|
||||
songlyrics.content = NotLoaded
|
||||
yield songlyrics
|
||||
|
||||
|
||||
class SonglyricsPage(BasePage):
|
||||
def get_lyrics(self, id):
|
||||
artist = NotAvailable
|
||||
title = NotAvailable
|
||||
content = unicode(self.parser.select(self.document.getroot(),'div#lyr_scroll',1).text_content().strip())
|
||||
infos = self.parser.select(self.document.getroot(),'h2.lyrics > font')
|
||||
artist = unicode(infos[0].text)
|
||||
title = unicode(infos[1].text)
|
||||
songlyrics = SongLyrics(id, title)
|
||||
songlyrics.artist = artist
|
||||
songlyrics.content = content
|
||||
return songlyrics
|
||||
46
modules/parolesmusique/test.py
Normal file
46
modules/parolesmusique/test.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013 Julien Veyssier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from weboob.tools.test import BackendTest
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
|
||||
class SeeklyricsTest(BackendTest):
|
||||
BACKEND = 'parolesmusique'
|
||||
|
||||
def test_search_song_n_get(self):
|
||||
l_lyrics = list(self.backend.iter_lyrics('song','chien'))
|
||||
for songlyrics in l_lyrics:
|
||||
assert songlyrics.id
|
||||
assert songlyrics.title
|
||||
assert songlyrics.artist
|
||||
assert songlyrics.content is NotLoaded
|
||||
full_lyr = self.backend.get_lyrics(songlyrics.id)
|
||||
assert full_lyr.id
|
||||
assert full_lyr.title
|
||||
assert full_lyr.artist
|
||||
assert full_lyr.content is not NotLoaded
|
||||
|
||||
|
||||
def test_search_artist(self):
|
||||
l_lyrics = list(self.backend.iter_lyrics('artist','boris'))
|
||||
for songlyrics in l_lyrics:
|
||||
assert songlyrics.id
|
||||
assert songlyrics.title
|
||||
assert songlyrics.artist
|
||||
assert songlyrics.content is NotLoaded
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013
|
||||
# Copyright(C) 2013 Julien Veyssier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue