From 95d4f6763038e2facee04dcd14b7eb401265a982 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Fri, 22 Feb 2013 01:38:24 +0100 Subject: [PATCH] suboob+attilasub works --- modules/attilasub/backend.py | 4 +-- modules/attilasub/browser.py | 9 +++--- modules/attilasub/pages.py | 36 ++++++++++++++++++++--- weboob/applications/suboob/suboob.py | 43 ++++++++++++++++++++++++++-- weboob/capabilities/subtitle.py | 1 + 5 files changed, 80 insertions(+), 13 deletions(-) diff --git a/modules/attilasub/backend.py b/modules/attilasub/backend.py index 8ff109ed..6b9bc6b9 100644 --- a/modules/attilasub/backend.py +++ b/modules/attilasub/backend.py @@ -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) diff --git a/modules/attilasub/browser.py b/modules/attilasub/browser.py index 00db1489..758a7fc3 100644 --- a/modules/attilasub/browser.py +++ b/modules/attilasub/browser.py @@ -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) diff --git a/modules/attilasub/pages.py b/modules/attilasub/pages.py index ff1c28d4..523b8f9b 100644 --- a/modules/attilasub/pages.py +++ b/modules/attilasub/pages.py @@ -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 diff --git a/weboob/applications/suboob/suboob.py b/weboob/applications/suboob/suboob.py index 04d2bb41..248364ff 100644 --- a/weboob/applications/suboob/suboob.py +++ b/weboob/applications/suboob/suboob.py @@ -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: diff --git a/weboob/capabilities/subtitle.py b/weboob/capabilities/subtitle.py index 31c57e00..39a3d2cb 100644 --- a/weboob/capabilities/subtitle.py +++ b/weboob/capabilities/subtitle.py @@ -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)