Commit 09c54510 authored by Vincent A's avatar Vincent A

capbands + metalarchives: cosmetics and rename some classes and pyflakes

parent 1e0a74be
Pipeline #2904 passed with stages
in 15 minutes and 45 seconds
......@@ -19,7 +19,6 @@
from __future__ import unicode_literals
from .module import MetalarchivesModule
......
......@@ -17,15 +17,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from weboob.browser import URL, LoginBrowser, need_login
from .pages import BandPage, SearchBandsPage, LoginPage, FavoritesPage, SuggestionsPage, AlbumPage
__all__ = ['MetalArchivesBrowser']
class MetalArchivesBrowser(LoginBrowser):
"""
Browsing the Metal Archives website.
......@@ -33,11 +33,11 @@ class MetalArchivesBrowser(LoginBrowser):
BASEURL = 'https://www.metal-archives.com/'
login = URL('authentication/login', LoginPage)
bands = URL('search/ajax-band-search/\?field=name&query=(?P<pattern>.*)', SearchBandsPage)
bands = URL(r'search/ajax-band-search/\?field=name&query=(?P<pattern>.*)', SearchBandsPage)
band = URL('bands/Band/(?P<band_id>.*)', BandPage)
albums = URL('band/discography/id/(?P<band_id>.*)/tab/all', AlbumPage)
favorites = URL('bookmark/ajax-list/type/band\?sEcho=1', FavoritesPage)
suggested = URL('band/ajax-recommendations/id/(?P<band_id>.*)\?showMoreSimilar=1', SuggestionsPage)
favorites = URL(r'bookmark/ajax-list/type/band\?sEcho=1', FavoritesPage)
suggested = URL(r'band/ajax-recommendations/id/(?P<band_id>.*)\?showMoreSimilar=1', SuggestionsPage)
def do_login(self):
d = {
......
......@@ -17,10 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from weboob.browser.pages import JsonPage, HTMLPage
from weboob.browser.elements import ItemElement, ListElement, DictElement, method
from weboob.browser.filters.json import Dict
......@@ -28,7 +26,7 @@ from weboob.browser.filters.standard import (
Regexp, CleanText, Format, Env,
)
from weboob.browser.filters.html import Link
from weboob.capabilities.bands import Bandinfo, Bandsearch, Favorites, Albums, Suggestions
from weboob.capabilities.bands import BandInfo, BandSearch, Favorite, Albums, Suggestion
class LoginPage(HTMLPage):
......@@ -47,7 +45,7 @@ class SearchBandsPage(JsonPage):
ignore_duplicate = True
class item(ItemElement):
klass = Bandsearch
klass = BandSearch
obj_id = Regexp(Dict('0'), '/([0-9]+)\\"')
obj_name = Regexp(Dict('0'), '>([^<]+)')
obj_short_description = Format('Genre: %s - Country: %s', Dict('1'), Dict('2'))
......@@ -59,7 +57,7 @@ class BandPage(HTMLPage):
"""
@method
class get_info(ItemElement):
klass = Bandinfo
klass = BandInfo
obj_id = Env('band_id')
obj_name = CleanText('//h1[@class="band_name"]/a/text()')
......@@ -98,7 +96,7 @@ class FavoritesPage(JsonPage):
ignore_duplicate = True
class item(ItemElement):
klass = Favorites
klass = Favorite
obj_id = Regexp(Dict('0'), '/([0-9]+)\\"')
obj_name = Regexp(Dict('0'), '>([^<]+)')
......@@ -114,8 +112,9 @@ class SuggestionsPage(HTMLPage):
class iter_suggestions(ListElement):
# Takes all the <td> except the last one that is not a band
item_xpath = '//tbody/tr[position() < last()]'
class item(ItemElement):
klass = Suggestions
klass = Suggestion
obj_id = Regexp(Link('./td[2]/a'), '/([0-9]+)')
obj_name = CleanText('./td[2]/a/text()')
......
......@@ -17,19 +17,17 @@
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import Capability, BaseObject, StringField, UserError
from datetime import datetime, date
from weboob.tools.compat import basestring, unicode
__all__ = [
'BandInfo', 'BandSearch', 'Albums', 'BandNotFound',
'Suggestion', 'Favorite',
'CapBands',
]
from .base import Capability, BaseObject, Field, StringField, UserError, NotLoaded
from .date import DateField
__all__ = ['Bandinfo', 'Band', 'Albums', 'BandNotFound', 'CapBands']
class Bandsearch(BaseObject):
class BandSearch(BaseObject):
"""
Bands search.
"""
......@@ -37,7 +35,7 @@ class Bandsearch(BaseObject):
short_description = StringField('Short description of the band')
def __init__(self, id='', name=None, short_description=None, url=None):
super(Bandsearch, self).__init__(id, url)
super(BandSearch, self).__init__(id, url)
self.name = name
self.short_description = short_description
......@@ -49,7 +47,7 @@ class BandNotFound(UserError):
pass
class Bandinfo(BaseObject):
class BandInfo(BaseObject):
"""
Information about one specific band.
"""
......@@ -60,7 +58,7 @@ class Bandinfo(BaseObject):
description = StringField('Description of the band')
def __init__(self, name=None, year=None, country=None, genre=None, description=None, url=None):
super(Bandinfo, self).__init__(id, url)
super(BandInfo, self).__init__(id, url)
self.name = name
self.genre = genre
self.year = year
......@@ -85,7 +83,7 @@ class Albums(BaseObject):
self.reviews = reviews
class Favorites(BaseObject):
class Favorite(BaseObject):
"""
Fetch your favorite bands.
"""
......@@ -94,13 +92,13 @@ class Favorites(BaseObject):
short_description = StringField('Short description of the favorite band')
def __init__(self, id='', name=None, band_url=None, short_description=None):
super(Favorites, self).__init__(id, name)
super(Favorite, self).__init__(id, name)
self.name = name
self.band_url = band_url
self.short_description = short_description
class Suggestions(BaseObject):
class Suggestion(BaseObject):
"""
Band suggestions based on your favorite bands.
"""
......@@ -109,7 +107,7 @@ class Suggestions(BaseObject):
url = StringField('URL of suggested band')
def __init__(self, id='', name=None, description=None, url=None):
super(Suggestions, self).__init__(id, url)
super(Suggestion, self).__init__(id, url)
self.name = name
self.url = url
self.description = description
......@@ -125,20 +123,18 @@ class CapBands(Capability):
Look for a band.
:param pattern: pattern to search
:type pattern: str
:rtype: iter[:class:`Bandsearch`]
:rtype: iter[:class:`BandSearch`]
"""
raise NotImplementedError()
def get_info(self):
"""
Get band info.
:param band_id: ID of the band
:rtype: :class:`Bandinfo`
:rtype: :class:`BandInfo`
"""
raise NotImplementedError()
def get_albums(self):
"""
Get a band's discography.
......@@ -147,20 +143,18 @@ class CapBands(Capability):
"""
raise NotImplementedError()
def get_favorites(self):
"""
Get my favorite bands.
:rtype: iter[:class:`Favorites`]
:rtype: iter[:class:`Favorite`]
"""
raise NotImplementedError()
def suggestions(self):
"""
Get band suggestions according to your favorite bands.
:rtype: iter[:class:`Suggestions`]
:rtype: iter[:class:`Suggestion`]
"""
raise NotImplementedError()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment