suboob+attilasub works
This commit is contained in:
parent
591db5c1be
commit
95d4f67630
5 changed files with 80 additions and 13 deletions
|
|
@ -39,8 +39,8 @@ class AttilasubBackend(BaseBackend, ICapSubtitle):
|
|||
def create_default_browser(self):
|
||||
return self.create_browser()
|
||||
|
||||
#def get_subtitle(self, id):
|
||||
# return self.browser.get_subtitle(id)
|
||||
def get_subtitle(self, id):
|
||||
return self.browser.get_subtitle(id)
|
||||
|
||||
def get_subtitle_file(self, id):
|
||||
subtitle = self.browser.get_subtitle(id)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class AttilasubBrowser(BaseBrowser):
|
|||
assert self.is_on_page(SearchPage)
|
||||
return self.page.iter_subtitles(pattern)
|
||||
|
||||
#def get_torrent(self, id):
|
||||
# self.location('http://kat.ph/%s.html' % id)
|
||||
# assert self.is_on_page(TorrentPage)
|
||||
# return self.page.get_torrent(id)
|
||||
def get_subtitle(self, id):
|
||||
url_end = id.split('|')[0]
|
||||
self.location('http://davidbillemont3.free.fr/%s' % url_end)
|
||||
assert self.is_on_page(SubtitlesPage)
|
||||
return self.page.get_subtitle(id)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ __all__ = ['SubtitlesPage','SearchPage']
|
|||
class SearchPage(BasePage):
|
||||
def iter_subtitles(self,pattern):
|
||||
fontresult = self.parser.select(self.document.getroot(),'div.search-results font.search-results')
|
||||
# for each result in freefind, explore the page to iter subtitles
|
||||
# for each result in freefind, explore the subtitle list page to iter subtitles
|
||||
for res in fontresult:
|
||||
a = self.parser.select(res,'a',1)
|
||||
url = a.attrib.get('href','')
|
||||
|
|
@ -49,6 +49,30 @@ class SearchPage(BasePage):
|
|||
|
||||
|
||||
class SubtitlesPage(BasePage):
|
||||
def get_subtitle(self,id):
|
||||
href = id.split('|')[1]
|
||||
# we have to find the 'tr' which contains the link to this address
|
||||
a = self.parser.select(self.document.getroot(),'a[href="%s"]'%href,1)
|
||||
line = a.getparent().getparent().getparent().getparent().getparent()
|
||||
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()
|
||||
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.description = "no desc"
|
||||
return subtitle
|
||||
|
||||
def iter_subtitles(self,pattern):
|
||||
pattern = pattern.strip().replace('+',' ')
|
||||
pattern_words = pattern.split()
|
||||
|
|
@ -76,8 +100,12 @@ class SubtitlesPage(BasePage):
|
|||
traduced_title = " ".join(traduced_title_words)
|
||||
original_title = " ".join(original_title_words)
|
||||
|
||||
title = "%s (%s)"%(original_title,traduced_title)
|
||||
subtitle = Subtitle(title,title)
|
||||
subtitle.url = self.parser.select(cols[3],'a',1).attrib.get('href','')
|
||||
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.description = "no desc"
|
||||
yield subtitle
|
||||
|
|
|
|||
|
|
@ -37,14 +37,27 @@ def sizeof_fmt(num):
|
|||
num /= 1024.0
|
||||
|
||||
|
||||
class SubtitleInfoFormatter(IFormatter):
|
||||
MANDATORY_FIELDS = ('id', 'name', 'url', 'fps', 'description')
|
||||
|
||||
def format_obj(self, obj, alias):
|
||||
result = u'%s%s%s\n' % (self.BOLD, obj.name, self.NC)
|
||||
result += 'ID: %s\n' % obj.fullid
|
||||
result += 'URL: %s\n' % obj.url
|
||||
result += 'FPS: %s\n' % obj.fps
|
||||
result += '\n%sDescription%s\n' % (self.BOLD, self.NC)
|
||||
result += obj.description
|
||||
return result
|
||||
|
||||
|
||||
class SubtitleListFormatter(PrettyFormatter):
|
||||
MANDATORY_FIELDS = ('id', 'name', 'url', 'fps')
|
||||
MANDATORY_FIELDS = ('id', 'name', 'url')
|
||||
|
||||
def get_title(self, obj):
|
||||
return obj.name
|
||||
|
||||
def get_description(self, obj):
|
||||
return '(%s fps)' % (obj.fps)
|
||||
return 'url : %s' % (obj.url)
|
||||
|
||||
|
||||
class Suboob(ReplApplication):
|
||||
|
|
@ -55,11 +68,35 @@ class Suboob(ReplApplication):
|
|||
"and download them."
|
||||
SHORT_DESCRIPTION = "search and download subtitles"
|
||||
CAPS = ICapSubtitle
|
||||
EXTRA_FORMATTERS = {'subtitle_list': SubtitleListFormatter
|
||||
EXTRA_FORMATTERS = {'subtitle_list': SubtitleListFormatter,
|
||||
'subtitle_info': SubtitleInfoFormatter
|
||||
}
|
||||
COMMANDS_FORMATTERS = {'search': 'subtitle_list',
|
||||
'info': 'subtitle_info'
|
||||
}
|
||||
|
||||
def complete_info(self, text, line, *ignored):
|
||||
args = line.split(' ')
|
||||
if len(args) == 2:
|
||||
return self._complete_object()
|
||||
|
||||
def do_info(self, id):
|
||||
"""
|
||||
info ID
|
||||
|
||||
Get information about a subtitle.
|
||||
"""
|
||||
|
||||
subtitle = self.get_object(id, 'get_subtitle')
|
||||
if not subtitle:
|
||||
print >>sys.stderr, 'Subtitle not found: %s' % id
|
||||
return 3
|
||||
|
||||
self.start_format()
|
||||
self.format(subtitle)
|
||||
self.flush()
|
||||
|
||||
|
||||
def complete_getfile(self, text, line, *ignored):
|
||||
args = line.split(' ', 2)
|
||||
if len(args) == 2:
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class Subtitle(CapBaseObject):
|
|||
name = StringField('Name of subtitle')
|
||||
url = StringField('Direct url to subtitle file')
|
||||
fps = StringField('Framerate of corresponding video')
|
||||
description = StringField('Description of corresponding video')
|
||||
|
||||
def __init__(self, id, name):
|
||||
CapBaseObject.__init__(self, id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue