• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python subliminal.download_best_subtitles函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中subliminal.download_best_subtitles函数的典型用法代码示例。如果您正苦于以下问题:Python download_best_subtitles函数的具体用法?Python download_best_subtitles怎么用?Python download_best_subtitles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了download_best_subtitles函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: com_meta_fetch_subtitle_batch

def com_meta_fetch_subtitle_batch(dir_name, sub_lang='eng'):
    """
    # batch fetch subtitles
    """
    # configure the cache
    subliminal.cache_region.configure('dogpile.cache.dbm', arguments={'filename':
                                                                          '/mediakraken/cache/cachefile.dbm'})
    # scan for videos in the folder and their subtitles
    videos = subliminal.scan_videos(dir_name, subtitles=True, embedded_subtitles=True)
    # download
    subliminal.download_best_subtitles(videos, Language(sub_lang))
开发者ID:MediaKraken,项目名称:MediaKraken_Deployment,代码行数:11,代码来源:common_metadata_subtitle.py


示例2: on_task_output

 def on_task_output(self, task, config):
     """
     Configuration::
         subliminal:
             languages: List of languages (3-letter ISO-639-3 code) in order of preference. At least one is required.
             alternatives: List of second-choice languages; subs will be downloaded but entries rejected.
             exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.
     """
     if not task.accepted:
         log.debug('nothing accepted, aborting')
         return
     from babelfish import Language
     from dogpile.cache.exception import RegionAlreadyConfigured
     import subliminal
     try:
         subliminal.cache_region.configure('dogpile.cache.dbm', 
             arguments={'filename': os.path.join(tempfile.gettempdir(), 'cachefile.dbm'), 
                        'lock_factory': subliminal.MutexLock})
     except RegionAlreadyConfigured:
         pass
     logging.getLogger("subliminal").setLevel(logging.CRITICAL)
     logging.getLogger("enzyme").setLevel(logging.WARNING)
     langs = set([Language(s) for s in config['languages']])
     alts = set([Language(s) for s in config.get('alternatives', [])])
     for entry in task.accepted:
         if not 'location' in entry:
             log.warning('Cannot act on entries that do not represent a local file.')
         elif not os.path.exists(entry['location']):
             entry.fail('file not found: %s' % entry['location'])
         elif not '$RECYCLE.BIN' in entry['location']:  # ignore deleted files in Windows shares
             try:
                 video = subliminal.scan_video(entry['location'])
                 msc = video.scores['hash'] if config['exact_match'] else 0
                 if langs & video.subtitle_languages:
                     continue  # subs for preferred lang(s) already exists
                 elif subliminal.download_best_subtitles([video], langs, min_score=msc):
                     log.info('Subtitles found for %s' % entry['location'])
                 elif alts and (alts - video.subtitle_languages) and \
                     subliminal.download_best_subtitles([video], alts, min_score=msc):
                     entry.fail('subtitles found for a second-choice language.')
                 else:
                     entry.fail('cannot find any subtitles for now.')
             except Exception as err:
                 # don't want to abort the entire task for errors in a  
                 # single video file or for occasional network timeouts
                 if err.args:
                     msg = err.args[0]
                 else:
                     # Subliminal errors don't always have a message, just use the name
                     msg = 'subliminal error: %s' % err.__class__.__name__
                 log.debug(msg)
                 entry.fail(msg)
开发者ID:ARLahan,项目名称:Flexget,代码行数:52,代码来源:subtitles_subliminal.py


示例3: download_subs

def download_subs(videos, languages):
    """
    Will scan for videos newer than one week and try to download
    subtitles in English and Spanish for them.

    Parameters
    ----------
    videos: list of

    languages: list of babelfish.language

    """
    nu_vids = []
    for vid in videos:
        if len(vid.subtitle_languages) == 0:
            nu_vids.append(vid)

    # download
    try:
        subs = subliminal.download_best_subtitles(nu_vids, languages)
    except:
        raise

    log.info('Subs found:')
    log.info(subs)

    # save
    log.debug('Saving subtitle files.')
    subliminal.save_subtitles(subs, single=False)
开发者ID:alexsavio,项目名称:dotfiles,代码行数:29,代码来源:download-subs.py


示例4: get_subtitle

def get_subtitle(magnet, lang):
    print("Obtaining subtitle (experimental, might take a while)")
    lt_session = session()
    params = {"save_path": "/tmp"}
    handle = add_magnet_uri(lt_session, magnet, params)
    while (not handle.has_metadata()):
        sleep(.1)
    info = handle.get_torrent_info()
    files = info.files()

    biggest_file = ("", 0)

    for file_ in files:
        if file_.size > biggest_file[1]:
            biggest_file = [file_.path, file_.size]

    print("Guessing data")
    filepath = biggest_file[0]
    guess = guess_video_info(filepath, info = ['filename'])
    video = Video.fromguess(filepath, guess)
    video.size = biggest_file[1]
    print("Donwloading Subtitle")
    subtitle = download_best_subtitles([video], {Language(lang)}, single=True)
    if not len(subtitle):
        subtitle = None
    else:
        subtitle = get_subtitle_path(video.name)
    lt_session.remove_torrent(handle)
    return subtitle
开发者ID:DoctorMalboro,项目名称:touchandgo,代码行数:29,代码来源:subtitles.py


示例5: subtitle

    def subtitle(self, episodes):

        # Parse babelfish languages
        bb_lang = {Language.fromietf(l) for l in self.languages}

        # Create subliminal episode set
        sub_episodes = set()
        for episode in episodes:

            ep_path = os.path.join(episode['dir'], episode['filename'])
            sub_episode = Episode.fromguess(ep_path, episode)

            # Look for external subtitles (not done automatically, apparently)
            sub_episode.subtitle_languages |= set(search_external_subtitles(sub_episode.name).values())

            sub_episodes.add(sub_episode)

        # download subtitles in the specified language
        subl_subtitles = download_best_subtitles(sub_episodes, bb_lang, providers=self.providers)

        for video, subtitles in subl_subtitles.items():

            save_subtitles(video, subtitles)

            # save subtitle languages in episode dict
开发者ID:rkohser,项目名称:gustaf2,代码行数:25,代码来源:subtitler.py


示例6: get_best_subtitle

	def get_best_subtitle(self):
		# Get a subtitle for a given video file
		self.status_bar.pop(self.context_id)
		self.status_bar.push(self.context_id, "Downloading Subtitle")
		self.timeout = GObject.timeout_add( 100, self.progress_pulse )
		self.subtitle = download_best_subtitles(
		[self.video],
		{ Language( self.language_combo.get_active_text() ) },
		providers=[self.provider_combo.get_active_text()] )
		
		try:
			self.subtitle = self.subtitle[self.video][0]
			self.status_bar.pop(self.context_id)
			self.status_bar.push(self.context_id, "Subtitle Downloaded Successfully")
		
		except IndexError:
			self.status_bar.pop(self.context_id)
			self.status_bar.push(self.context_id, "No Subtitle Found")
			GObject.source_remove(self.timeout)
			self.progress_bar.set_fraction(0)
			return False
		
			
		save_subtitles(self.video, [self.subtitle])
		GObject.source_remove(self.timeout)
		self.progress_bar.set_fraction(1)
开发者ID:DarkNand,项目名称:subliminal-minimal-gui,代码行数:26,代码来源:subliminal-minimal-gui.py


示例7: getSubtitle

 def getSubtitle(self):
     if not "sub" in self.config or not os.path.isfile(self.config['sub']):
         self.config['sub'] = {}
         name = os.path.splitext(self.config['file']['name'])[0]
         file = os.path.join(self.config['file']['path'], name + ".srt")
         if os.path.isfile(file):
             print "found file. copying to temp"
             shutil.copy(file, self.config['temp']['path'])
             self.config['sub']['file'] = os.path.join(self.config['temp']['path'], name + ".srt")
             self.config['sub']['lang'] = self.config['language']['subtitle'][0]
         else:
             print "trying to download subtitle"
             file = self.config['file']['name']
             lang = self.config['language']['subtitle']
             languages = set();
             for l in lang:
                 languages.add(Language(l))
             print languages
             videoPath = os.path.join(self.config['temp']['path'], file)
             video = set([subliminal.scan_video(videoPath)])
             print video
             cache = self.config['temp']['path'] if "temp" in self.config else self.config['file']['path']
             sub = subliminal.download_best_subtitles(video, languages)
             print sub.items()
             if not sub.items():
                 self.config['sub'] = False
             for item in sub.items():
                 subLang = item[1][0].language.alpha3
                 self.config['sub'][subLang] = {}
                 self.config['sub'][subLang]['lang'] = subLang
                 self.config['sub'][subLang]['file'] = subliminal.subtitle.get_subtitle_path(videoPath, Language(subLang))
             
             print self.config['sub']
     return self.config['sub']
开发者ID:olyckne,项目名称:tvshow_parser,代码行数:34,代码来源:subtitle.py


示例8: download

 def download(self, model):
     """Download subtitles using subliminal"""
     video = subliminal.scan_video(model.series_path)
     subtitles = subliminal.download_best_subtitles(
         {video}, {Language('eng')},
     )
     save_subtitles(subtitles, True, config.download_path)
开发者ID:diannt,项目名称:series_list,代码行数:7,代码来源:subliminal_loader.py


示例9: test_download_best_subtitles_min_score

 def test_download_best_subtitles_min_score(self):
     videos = [MOVIES[0]]
     for video in videos:
         video.name = os.path.join(TEST_DIR, os.path.split(video.name)[1])
     languages = {Language('eng'), Language('fra')}
     subtitles = download_best_subtitles(videos, languages, min_score=1000)
     self.assertEqual(len(subtitles), 0)
开发者ID:Amelandbor,项目名称:nzbToMedia,代码行数:7,代码来源:test_subliminal.py


示例10: get_subtitle

def get_subtitle(magnet, lang):
    print("Explorando torrent")
    lt_session = session()
    lt_session.listen_on(6881, 6891)
    params = {"save_path": "/tmp"}
    handle = add_magnet_uri(lt_session, magnet, params)
    lt_session.start_dht()
    print "esperando"
    while (not handle.has_metadata()):
        sleep(.1)
    print "esperando"
    info = handle.get_torrent_info()
    print "esperando", info
    files = info.files()

    biggest_file = ("", 0)

    for file_ in files:
        if file_.size > biggest_file[1]:
            biggest_file = [file_.path, file_.size]

    print("Adivinando data")
    filepath = biggest_file[0]
    guess = guess_video_info(filepath, info = ['filename'])
    video = Video.fromguess(filepath, guess)
    video.size = biggest_file[1]
    print("Bajando el subtitulo para lang = " + lang)
    subtitle = download_best_subtitles([video], {Language(lang)}, single=True)
    if not len(subtitle):
        subtitle = None
    else:
        subtitle = get_subtitle_path(video.name)
    lt_session.remove_torrent(handle)
    return subtitle
开发者ID:damdev,项目名称:touchandgo,代码行数:34,代码来源:subtitles.py


示例11: import_subs

def import_subs(filename):
    if not core.GETSUBS:
        return
    try:
        subliminal.cache_region.configure('dogpile.cache.memory')
    except:
        pass   

    languages = set()
    for item in core.SLANGUAGES:
        try:
            languages.add(Language(item))
        except:
            pass
    if not languages:
        return

    logger.debug("Attempting to download subtitles for %s" %(filename), 'SUBTITLES')
    try:
        # subliminal.logger = subliminal.logging.getLogger('subliminal')
        # subliminal.logger.setLevel(subliminal.logging.DEBUG)
        # ch = subliminal.logging.StreamHandler()
        # ch.setLevel(subliminal.logging.DEBUG)
        # formatter = subliminal.logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        # ch.setFormatter(formatter)
        # subliminal.logger.addHandler(ch)

        video = subliminal.scan_video(filename, subtitles=True, embedded_subtitles=True)
        subtitles = subliminal.download_best_subtitles([video], languages, hearing_impaired=False)
        saved_subtitles = subliminal.save_subtitles(video, subtitles[video])
        logger.debug("Saved subtitles:%s" %(saved_subtitles), 'SUBTITLES')
    except Exception as e:
        logger.error("Failed to download subtitles for %s due to: %s" %(filename, e), 'SUBTITLES') 
开发者ID:diglam,项目名称:nzbToMedia,代码行数:33,代码来源:nzbToMediaUtil.py


示例12: test_download_best_subtitles_hearing_impaired

 def test_download_best_subtitles_hearing_impaired(self):
     videos = [MOVIES[0]]
     for video in videos:
         video.name = os.path.join(TEST_DIR, video.name.split(os.sep)[-1])
     languages = {Language("eng")}
     subtitles = download_best_subtitles(videos, languages, hearing_impaired=True)
     self.assertTrue(subtitles[videos[0]][0].hearing_impaired == True)
开发者ID:notorius28,项目名称:subliminal,代码行数:7,代码来源:test_subliminal.py


示例13: test_download_best_subtitles_min_score

 def test_download_best_subtitles_min_score(self):
     videos = [MOVIES[0]]
     for video in videos:
         video.name = os.path.join(TEST_DIR, video.name.split(os.sep)[-1])
     languages = {Language("eng"), Language("fra")}
     subtitles = download_best_subtitles(videos, languages, min_score=1000)
     self.assertTrue(len(subtitles) == 0)
开发者ID:notorius28,项目名称:subliminal,代码行数:7,代码来源:test_subliminal.py


示例14: test_download_best_subtitles_single

 def test_download_best_subtitles_single(self):
     videos = [EPISODES[0], EPISODES[1]]
     for video in videos:
         video.name = os.path.join(TEST_DIR, video.name.split(os.sep)[-1])
     languages = {Language("eng"), Language("fra")}
     subtitles = download_best_subtitles(videos, languages, single=True)
     for video in videos:
         self.assertTrue(video in subtitles and len(subtitles[video]) == 1)
         self.assertTrue(os.path.exists(os.path.splitext(video.name)[0] + ".srt"))
开发者ID:notorius28,项目名称:subliminal,代码行数:9,代码来源:test_subliminal.py


示例15: downloadSubtitles

def downloadSubtitles(subtitles_info):
    existing_subtitles = subtitles_info['subtitles']
    # First of all, check if we need subtitles
    languages = getNeededLanguages(existing_subtitles)
    if not languages:
        logger.log(u'%s: No missing subtitles for S%02dE%02d' % (subtitles_info['show.indexerid'], subtitles_info['season'], subtitles_info['episode']), logger.DEBUG)
        return (existing_subtitles, None)

    subtitles_path = getSubtitlesPath(subtitles_info['location']).encode(sickbeard.SYS_ENCODING)
    video_path = subtitles_info['location'].encode(sickbeard.SYS_ENCODING)
    providers = getEnabledServiceList()

    try:
        video = subliminal.scan_video(video_path, subtitles=False, embedded_subtitles=False)
    except Exception:
        logger.log(u'%s: Exception caught in subliminal.scan_video for S%02dE%02d' %
        (subtitles_info['show.indexerid'], subtitles_info['season'], subtitles_info['episode']), logger.DEBUG)
        return (existing_subtitles, None)

    try:
        # TODO: Add gui option for hearing_impaired parameter ?
        found_subtitles = subliminal.download_best_subtitles([video], languages=languages, hearing_impaired=False, only_one=not sickbeard.SUBTITLES_MULTI, providers=providers)
        if not found_subtitles:
            logger.log(u'%s: No subtitles found for S%02dE%02d on any provider' % (subtitles_info['show.indexerid'], subtitles_info['season'], subtitles_info['episode']), logger.DEBUG)
            return (existing_subtitles, None)

        for index, subtitle in enumerate(found_subtitles[video]):
            encoding = subliminal.subtitle.Subtitle.guess_encoding(subtitle)
            found_subtitles[video][index].encoding = encoding

        subliminal.save_subtitles(video, found_subtitles[video], directory=subtitles_path, single=not sickbeard.SUBTITLES_MULTI)

        for video, subtitles in found_subtitles.iteritems():
            for subtitle in subtitles:
                new_video_path = subtitles_path + "/" + video.name.rsplit("/", 1)[-1]
                new_subtitles_path = subliminal.subtitle.get_subtitle_path(new_video_path, subtitle.language if sickbeard.SUBTITLES_MULTI else None)
                sickbeard.helpers.chmodAsParent(new_subtitles_path)
                sickbeard.helpers.fixSetGroupID(new_subtitles_path)

        if not sickbeard.EMBEDDED_SUBTITLES_ALL and sickbeard.SUBTITLES_EXTRA_SCRIPTS and video_path.endswith(('.mkv','.mp4')):
            run_subs_extra_scripts(subtitles_info, found_subtitles)

        current_subtitles = subtitlesLanguages(video_path)[0]
        new_subtitles = frozenset(current_subtitles).difference(existing_subtitles)

    except Exception as e:
                logger.log("Error occurred when downloading subtitles for: %s" % video_path)
                logger.log(traceback.format_exc(), logger.ERROR)
                return (existing_subtitles, None)

    if sickbeard.SUBTITLES_HISTORY:
        for video, subtitles in found_subtitles.iteritems():
            for subtitle in subtitles:
                logger.log(u'history.logSubtitle %s, %s' % (subtitle.provider_name, subtitle.language.opensubtitles), logger.DEBUG)
                history.logSubtitle(subtitles_info['show.indexerid'], subtitles_info['season'], subtitles_info['episode'], subtitles_info['status'], subtitle)

    return (current_subtitles, new_subtitles)
开发者ID:mexicanamerican,项目名称:SickRage,代码行数:57,代码来源:subtitles.py


示例16: test_download_best_subtitles

 def test_download_best_subtitles(self):
     videos = [EPISODES[0], EPISODES[1]]
     for video in videos:
         video.name = os.path.join(TEST_DIR, os.path.split(video.name)[1])
     languages = {Language('eng'), Language('fra')}
     subtitles = download_best_subtitles(videos, languages)
     for video in videos:
         self.assertIn(video, subtitles)
         self.assertEqual(len(subtitles[video]), 2)
开发者ID:Amelandbor,项目名称:nzbToMedia,代码行数:9,代码来源:test_subliminal.py


示例17: download_sub

 def download_sub(self, language):
     l = Language(language)
     v = scan_video(self.path)
     sub_path = get_subtitle_path(v.name, l)
     if not os.path.isfile(sub_path):
         sub = download_best_subtitles((v,), {l})
         # TODO Save in tmp folder if regular is not available
         save_subtitles(sub)
     return sub_path
开发者ID:gileri,项目名称:cli_theatre,代码行数:9,代码来源:library.py


示例18: find_subtitles

def find_subtitles(video, language):
    """ Input: object video
        Output: returns the best subtitle found
        Throws: ValueError
    """

    subtitles = download_best_subtitles([video], {Language(language)})
    best_subtitle = subtitles[video][0]
    return best_subtitle
开发者ID:NicolasVerbeek,项目名称:WebSubtitles,代码行数:9,代码来源:app.py


示例19: test_download_best_subtitles_no_language

def test_download_best_subtitles_no_language(episodes):
    video = episodes['bbt_s07e05']
    languages = {Language('fra')}
    video.subtitle_languages = languages
    providers = ['addic7ed']

    subtitles = download_best_subtitles({video}, languages, min_score=video.scores['hash'], providers=providers)

    assert len(subtitles) == 0
开发者ID:Esiravegna,项目名称:subliminal,代码行数:9,代码来源:test_api.py


示例20: test_download_best_subtitles_undefined

def test_download_best_subtitles_undefined(episodes):
    video = episodes['bbt_s07e05']
    languages = {Language('und')}
    video.subtitle_languages = languages
    providers = ['addic7ed']

    subtitles = download_best_subtitles({video}, languages, min_score=video.scores['hash'], only_one=True,
                                        providers=providers)

    assert len(subtitles) == 0
开发者ID:Esiravegna,项目名称:subliminal,代码行数:10,代码来源:test_api.py



注:本文中的subliminal.download_best_subtitles函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python subliminal.save_subtitles函数代码示例发布时间:2022-05-27
下一篇:
Python sublimezen.expand_abbr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap