diff --git a/modules/attilasub/browser.py b/modules/attilasub/browser.py index a0fa9642..26b19d43 100644 --- a/modules/attilasub/browser.py +++ b/modules/attilasub/browser.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.tools.browser import BaseBrowser +from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound from .pages import SubtitlesPage, SearchPage @@ -29,7 +29,7 @@ __all__ = ['AttilasubBrowser'] class AttilasubBrowser(BaseBrowser): DOMAIN = 'davidbillemont3.free.fr' PROTOCOL = 'http' - ENCODING = 'utf-8' + ENCODING = 'windows-1252' USER_AGENT = BaseBrowser.USER_AGENTS['wget'] PAGES = { 'http://search.freefind.com/find.html.*': SearchPage, @@ -43,6 +43,9 @@ class AttilasubBrowser(BaseBrowser): def get_subtitle(self, id): url_end = id.split('|')[0] - self.location('http://davidbillemont3.free.fr/%s' % url_end) + try: + self.location('http://davidbillemont3.free.fr/%s' % url_end) + except BrowserHTTPNotFound: + return 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 bddeeb73..3c334add 100644 --- a/modules/attilasub/pages.py +++ b/modules/attilasub/pages.py @@ -99,7 +99,7 @@ class SubtitlesPage(BasePage): original_title = " ".join(original_title_words) nb_cd = self.parser.select(cols[2],'font',1).text.strip() - nb_cd = int(nb_cd.split()[0]) + nb_cd = int(nb_cd.strip(' CD')) 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 diff --git a/weboob/applications/cineoob/cineoob.py b/weboob/applications/cineoob/cineoob.py index 067114f1..49695301 100644 --- a/weboob/applications/cineoob/cineoob.py +++ b/weboob/applications/cineoob/cineoob.py @@ -23,8 +23,10 @@ import sys from datetime import datetime from weboob.applications.weboorrents.weboorrents import TorrentInfoFormatter, TorrentListFormatter +from weboob.applications.suboob.suboob import SubtitleInfoFormatter, SubtitleListFormatter from weboob.capabilities.torrent import ICapTorrent from weboob.capabilities.cinema import ICapCinema +from weboob.capabilities.subtitle import ICapSubtitle from weboob.capabilities.base import NotAvailable,NotLoaded from weboob.tools.application.repl import ReplApplication from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter @@ -148,13 +150,15 @@ class Cineoob(ReplApplication): ", list persons related to a movie, list movies related to a person and list common movies " \ "of two persons." SHORT_DESCRIPTION = "search movies and persons around cinema" - CAPS = (ICapCinema,ICapTorrent) + CAPS = (ICapCinema,ICapTorrent,ICapSubtitle) EXTRA_FORMATTERS = {'movie_list': MovieListFormatter, 'movie_info': MovieInfoFormatter, 'person_list': PersonListFormatter, 'person_info': PersonInfoFormatter, 'torrent_list': TorrentListFormatter, 'torrent_info': TorrentInfoFormatter, + 'subtitle_list': SubtitleListFormatter, + 'subtitle_info': SubtitleInfoFormatter } COMMANDS_FORMATTERS = {'search_movie': 'movie_list', 'info_movie': 'movie_info', @@ -167,6 +171,9 @@ class Cineoob(ReplApplication): 'search_torrent': 'torrent_list', 'search_movie_torrent': 'torrent_list', 'info_torrent': 'torrent_info', + 'search_subtitle': 'subtitle_list', + 'search_movie_subtitle': 'subtitle_list', + 'info_subtitle': 'subtitle_info' } ROLE_LIST = ['actor','director','writer','composer','producer'] COUNTRY_LIST = ['us','fr','de','jp'] @@ -521,3 +528,117 @@ class Cineoob(ReplApplication): for backend, torrent in self.do('iter_torrents', pattern=pattern, caps=ICapTorrent): self.cached_format(torrent) self.flush() + + #================== SUBTITLE ================== + + def complete_info_subtitle(self, text, line, *ignored): + args = line.split(' ') + if len(args) == 2: + return self._complete_object() + + def do_info_subtitle(self, id): + """ + info_subtitle subtitle_ID + + Get information about a subtitle. + """ + + subtitle = None + _id, backend = self.parse_id(id) + for _backend, result in self.do('get_subtitle', _id, backends=backend, caps=ICapSubtitle): + if result: + backend = _backend + subtitle = result + if not subtitle: + print >>sys.stderr, 'Subtitle not found: %s' % id + return 3 + + self.start_format() + self.format(subtitle) + self.flush() + + + def complete_getfile_subtitle(self, text, line, *ignored): + args = line.split(' ', 2) + if len(args) == 2: + return self._complete_object() + elif len(args) >= 3: + return self.path_completer(args[2]) + + def do_getfile_subtitle(self, line): + """ + getfile_subtitle subtitle_ID [FILENAME] + + Get the subtitle or archive file. + FILENAME is where to write the file. If FILENAME is '-', + the file is written to stdout. + """ + id, dest = self.parse_command_args(line, 2, 1) + + _id, backend_name = self.parse_id(id) + + if dest is None: + dest = '%s' % _id + + try: + for backend, buf in self.do('get_subtitle_file', _id, backends=backend_name, caps=ICapSubtitle): + if buf: + if dest == '-': + print buf + else: + try: + with open(dest, 'w') as f: + f.write(buf) + except IOError, e: + print >>sys.stderr, 'Unable to write file in "%s": %s' % (dest, e) + return 1 + return + except CallErrors, errors: + for backend, error, backtrace in errors: + self.bcall_error_handler(backend, error, backtrace) + + print >>sys.stderr, 'Subtitle "%s" not found' % id + return 3 + + def do_search_subtitle(self,line): + """ + search_subtitle language [PATTERN] + + Search subtitles. + """ + language, pattern = self.parse_command_args(line, 2, 1) + self.change_path([u'search subtitle']) + if not pattern: + pattern = None + + self.start_format(pattern=pattern) + for backend, subtitle in self.do('iter_subtitles', language=language, pattern=pattern, caps=ICapSubtitle): + self.cached_format(subtitle) + self.flush() + + def do_search_movie_subtitle(self,line): + """ + search_movie_subtitle language movie_ID + + Search subtitles of movie_ID. + """ + language, id = self.parse_command_args(line, 2, 2) + movie = None + _id, backend = self.parse_id(id) + for _backend, result in self.do('get_movie', _id, backends=backend, caps=ICapCinema): + if result: + backend = _backend + movie = result + if not movie: + print >>sys.stderr, 'Movie not found: %s' % id + return 3 + + pattern = movie.original_title + self.change_path([u'search subtitle']) + if not pattern: + pattern = None + + self.start_format(pattern=pattern) + for backend, subtitle in self.do('iter_subtitles', language=language, pattern=pattern, caps=ICapSubtitle): + self.cached_format(subtitle) + self.flush()