Exemple #1
0
    def download(self, subtitles, selected_subtitle, path=None):
        """
        downloads and returns path to subtitles file(can be compressed)

        @param subtitles: subtitles list returned by search function
        @param selected_subtitle: subtitle from subtitles list which will be downloaded
        @param path: if provided then this path will be used as download path instead
                                      of default download path

        raises SubtitlesDownloadError
        """
        self.log.info("download - selected_subtitle: %s, path: %s" % (toString(selected_subtitle['filename']), toString(path)))
        try:
            compressed, lang, filepath = self._download(subtitles, selected_subtitle, toString(path))
        except SubtitlesDownloadError as e:
            self.log.error("download error occured: %s" % str(e))
            e.provider = self.id
            raise e
        except Exception:
            exc_value, exc_traceback = sys.exc_info()[1:]
            self.log.error("unknown download error occured: %s" % str(exc_value))
            self.log.error("traceback: \n%s"% "".join(traceback.format_tb(exc_traceback)))
            err = SubtitlesDownloadError(SubtitlesErrors.UNKNOWN_ERROR, str(exc_value))
            err.provider = self.id
            err.wrapped_error = exc_value
            raise err

        self.log.info("download finished, compressed: %s, lang: %s, filepath:%s" % (toString(compressed), toString(lang), toString(filepath)))
        return compressed, lang, filepath
Exemple #2
0
 def _download(self, subtitles, selected_subtitle, path=None):
     subtitles_list = subtitles['list']
     session_id = subtitles['session_id']
     pos = subtitles_list.index(selected_subtitle)
     zip_subs = os.path.join(toString(self.tmp_path), toString(selected_subtitle['filename']))
     tmp_sub_dir = toString(self.tmp_path)
     if path is not None:
         sub_folder = toString(path)
     else:
         sub_folder = toString(self.tmp_path)
     self.module.settings_provider = self.settings_provider
     # Standard output -
     # True if the file is packed as zip: addon will automatically unpack it.
     # language of subtitles,
     # Name of subtitles file if not packed (or if we unpacked it ourselves)
     # return False, language, subs_file
     compressed, language, filepath = self.module.download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id)
     if compressed != False:
         if compressed == True or compressed == "":
             compressed = "zip"
         else:
             compressed = filepath
         if not os.path.isfile(filepath):
             filepath = zip_subs
     else:
         filepath = os.path.join(sub_folder, filepath)
     return  compressed, language, filepath
Exemple #3
0
    def download(self, subtitles, selected_subtitle, path=None):
        """
        downloads and returns path to subtitles file(can be compressed)

        @param subtitles: subtitles list returned by search function
        @param selected_subtitle: subtitle from subtitles list which will be downloaded
        @param path: if provided then this path will be used as download path instead
                                      of default download path

        raises SubtitlesDownloadError
        """
        self.log.info("download - selected_subtitle: %s,  path: %s" % (toString(selected_subtitle['filename']), toString(path)))
        try:
            compressed, lang, filepath = self._download(subtitles, selected_subtitle, toString(path))
        except SubtitlesDownloadError as e:
            self.log.error("download error occured: %s" % str(e))
            e.provider = self.id
            raise e
        except Exception:
            exc_value, exc_traceback = sys.exc_info()[1:]
            self.log.error("unknown download error occured: %s" % str(exc_value))
            self.log.error("traceback: \n%s"% "".join(traceback.format_tb(exc_traceback)))
            err = SubtitlesDownloadError(SubtitlesErrors.UNKNOWN_ERROR, str(exc_value))
            err.provider = self.id
            err.wrapped_error = exc_value
            raise err

        self.log.info("download finished,  compressed: %s, lang: %s, filepath:%s" % (toString(compressed), toString(lang), toString(filepath)))
        return compressed, lang, filepath
Exemple #4
0
 def _search(self, title, filepath, langs, season, episode, tvshow, year):
     file_original_path = filepath and filepath or ""
     title = title and title or file_original_path
     season = season if season else ""
     episode = episode if episode else ""
     tvshow = tvshow if tvshow else ""
     year = year if year else ""
     if len(langs) > 3:
         self.log.info('more then three languages provided, only first three will be selected')
     if len(langs) == 0:
         self.log.info('no languages provided will use default ones')
         lang1 = self.lang1
         lang2 = self.lang2
         lang3 = self.lang3
     elif len(langs) == 1:
         lang1 = lang2= lang3 = languageTranslate(langs[0],2,0)
     elif len(langs) == 2:
         lang1 = lang3 = languageTranslate(langs[0],2,0)
         lang2 = languageTranslate(langs[1],2,0)
     elif len(langs) == 3:
         lang1 = languageTranslate(langs[0],2,0)
         lang2 = languageTranslate(langs[1],2,0)
         lang3 = languageTranslate(langs[2],2,0)
     self.log.info('using langs %s %s %s'%(toString(lang1), toString(lang2), toString(lang3)))
     self.module.settings_provider = self.settings_provider
     # Standard output -
     # subtitles list
     # session id (e.g a cookie string, passed on to download_subtitles),
     # message to print back to the user
     # return subtitlesList, "", msg
     subtitles_list, session_id, msg = self.module.search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp=False, rar=False, lang1=lang1, lang2=lang2, lang3=lang3, stack=None)
     return {'list':subtitles_list, 'session_id':session_id, 'msg':msg}