autopep8 with 120 chars line length on my modules
This commit is contained in:
parent
6a7bc0924d
commit
5d923bc73b
39 changed files with 434 additions and 426 deletions
|
|
@ -17,10 +17,10 @@
|
|||
# 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.subtitle import ICapSubtitle,LanguageNotSupported
|
||||
from weboob.capabilities.subtitle import ICapSubtitle, LanguageNotSupported
|
||||
from weboob.tools.backend import BaseBackend
|
||||
|
||||
from .browser import TvsubtitlesBrowser,LANGUAGE_LIST
|
||||
from .browser import TvsubtitlesBrowser, LANGUAGE_LIST
|
||||
|
||||
from urllib import quote_plus
|
||||
|
||||
|
|
@ -52,4 +52,4 @@ class TvsubtitlesBackend(BaseBackend, ICapSubtitle):
|
|||
def iter_subtitles(self, language, pattern):
|
||||
if language not in LANGUAGE_LIST:
|
||||
raise LanguageNotSupported()
|
||||
return self.browser.iter_subtitles(language,quote_plus(pattern.encode('utf-8')))
|
||||
return self.browser.iter_subtitles(language, quote_plus(pattern.encode('utf-8')))
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@
|
|||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from .pages import SeriePage, SearchPage, SeasonPage,HomePage
|
||||
from .pages import SeriePage, SearchPage, SeasonPage, HomePage
|
||||
|
||||
|
||||
__all__ = ['TvsubtitlesBrowser']
|
||||
|
||||
LANGUAGE_LIST = ['en','es','fr','de','br','ru','ua','it','gr',
|
||||
'ar','hu','pl','tr','nl','pt','sv','da','fi',
|
||||
'ko','cn','jp','bg','cz','ro']
|
||||
LANGUAGE_LIST = ['en', 'es', 'fr', 'de', 'br', 'ru', 'ua', 'it', 'gr',
|
||||
'ar', 'hu', 'pl', 'tr', 'nl', 'pt', 'sv', 'da', 'fi',
|
||||
'ko', 'cn', 'jp', 'bg', 'cz', 'ro']
|
||||
|
||||
|
||||
class TvsubtitlesBrowser(BaseBrowser):
|
||||
|
|
@ -39,13 +39,13 @@ class TvsubtitlesBrowser(BaseBrowser):
|
|||
'http://www.tvsubtitles.net': HomePage,
|
||||
'http://www.tvsubtitles.net/search.php': SearchPage,
|
||||
'http://www.tvsubtitles.net/tvshow-.*.html': SeriePage,
|
||||
'http://www.tvsubtitles.net/subtitle-[0-9]*-[0-9]*-.*.html' : SeasonPage
|
||||
}
|
||||
'http://www.tvsubtitles.net/subtitle-[0-9]*-[0-9]*-.*.html': SeasonPage
|
||||
}
|
||||
|
||||
def iter_subtitles(self, language, pattern):
|
||||
self.location('http://www.tvsubtitles.net')
|
||||
assert self.is_on_page(HomePage)
|
||||
return self.page.iter_subtitles(language,pattern)
|
||||
return self.page.iter_subtitles(language, pattern)
|
||||
|
||||
def get_subtitle(self, id):
|
||||
self.location('http://www.tvsubtitles.net/subtitle-%s.html' % id)
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ from weboob.capabilities.subtitle import Subtitle
|
|||
from weboob.tools.browser import BasePage
|
||||
|
||||
|
||||
__all__ = ['HomePage','SearchPage','SeriePage','SeasonPage']
|
||||
__all__ = ['HomePage', 'SearchPage', 'SeriePage', 'SeasonPage']
|
||||
|
||||
|
||||
class HomePage(BasePage):
|
||||
def iter_subtitles(self,language,pattern):
|
||||
def iter_subtitles(self, language, pattern):
|
||||
self.browser.select_form(nr=0)
|
||||
self.browser['q'] = pattern.encode('utf-8')
|
||||
self.browser.submit()
|
||||
|
|
@ -38,15 +38,15 @@ class HomePage(BasePage):
|
|||
class SearchPage(BasePage):
|
||||
""" Page which contains results as a list of series
|
||||
"""
|
||||
def iter_subtitles(self,language):
|
||||
list_result = self.parser.select(self.document.getroot(),'div.left_articles ul')
|
||||
def iter_subtitles(self, language):
|
||||
list_result = self.parser.select(self.document.getroot(), 'div.left_articles ul')
|
||||
if len(list_result) > 0:
|
||||
li_result = self.parser.select(list_result[0],'li')
|
||||
li_result = self.parser.select(list_result[0], 'li')
|
||||
for line in li_result:
|
||||
if len(self.parser.select(line,'img[alt=%s]'%language)) > 0:
|
||||
link = self.parser.select(line,'a',1)
|
||||
href = link.attrib.get('href','')
|
||||
self.browser.location("http://%s%s"%(self.browser.DOMAIN,href))
|
||||
if len(self.parser.select(line, 'img[alt=%s]' % language)) > 0:
|
||||
link = self.parser.select(line, 'a', 1)
|
||||
href = link.attrib.get('href', '')
|
||||
self.browser.location("http://%s%s" % (self.browser.DOMAIN, href))
|
||||
assert self.browser.is_on_page(SeriePage)
|
||||
for subtitle in self.browser.page.iter_subtitles(language):
|
||||
yield subtitle
|
||||
|
|
@ -55,26 +55,27 @@ class SearchPage(BasePage):
|
|||
class SeriePage(BasePage):
|
||||
""" Page of all seasons
|
||||
"""
|
||||
def iter_subtitles(self,language,only_one_season=False):
|
||||
def iter_subtitles(self, language, only_one_season=False):
|
||||
# handle the current season
|
||||
last_table_line = self.parser.select(self.document.getroot(),'table#table5 tr')[-1]
|
||||
amount = int(self.parser.select(last_table_line,'td')[2].text_content())
|
||||
last_table_line = self.parser.select(self.document.getroot(), 'table#table5 tr')[-1]
|
||||
amount = int(self.parser.select(last_table_line, 'td')[2].text_content())
|
||||
if amount > 0:
|
||||
my_lang_img = self.parser.select(last_table_line,'img[alt=%s]'%language)
|
||||
my_lang_img = self.parser.select(last_table_line, 'img[alt=%s]' % language)
|
||||
if len(my_lang_img) > 0:
|
||||
url_current_season = self.browser.geturl().split('/')[-1].replace('tvshow','subtitle').replace('.html','-%s.html'%language)
|
||||
url_current_season = self.browser.geturl().split('/')[-1].replace(
|
||||
'tvshow', 'subtitle').replace('.html', '-%s.html' % language)
|
||||
self.browser.location(url_current_season)
|
||||
assert self.browser.is_on_page(SeasonPage)
|
||||
yield self.browser.page.iter_subtitles()
|
||||
|
||||
if not only_one_season:
|
||||
# handle the other seasons by following top links
|
||||
other_seasons_links = self.parser.select(self.document.getroot(),'p.description a')
|
||||
other_seasons_links = self.parser.select(self.document.getroot(), 'p.description a')
|
||||
for link in other_seasons_links:
|
||||
href = link.attrib.get('href','')
|
||||
self.browser.location("http://%s/%s"%(self.browser.DOMAIN,href))
|
||||
href = link.attrib.get('href', '')
|
||||
self.browser.location("http://%s/%s" % (self.browser.DOMAIN, href))
|
||||
assert self.browser.is_on_page(SeriePage)
|
||||
for subtitle in self.browser.page.iter_subtitles(language,True):
|
||||
for subtitle in self.browser.page.iter_subtitles(language, True):
|
||||
yield subtitle
|
||||
|
||||
|
||||
|
|
@ -82,19 +83,19 @@ class SeasonPage(BasePage):
|
|||
""" Page of a season with the right language
|
||||
"""
|
||||
def get_subtitle(self):
|
||||
filename_line = self.parser.select(self.document.getroot(),'img[alt=filename]',1).getparent().getparent()
|
||||
name = unicode(self.parser.select(filename_line,'td')[2].text)
|
||||
id = self.browser.geturl().split('/')[-1].replace('.html','').replace('subtitle-','')
|
||||
url = unicode('http://%s/download-%s.html'%(self.browser.DOMAIN,id))
|
||||
amount_line = self.parser.select(self.document.getroot(),'tr[title~=amount]',1)
|
||||
nb_cd = int(self.parser.select(amount_line,'td')[2].text)
|
||||
filename_line = self.parser.select(self.document.getroot(), 'img[alt=filename]', 1).getparent().getparent()
|
||||
name = unicode(self.parser.select(filename_line, 'td')[2].text)
|
||||
id = self.browser.geturl().split('/')[-1].replace('.html', '').replace('subtitle-', '')
|
||||
url = unicode('http://%s/download-%s.html' % (self.browser.DOMAIN, id))
|
||||
amount_line = self.parser.select(self.document.getroot(), 'tr[title~=amount]', 1)
|
||||
nb_cd = int(self.parser.select(amount_line, 'td')[2].text)
|
||||
lang = unicode(url.split('-')[-1].split('.html')[0])
|
||||
filenames_line = self.parser.select(self.document.getroot(),'tr[title~=list]',1)
|
||||
file_names = self.parser.select(filenames_line,'td')[2].text_content().strip().replace('.srt','.srt\n')
|
||||
filenames_line = self.parser.select(self.document.getroot(), 'tr[title~=list]', 1)
|
||||
file_names = self.parser.select(filenames_line, 'td')[2].text_content().strip().replace('.srt', '.srt\n')
|
||||
desc = u"files :\n"
|
||||
desc += file_names
|
||||
|
||||
subtitle = Subtitle(id,name)
|
||||
subtitle = Subtitle(id, name)
|
||||
subtitle.url = url
|
||||
subtitle.language = lang
|
||||
subtitle.nb_cd = nb_cd
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TvsubtitlesTest(BackendTest):
|
|||
BACKEND = 'tvsubtitles'
|
||||
|
||||
def test_subtitle(self):
|
||||
subtitles = list(self.backend.iter_subtitles('fr','sopranos'))
|
||||
subtitles = list(self.backend.iter_subtitles('fr', 'sopranos'))
|
||||
assert (len(subtitles) > 0)
|
||||
for subtitle in subtitles:
|
||||
assert subtitle.url.startswith('http')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue