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,7 +17,7 @@
|
|||
# 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,Subtitle
|
||||
from weboob.capabilities.subtitle import ICapSubtitle, LanguageNotSupported, Subtitle
|
||||
from weboob.applications.suboob.suboob import LANGUAGE_CONV
|
||||
from weboob.tools.backend import BaseBackend
|
||||
|
||||
|
|
@ -53,15 +53,15 @@ class OpensubtitlesBackend(BaseBackend, ICapSubtitle):
|
|||
def iter_subtitles(self, language, pattern):
|
||||
if language not in LANGUAGE_CONV.keys():
|
||||
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')))
|
||||
|
||||
def fill_subtitle(self, subtitle, fields):
|
||||
if 'description' in fields:
|
||||
sub = self.get_subtitle(subtitle.id)
|
||||
subtitle.description = sub.description
|
||||
subtitle.description = sub.description
|
||||
|
||||
return subtitle
|
||||
|
||||
OBJECTS = {
|
||||
Subtitle:fill_subtitle,
|
||||
}
|
||||
Subtitle: fill_subtitle,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,13 +35,14 @@ class OpensubtitlesBrowser(BaseBrowser):
|
|||
PAGES = {
|
||||
'http://www.opensubtitles.org.*search2/sublanguageid.*moviename.*': SearchPage,
|
||||
'http://www.opensubtitles.org.*search/sublanguageid.*idmovie.*': SubtitlesPage,
|
||||
'http://www.opensubtitles.org.*search/imdbid.*/sublanguageid.*/moviename.*' : SubtitlesPage,
|
||||
'http://www.opensubtitles.org.*subtitles/[0-9]*/.*' : SubtitlePage
|
||||
}
|
||||
'http://www.opensubtitles.org.*search/imdbid.*/sublanguageid.*/moviename.*': SubtitlesPage,
|
||||
'http://www.opensubtitles.org.*subtitles/[0-9]*/.*': SubtitlePage
|
||||
}
|
||||
|
||||
def iter_subtitles(self, language, pattern):
|
||||
lang = LANGUAGE_CONV[language]
|
||||
self.location('http://www.opensubtitles.org/search2/sublanguageid-%s/moviename-%s' % (lang,pattern.encode('utf-8')))
|
||||
self.location('http://www.opensubtitles.org/search2/sublanguageid-%s/moviename-%s' % (
|
||||
lang, pattern.encode('utf-8')))
|
||||
assert self.is_on_page(SearchPage) or self.is_on_page(SubtitlesPage) or self.is_on_page(SubtitlePage)
|
||||
return self.page.iter_subtitles()
|
||||
|
||||
|
|
|
|||
|
|
@ -24,24 +24,24 @@ from weboob.tools.browser import BasePage
|
|||
from weboob.applications.suboob.suboob import LANGUAGE_CONV
|
||||
|
||||
|
||||
__all__ = ['SubtitlesPage','SubtitlePage','SearchPage']
|
||||
__all__ = ['SubtitlesPage', 'SubtitlePage', 'SearchPage']
|
||||
|
||||
|
||||
class SearchPage(BasePage):
|
||||
""" Page which contains results as a list of movies
|
||||
"""
|
||||
def iter_subtitles(self):
|
||||
tabresults = self.parser.select(self.document.getroot(),'table#search_results')
|
||||
tabresults = self.parser.select(self.document.getroot(), 'table#search_results')
|
||||
if len(tabresults) > 0:
|
||||
table = tabresults[0]
|
||||
# for each result line, explore the subtitle list page to iter subtitles
|
||||
for line in self.parser.select(table,'tr'):
|
||||
links = self.parser.select(line,'a')
|
||||
for line in self.parser.select(table, 'tr'):
|
||||
links = self.parser.select(line, 'a')
|
||||
if len(links) > 0:
|
||||
a = links[0]
|
||||
url = a.attrib.get('href','')
|
||||
url = a.attrib.get('href', '')
|
||||
if "ads.opensubtitles" not in url:
|
||||
self.browser.location("http://www.opensubtitles.org%s"%url)
|
||||
self.browser.location("http://www.opensubtitles.org%s" % url)
|
||||
assert self.browser.is_on_page(SubtitlesPage) or self.browser.is_on_page(SubtitlePage)
|
||||
# subtitles page does the job
|
||||
for subtitle in self.browser.page.iter_subtitles():
|
||||
|
|
@ -52,48 +52,48 @@ class SubtitlesPage(BasePage):
|
|||
""" Page which contains several subtitles for a single movie
|
||||
"""
|
||||
def iter_subtitles(self):
|
||||
tabresults = self.parser.select(self.document.getroot(),'table#search_results')
|
||||
tabresults = self.parser.select(self.document.getroot(), 'table#search_results')
|
||||
if len(tabresults) > 0:
|
||||
table = tabresults[0]
|
||||
# for each result line, get informations
|
||||
# why following line doesn't work all the time (for example 'search fr sopranos guy walks' ?
|
||||
#for line in self.parser.select(table,'tr'):
|
||||
# for line in self.parser.select(table,'tr'):
|
||||
for line in table.getiterator('tr'):
|
||||
# some tr are useless, specially ads
|
||||
if line.attrib.get('id','').startswith('name'):
|
||||
if line.attrib.get('id', '').startswith('name'):
|
||||
yield self.get_subtitle_from_line(line)
|
||||
|
||||
def get_subtitle_from_line(self,line):
|
||||
cells = self.parser.select(line,'td')
|
||||
def get_subtitle_from_line(self, line):
|
||||
cells = self.parser.select(line, 'td')
|
||||
if len(cells) > 0:
|
||||
links = self.parser.select(line,'a')
|
||||
links = self.parser.select(line, 'a')
|
||||
a = links[0]
|
||||
name = u" ".join(a.text.strip().split())
|
||||
first_cell = cells[0]
|
||||
spanlist = self.parser.select(first_cell,'span')
|
||||
spanlist = self.parser.select(first_cell, 'span')
|
||||
if len(spanlist) > 0:
|
||||
long_name = spanlist[0].attrib.get('title','')
|
||||
long_name = spanlist[0].attrib.get('title', '')
|
||||
else:
|
||||
texts = first_cell.itertext()
|
||||
long_name = texts.next()
|
||||
long_name = texts.next()
|
||||
if "Download at 25" in long_name:
|
||||
long_name = "---"
|
||||
name = "%s (%s)"%(name,long_name)
|
||||
name = "%s (%s)" % (name, long_name)
|
||||
second_cell = cells[1]
|
||||
link = self.parser.select(second_cell,'a',1)
|
||||
lang = link.attrib.get('href','').split('/')[-1].split('-')[-1]
|
||||
for lshort,llong in LANGUAGE_CONV.items():
|
||||
link = self.parser.select(second_cell, 'a', 1)
|
||||
lang = link.attrib.get('href', '').split('/')[-1].split('-')[-1]
|
||||
for lshort, llong in LANGUAGE_CONV.items():
|
||||
if lang == llong:
|
||||
lang = unicode(lshort)
|
||||
break
|
||||
nb_cd = int(cells[2].text.strip().lower().replace('cd',''))
|
||||
nb_cd = int(cells[2].text.strip().lower().replace('cd', ''))
|
||||
cell_dl = cells[4]
|
||||
href = self.parser.select(cell_dl,'a',1).attrib.get('href','')
|
||||
url = unicode('http://www.opensubtitles.org%s'%href)
|
||||
href = self.parser.select(cell_dl, 'a', 1).attrib.get('href', '')
|
||||
url = unicode('http://www.opensubtitles.org%s' % href)
|
||||
id = href.split('/')[-1]
|
||||
|
||||
subtitle = Subtitle(id,name)
|
||||
subtitle = Subtitle(id, name)
|
||||
subtitle.url = url
|
||||
subtitle.language = lang
|
||||
subtitle.nb_cd = nb_cd
|
||||
|
|
@ -106,15 +106,15 @@ class SubtitlePage(BasePage):
|
|||
"""
|
||||
def get_subtitle(self):
|
||||
desc = NotAvailable
|
||||
father = self.parser.select(self.document.getroot(),'a#app_link',1).getparent()
|
||||
a = self.parser.select(father,'a')[1]
|
||||
id = a.attrib.get('href','').split('/')[-1]
|
||||
url = unicode('http://www.opensubtitles.org/subtitleserve/sub/%s'%id)
|
||||
link = self.parser.select(self.document.getroot(),'link[rel=bookmark]',1)
|
||||
title = unicode(link.attrib.get('title',''))
|
||||
father = self.parser.select(self.document.getroot(), 'a#app_link', 1).getparent()
|
||||
a = self.parser.select(father, 'a')[1]
|
||||
id = a.attrib.get('href', '').split('/')[-1]
|
||||
url = unicode('http://www.opensubtitles.org/subtitleserve/sub/%s' % id)
|
||||
link = self.parser.select(self.document.getroot(), 'link[rel=bookmark]', 1)
|
||||
title = unicode(link.attrib.get('title', ''))
|
||||
nb_cd = int(title.lower().split('cd')[0].split()[-1])
|
||||
lang = unicode(title.split('(')[1].split(')')[0])
|
||||
file_names = self.parser.select(self.document.getroot(),"img[title~=filename]")
|
||||
file_names = self.parser.select(self.document.getroot(), "img[title~=filename]")
|
||||
if len(file_names) > 0:
|
||||
file_name = file_names[0].getparent().text_content()
|
||||
file_name = ' '.join(file_name.split())
|
||||
|
|
@ -122,11 +122,11 @@ class SubtitlePage(BasePage):
|
|||
for f in file_names:
|
||||
desc_line = f.getparent().text_content()
|
||||
desc += '\n'+' '.join(desc_line.split())
|
||||
name = unicode('%s (%s)'%(title,file_name))
|
||||
name = unicode('%s (%s)' % (title, file_name))
|
||||
|
||||
subtitle = Subtitle(id,name)
|
||||
subtitle = Subtitle(id, name)
|
||||
subtitle.url = url
|
||||
for lshort,llong in LANGUAGE_CONV.items():
|
||||
for lshort, llong in LANGUAGE_CONV.items():
|
||||
if lang == llong:
|
||||
lang = unicode(lshort)
|
||||
break
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class OpensubtitlesTest(BackendTest):
|
|||
|
||||
def test_subtitle(self):
|
||||
lsub = []
|
||||
subtitles = self.backend.iter_subtitles('fr','spiderman')
|
||||
subtitles = self.backend.iter_subtitles('fr', 'spiderman')
|
||||
for i in range(5):
|
||||
subtitle = subtitles.next()
|
||||
lsub.append(subtitle)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue