Beispiel #1
0
 def languages(self, languages):
     """Setter for languages"""
     logger.debug(u'Setting languages to %r' % languages)
     self._languages = []
     for l in languages:
         if l not in list_languages(1):
             raise InvalidLanguageError(l)
         if not l in self._languages:
             self._languages.append(l)
 def fromPath(cls, path):
     extension = ''
     for e in EXTENSIONS:
         if path.endswith(e):
             extension = e
             break
     if not extension:
         raise ValueError('Not a supported subtitle extension')
     language = os.path.splitext(path[:len(path) - len(extension)])[1][1:]
     if not language in list_languages(1):
         language = None
     return cls(path, language)
Beispiel #3
0
    def listSubtitles(self, entries, auto=False):
        """
        Search subtitles within the plugins and return all found subtitles in a list of Subtitle object.

        Attributes:
            entries -- filepath or folderpath of video file or a list of that
            auto    -- automaticaly manage workers (default to False)"""
        if auto:
            if self.state != IDLE:
                raise BadStateError(self.state, IDLE)
            self.startWorkers()
        if isinstance(entries, basestring):
            entries = [entries]
        config = utils.PluginConfig(self.multi, self.cache_dir, self.filemode)
        scan_result = []
        for e in entries:
            if not isinstance(e, unicode):
                logger.warning(u'Entry %r is not unicode' % e)
            scan_result.extend(videos.scan(e))
        task_count = 0
        for video, subtitles in scan_result:
            languages = set([s.language for s in subtitles if s.language])
            wanted_languages = set(self._languages)
            if not wanted_languages:
                wanted_languages = list_languages(1)
            if not self.force and self.multi:
                wanted_languages = set(wanted_languages) - languages
                if not wanted_languages:
                    logger.debug(u'No need to list multi subtitles %r for %r because %r subtitles detected' % (self._languages, video.path, languages))
                    continue
            if not self.force and not self.multi and None in [s.language for s in subtitles]:
                logger.debug(u'No need to list single subtitles %r for %r because one detected' % (self._languages, video.path))
                continue
            logger.debug(u'Listing subtitles %r for %r with %r' % (wanted_languages, video.path, self._plugins))
            for plugin_name in self._plugins:
                plugin = getattr(plugins, plugin_name)
                to_list_languages = wanted_languages & plugin.availableLanguages()
                if not to_list_languages:
                    logger.debug(u'Skipping %r: none of wanted languages %r available in %r for plugin %s' % (video.path, wanted_languages, plugin.availableLanguages(), plugin_name))
                    continue
                if not plugin.isValidVideo(video):
                    logger.debug(u'Skipping %r: video %r is not part of supported videos %r for plugin %s' % (video.path, video, plugin.videos, plugin_name))
                    continue
                self.taskQueue.put((5, ListTask(video, to_list_languages, plugin_name, config)))
                task_count += 1
        subtitles = []
        for _ in range(task_count):
            subtitles.extend(self.listResultQueue.get())
        if auto:
            self.stopWorkers()
        return subtitles
 def scan(self):
     """Scan and return associated Subtitles"""
     if not self.exists:
         return []
     basepath = os.path.splitext(self.path)[0]
     results = []
     video_infos = None
     try:
         video_infos = enzyme.parse(self.path)
     except enzyme.ParseError:
         pass
     if isinstance(video_infos, enzyme.core.AVContainer):
         results.extend([subtitles.EmbeddedSubtitle.fromEnzyme(self.path, s) for s in video_infos.subtitles])
     for l in list_languages(1):
         for e in subtitles.EXTENSIONS:
             single_path = basepath + "%s" % e
             if os.path.exists(single_path):
                 results.append(subtitles.ExternalSubtitle(single_path, None))
             multi_path = basepath + ".%s%s" % (l, e)
             if os.path.exists(multi_path):
                 results.append(subtitles.ExternalSubtitle(multi_path, l))
     return results
 def single(self):
     extension = os.path.splitext(self.path)[0]
     language = os.path.splitext(self.path[:len(self.path) - len(extension)])[1][1:]
     if not language in list_languages(1):
         return True
     return False
Beispiel #6
0
                        type=str,
                        help="File name to read",
                        required=True)
    parser.add_argument("-l", "--language", type=str, help="Language")
    parser.add_argument("-v", "--voice", type=str, help="Voice")
    parser.add_argument("-d",
                        "--directory",
                        type=str,
                        help="Directory to store the files")

    args = parser.parse_args()

    fname = args.filename
    lang = args.language
    if not lang:
        languages.list_languages()
        print()
        lang = input("Enter language: ")
    voice = args.voice
    if not voice:
        languages.list_voices(lang)
        print()
        voice = input("Enter voice: ")
    directory = args.directory
    if not directory:
        directory = lang

    try:
        os.makedirs(directory)
    except Exception as e:
        pass