[opensub] multi sub result page
This commit is contained in:
parent
50d69004f6
commit
1f03dc7c7f
2 changed files with 59 additions and 72 deletions
|
|
@ -46,6 +46,10 @@ class OpensubtitlesBrowser(BaseBrowser):
|
||||||
return self.page.iter_subtitles()
|
return self.page.iter_subtitles()
|
||||||
|
|
||||||
def get_subtitle(self, id):
|
def get_subtitle(self, id):
|
||||||
|
""" the id is formed this way : id_movie|id_file
|
||||||
|
the id_movie helps to find the page
|
||||||
|
the id_file help to find the file into the page
|
||||||
|
"""
|
||||||
ids = id.split('|')
|
ids = id.split('|')
|
||||||
id_movie = ids[0]
|
id_movie = ids[0]
|
||||||
id_file = ids[1]
|
id_file = ids[1]
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ __all__ = ['SubtitlesPage','SearchPage']
|
||||||
|
|
||||||
|
|
||||||
class SearchPage(BasePage):
|
class SearchPage(BasePage):
|
||||||
|
""" Page which contains results as a list of movies
|
||||||
|
"""
|
||||||
def iter_subtitles(self):
|
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:
|
if len(tabresults) > 0:
|
||||||
|
|
@ -48,7 +50,7 @@ class SearchPage(BasePage):
|
||||||
if "ads.opensubtitles" in url:
|
if "ads.opensubtitles" in url:
|
||||||
continue
|
continue
|
||||||
self.browser.location("http://www.opensubtitles.org%s"%url)
|
self.browser.location("http://www.opensubtitles.org%s"%url)
|
||||||
# TODO verifier pourquoi on ne chope pas toutes les lignes. plusieurs tableaux ?
|
# TODO verifier si on ne chope pas toutes les lignes. plusieurs tableaux ?
|
||||||
assert self.browser.is_on_page(SubtitlesPage) or self.browser.is_on_page(SubtitlePage)
|
assert self.browser.is_on_page(SubtitlesPage) or self.browser.is_on_page(SubtitlePage)
|
||||||
# subtitles page does the job
|
# subtitles page does the job
|
||||||
for subtitle in self.browser.page.iter_subtitles():
|
for subtitle in self.browser.page.iter_subtitles():
|
||||||
|
|
@ -56,81 +58,62 @@ class SearchPage(BasePage):
|
||||||
|
|
||||||
|
|
||||||
class SubtitlesPage(BasePage):
|
class SubtitlesPage(BasePage):
|
||||||
def get_subtitle(self,id):
|
""" Page which contains several subtitles for a single movie
|
||||||
return []
|
"""
|
||||||
href = id.split('|')[1]
|
def get_subtitle(self,id_file):
|
||||||
# we have to find the 'tr' which contains the link to this address
|
tabresults = self.parser.select(self.document.getroot(),'table#search_results')
|
||||||
a = self.parser.select(self.document.getroot(),'a[href="%s"]'%href,1)
|
if len(tabresults) > 0:
|
||||||
line = a.getparent().getparent().getparent().getparent().getparent()
|
table = tabresults[0]
|
||||||
cols = self.parser.select(line,'td')
|
# for each result line, get informations
|
||||||
traduced_title = self.parser.select(cols[0],'font',1).text.lower()
|
for line in table.getiterator('tr'):
|
||||||
original_title = self.parser.select(cols[1],'font',1).text.lower()
|
idline = line.attrib.get('id','').replace('name','')
|
||||||
nb_cd = self.parser.select(cols[2],'font',1).text.strip()
|
if idline == id_file:
|
||||||
nb_cd = int(nb_cd.split()[0])
|
return self.get_subtitle_from_line(line)
|
||||||
|
|
||||||
traduced_title_words = traduced_title.split()
|
|
||||||
original_title_words = original_title.split()
|
|
||||||
|
|
||||||
# this is to trash special spacing chars
|
|
||||||
traduced_title = " ".join(traduced_title_words)
|
|
||||||
original_title = " ".join(original_title_words)
|
|
||||||
|
|
||||||
name = "%s (%s)"%(original_title,traduced_title)
|
|
||||||
url = "http://davidbillemont3.free.fr/%s"%href
|
|
||||||
subtitle = Subtitle(id,name)
|
|
||||||
subtitle.url = url
|
|
||||||
subtitle.fps = 0
|
|
||||||
subtitle.language = "fre"
|
|
||||||
subtitle.nb_cd = nb_cd
|
|
||||||
subtitle.description = "no desc"
|
|
||||||
return subtitle
|
|
||||||
|
|
||||||
def iter_subtitles(self):
|
def iter_subtitles(self):
|
||||||
return
|
# TODO verifier les ads
|
||||||
pattern = pattern.strip().replace('+',' ')
|
tabresults = self.parser.select(self.document.getroot(),'table#search_results')
|
||||||
pattern_words = pattern.split()
|
if len(tabresults) > 0:
|
||||||
tab = self.parser.select(self.document.getroot(),'table[bordercolor="#B8C0B2"]')
|
table = tabresults[0]
|
||||||
if len(tab) == 0:
|
# for each result line, get informations
|
||||||
tab = self.parser.select(self.document.getroot(),'table[bordercolordark="#B8C0B2"]')
|
for line in table.getiterator('tr'):
|
||||||
if len(tab) == 0:
|
yield self.get_subtitle_from_line(line)
|
||||||
return
|
|
||||||
# some results of freefind point on useless pages
|
|
||||||
if tab[0].attrib.get('width','') != '100%':
|
|
||||||
return
|
|
||||||
for line in tab[0].getiterator('tr'):
|
|
||||||
cols = self.parser.select(line,'td')
|
|
||||||
traduced_title = self.parser.select(cols[0],'font',1).text.lower()
|
|
||||||
original_title = self.parser.select(cols[1],'font',1).text.lower()
|
|
||||||
|
|
||||||
traduced_title_words = traduced_title.split()
|
def get_subtitle_from_line(self,line):
|
||||||
original_title_words = original_title.split()
|
id_movie = line.attrib.get('id','').replace('name','')
|
||||||
|
cells = self.parser.select(line,'td')
|
||||||
|
if len(cells) > 0:
|
||||||
|
first_cell = cells[0]
|
||||||
|
links = self.parser.select(line,'a')
|
||||||
|
a = links[0]
|
||||||
|
urldetail = a.attrib.get('href','')
|
||||||
|
name = a.text
|
||||||
|
long_name = self.parser.select(first_cell,'span').attrib.get('title','')
|
||||||
|
name = "%s (%s)"%(name,long_name)
|
||||||
|
second_cell = cells[1]
|
||||||
|
link = self.parser.select(second_cell,'a',1)
|
||||||
|
lang = link.attrib.get('onclick','').split('/')[-1].split('-')[-1]
|
||||||
|
nb_cd = cells[2].text.strip().lower().replace('CD','')
|
||||||
|
fps = 0
|
||||||
|
desc = ''
|
||||||
|
cell_dl = cells[4]
|
||||||
|
href = self.parser.select(cell_dl,'a',1).attrib.get('href','')
|
||||||
|
url = "http://www.opensubtitles.org%s"%href
|
||||||
|
id_file = href.split('/')[-1]
|
||||||
|
|
||||||
# if the pattern is one word and in the title OR if the
|
id = "%s|%s"%(id_movie,id_file)
|
||||||
# intersection between pattern and the title is at least 2 words
|
subtitle = Subtitle(id,name)
|
||||||
if (len(pattern_words) == 1 and pattern in traduced_title_words) or\
|
subtitle.url = url
|
||||||
(len(pattern_words) == 1 and pattern in original_title_words) or\
|
subtitle.fps = fps
|
||||||
(len(list(set(pattern_words) & set(traduced_title_words))) > 1) or\
|
subtitle.language = lang
|
||||||
(len(list(set(pattern_words) & set(original_title_words))) > 1):
|
subtitle.nb_cd = nb_cd
|
||||||
|
subtitle.description = "no desc"
|
||||||
|
return subtitle
|
||||||
|
|
||||||
# this is to trash special spacing chars
|
|
||||||
traduced_title = " ".join(traduced_title_words)
|
|
||||||
original_title = " ".join(original_title_words)
|
|
||||||
|
|
||||||
nb_cd = self.parser.select(cols[2],'font',1).text.strip()
|
|
||||||
nb_cd = int(nb_cd.split()[0])
|
|
||||||
name = "%s (%s)"%(original_title,traduced_title)
|
|
||||||
href = self.parser.select(cols[3],'a',1).attrib.get('href','')
|
|
||||||
url = "http://davidbillemont3.free.fr/%s"%href
|
|
||||||
id = "%s|%s"%(self.browser.geturl().split('/')[-1],href)
|
|
||||||
subtitle = Subtitle(id,name)
|
|
||||||
subtitle.url = url
|
|
||||||
subtitle.fps = 0
|
|
||||||
subtitle.language = "fre"
|
|
||||||
subtitle.nb_cd = nb_cd
|
|
||||||
subtitle.description = "no desc"
|
|
||||||
yield subtitle
|
|
||||||
|
|
||||||
class SubtitlePage(BasePage):
|
class SubtitlePage(BasePage):
|
||||||
|
""" Page which contains a single subtitle for a movie
|
||||||
|
"""
|
||||||
def get_subtitle(self,id):
|
def get_subtitle(self,id):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue