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

Python helpers.isMediaFile函数代码示例

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

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



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

示例1: _torrent_has_any_media_files

def _torrent_has_any_media_files(torrent_info):
    """
    Internal function to check if a torrent has any useful media files.
    @param torrent_info: (a libtorrent torrent_info object)
    @return: (bool) True if any useful media is found, false otherwise.
    """
    for f in torrent_info.files():
        if isMediaFile(f.path):
            return True
    return False
开发者ID:eagleamon,项目名称:Sick-Beard,代码行数:10,代码来源:downloader.py


示例2: test_is_media_file

    def test_is_media_file(self):
        """
        Test isMediaFile
        """
        # TODO: Add unicode tests
        # TODO: Add MAC OS resource fork tests
        # TODO: Add RARBG release tests
        # RARBG release intros should be ignored
        # MAC OS's "resource fork" files should be ignored
        # Extras should be ignored
        # and the file extension should be in the list of media extensions

        # Test all valid media extensions
        temp_name = 'Show.Name.S01E01.HDTV.x264-RLSGROUP'
        extension_tests = {'.'.join((temp_name, ext)): True for ext in MEDIA_EXTENSIONS}
        # ...and some invalid ones
        other_extensions = ['txt', 'sfv', 'srr', 'rar', 'nfo', 'zip']
        extension_tests.update({'.'.join((temp_name, ext)): False for ext in other_extensions + SUBTITLE_EXTENSIONS})

        # Samples should be ignored
        sample_tests = {  # Samples should be ignored, valid samples will return False
            'Show.Name.S01E01.HDTV.sample.mkv': False,  # default case
            'Show.Name.S01E01.HDTV.sAmPle.mkv': False,  # Ignore case
            'Show.Name.S01E01.HDTV.samples.mkv': True,  # sample should not be plural
            'Show.Name.S01E01.HDTVsample.mkv': True,  # no separation, can't identify as sample
            'Sample.Show.Name.S01E01.HDTV.mkv': False,  # location doesn't matter
            'Show.Name.Sample.S01E01.HDTV.sample.mkv': False,  # location doesn't matter
            'Show.Name.S01E01.HDTV.sample1.mkv': False,  # numbered samples are ok
            'Show.Name.S01E01.HDTV.sample12.mkv': False,  # numbered samples are ok
            'Show.Name.S01E01.HDTV.sampleA.mkv': True,  # samples should not be indexed alphabetically
            'RARBG.mp4': False,
            'rarbg.MP4': False
        }

        edge_cases = {
            None: False,
            '': False,
            0: False,
            1: False,
            42: False,
            123189274981274: False,
            12.23: False,
            ('this', 'is', 'a tuple'): False,
        }

        for cur_test in extension_tests, sample_tests, edge_cases:
            for cur_name, expected_result in cur_test.items():
                self.assertEqual(helpers.isMediaFile(cur_name), expected_result, cur_name)
开发者ID:SickRage,项目名称:SickRage,代码行数:48,代码来源:helpers_tests.py


示例3: validateDir

def validateDir(
    path, dirName, nzbNameOriginal, failed, result
):  # pylint: disable=too-many-locals,too-many-branches,too-many-return-statements
    """
    Check if directory is valid for processing

    :param path: Path to use
    :param dirName: Directory to check
    :param nzbNameOriginal: Original NZB name
    :param failed: Previously failed objects
    :param result: Previous results
    :return: True if dir is valid for processing, False if not
    """

    dirName = ss(dirName)

    IGNORED_FOLDERS = [u".AppleDouble", u"[email protected]__thumb", u"@eaDir"]
    folder_name = ek(os.path.basename, dirName)
    if folder_name in IGNORED_FOLDERS:
        return False

    result.output += logHelper(u"Processing folder " + dirName, logger.DEBUG)

    if folder_name.startswith(u"_FAILED_"):
        result.output += logHelper(u"The directory name indicates it failed to extract.", logger.DEBUG)
        failed = True
    elif folder_name.startswith(u"_UNDERSIZED_"):
        result.output += logHelper(
            u"The directory name indicates that it was previously rejected for being undersized.", logger.DEBUG
        )
        failed = True
    elif folder_name.upper().startswith(u"_UNPACK"):
        result.output += logHelper(
            u"The directory name indicates that this release is in the process of being unpacked.", logger.DEBUG
        )
        result.missedfiles.append(u"%s : Being unpacked" % dirName)
        return False

    if failed:
        process_failed(ek(os.path.join, path, dirName), nzbNameOriginal, result)
        result.missedfiles.append(u"%s : Failed download" % dirName)
        return False

    if helpers.is_hidden_folder(ek(os.path.join, path, dirName)):
        result.output += logHelper(u"Ignoring hidden folder: %s" % dirName, logger.DEBUG)
        result.missedfiles.append(u"%s : Hidden folder" % dirName)
        return False

    # make sure the dir isn't inside a show dir
    main_db_con = db.DBConnection()
    sql_results = main_db_con.select("SELECT location FROM tv_shows")

    for sqlShow in sql_results:
        if (
            dirName.lower().startswith(ek(os.path.realpath, sqlShow["location"]).lower() + os.sep)
            or dirName.lower() == ek(os.path.realpath, sqlShow["location"]).lower()
        ):

            result.output += logHelper(
                u"Cannot process an episode that's already been moved to its show dir, skipping " + dirName,
                logger.WARNING,
            )
            return False

    # Get the videofile list for the next checks
    allFiles = []
    allDirs = []
    for _, processdir, fileList in ek(os.walk, ek(os.path.join, path, dirName), topdown=False):
        allDirs += processdir
        allFiles += fileList

    videoFiles = [x for x in allFiles if helpers.isMediaFile(x)]
    allDirs.append(dirName)

    # check if the dir have at least one tv video file
    for video in videoFiles:
        try:
            NameParser().parse(video, cache_result=False)
            return True
        except (InvalidNameException, InvalidShowException):
            pass

    for proc_dir in allDirs:
        try:
            NameParser().parse(proc_dir, cache_result=False)
            return True
        except (InvalidNameException, InvalidShowException):
            pass

    if sickbeard.UNPACK:
        # Search for packed release
        packedFiles = [x for x in allFiles if helpers.isRarFile(x)]

        for packed in packedFiles:
            try:
                NameParser().parse(packed, cache_result=False)
                return True
            except (InvalidNameException, InvalidShowException):
                pass

#.........这里部分代码省略.........
开发者ID:lastdevonearth,项目名称:SickRage,代码行数:101,代码来源:processTV.py


示例4: processDir

def processDir(
    dirName,
    nzbName=None,
    process_method=None,
    force=False,
    is_priority=None,
    delete_on=False,
    failed=False,
    proc_type="auto",
):
    """
    Scans through the files in dirName and processes whatever media files it finds

    :param dirName: The folder name to look in
    :param nzbName: The NZB name which resulted in this folder being downloaded
    :param force: True to postprocess already postprocessed files
    :param failed: Boolean for whether or not the download failed
    :param proc_type: Type of postprocessing auto or manual
    """

    result = ProcessResult()

    # if they passed us a real dir then assume it's the one we want
    if ek(os.path.isdir, dirName):
        dirName = ek(os.path.realpath, dirName)
        result.output += logHelper(u"Processing folder %s" % dirName, logger.DEBUG)

    # if the client and SickRage are not on the same machine translate the directory into a network directory
    elif all(
        [
            sickbeard.TV_DOWNLOAD_DIR,
            ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR),
            ek(os.path.normpath, dirName) == ek(os.path.normpath, sickbeard.TV_DOWNLOAD_DIR),
        ]
    ):
        dirName = ek(os.path.join, sickbeard.TV_DOWNLOAD_DIR, ek(os.path.abspath, dirName).split(os.path.sep)[-1])
        result.output += logHelper(u"Trying to use folder: %s " % dirName, logger.DEBUG)

    # if we didn't find a real dir then quit
    if not ek(os.path.isdir, dirName):
        result.output += logHelper(
            u"Unable to figure out what folder to process. "
            u"If your downloader and SickRage aren't on the same PC "
            u"make sure you fill out your TV download dir in the config.",
            logger.DEBUG,
        )
        return result.output

    path, dirs, files = get_path_dir_files(dirName, nzbName, proc_type)

    files = [x for x in files if not is_torrent_or_nzb_file(x)]
    SyncFiles = [x for x in files if is_sync_file(x)]
    nzbNameOriginal = nzbName

    # Don't post process if files are still being synced and option is activated
    postpone = SyncFiles and sickbeard.POSTPONE_IF_SYNC_FILES

    if not postpone:
        result.output += logHelper(u"PostProcessing Path: %s" % path, logger.INFO)
        result.output += logHelper(u"PostProcessing Dirs: %s" % str(dirs), logger.DEBUG)

        rarFiles = [x for x in files if helpers.isRarFile(x)]
        rarContent = unRAR(path, rarFiles, force, result)
        files += rarContent
        videoFiles = [x for x in files if helpers.isMediaFile(x)]
        videoInRar = [x for x in rarContent if helpers.isMediaFile(x)]

        result.output += logHelper(u"PostProcessing Files: %s" % files, logger.DEBUG)
        result.output += logHelper(u"PostProcessing VideoFiles: %s" % videoFiles, logger.DEBUG)
        result.output += logHelper(u"PostProcessing RarContent: %s" % rarContent, logger.DEBUG)
        result.output += logHelper(u"PostProcessing VideoInRar: %s" % videoInRar, logger.DEBUG)

        # If nzbName is set and there's more than one videofile in the folder, files will be lost (overwritten).
        nzbName = None if len(videoFiles) >= 2 else nzbName

        process_method = process_method if process_method else sickbeard.PROCESS_METHOD
        result.result = True

        # Don't Link media when the media is extracted from a rar in the same path
        if process_method in (u"hardlink", u"symlink") and videoInRar:
            process_media(path, videoInRar, nzbName, u"move", force, is_priority, result)
            delete_files(path, rarContent, result)
            for video in set(videoFiles) - set(videoInRar):
                process_media(path, [video], nzbName, process_method, force, is_priority, result)
        elif sickbeard.DELRARCONTENTS and videoInRar:
            process_media(path, videoInRar, nzbName, process_method, force, is_priority, result)
            delete_files(path, rarContent, result, True)
            for video in set(videoFiles) - set(videoInRar):
                process_media(path, [video], nzbName, process_method, force, is_priority, result)
        else:
            for video in videoFiles:
                process_media(path, [video], nzbName, process_method, force, is_priority, result)

    else:
        result.output += logHelper(u"Found temporary sync files: %s in path: %s" % (SyncFiles, path))
        result.output += logHelper(u"Skipping post processing for folder: %s" % path)
        result.missedfiles.append(u"%s : Syncfiles found" % path)

    # Process Video File in all TV Subdir
    for curDir in [x for x in dirs if validateDir(path, x, nzbNameOriginal, failed, result)]:
#.........这里部分代码省略.........
开发者ID:lastdevonearth,项目名称:SickRage,代码行数:101,代码来源:processTV.py


示例5: subtitles_download_in_pp

    def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = enabled_service_list()
        provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                         'password': sickbeard.ADDIC7ED_PASS},
                            'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                           'password': sickbeard.LEGENDASTV_PASS},
                            'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                              'password': sickbeard.OPENSUBTITLES_PASS}}

        pool = subliminal.api.ProviderPool(providers=providers, provider_configs=provider_configs)

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            for root, _, files in ek(os.walk, sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for video_filename in sorted(files):
                    try:
                        # Remove non release groups from video file. Needed to match subtitles
                        new_video_filename = remove_non_release_groups(video_filename)
                        if new_video_filename != video_filename:
                            os.rename(video_filename, new_video_filename)
                            video_filename = new_video_filename
                    except Exception as error:
                        logger.log(u'Could not remove non release groups from video file. Error: %r'
                                   % ex(error), logger.DEBUG)
                    if isMediaFile(video_filename):
                        try:
                            video = subliminal.scan_video(os.path.join(root, video_filename),
                                                          subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)

                            if not subtitles_list:
                                logger.log(u'No subtitles found for %s'
                                           % ek(os.path.join, root, video_filename), logger.DEBUG)
                                continue

                            logger.log(u'Found subtitle(s) canditate(s) for %s' % video_filename, logger.INFO)
                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            user_score = 132 if sickbeard.SUBTITLES_PERFECT_MATCH else 111
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                                           hearing_impaired=hearing_impaired,
                                                                           min_score=user_score,
                                                                           only_one=not sickbeard.SUBTITLES_MULTI)

                            for subtitle in subtitles_list:
                                matches = subtitle.get_matches(video, hearing_impaired=False)
                                score = subliminal.subtitle.compute_score(matches, video)
                                logger.log(u"[%s] Subtitle score for %s is: %s (min=%s)"
                                           % (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(u"Found subtitle for %s in %s provider with language %s"
                                           % (os.path.join(root, video_filename), subtitle.provider_name,
                                              subtitle.language.opensubtitles), logger.DEBUG)
                                subliminal.save_subtitles(video, found_subtitles, directory=root,
                                                          single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                                                      None if subtitles_multi else
                                                                                      subtitle.language)
                                if root is not None:
                                    subtitle_path = ek(os.path.join, root, ek(os.path.split, subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(u"Error occurred when downloading subtitles for: %s. Error: %r"
                                       % (os.path.join(root, video_filename), ex(error)))
            if run_post_process:
                logger.log(u"Starting post-process with default settings now that we found subtitles")
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
开发者ID:madtrix74,项目名称:SickRage,代码行数:85,代码来源:subtitles.py


示例6: download_subtitles

def download_subtitles(subtitles_info):  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
    existing_subtitles = subtitles_info['subtitles']

    if not needs_subtitles(existing_subtitles):
        logger.log(u'Episode already has all needed subtitles, skipping %s S%02dE%02d'
                   % (subtitles_info['show_name'], subtitles_info['season'], subtitles_info['episode']), logger.DEBUG)
        return existing_subtitles, None

    # Check if we really need subtitles
    languages = get_needed_languages(existing_subtitles)
    if not languages:
        logger.log(u'No subtitles needed for %s S%02dE%02d'
                   % (subtitles_info['show_name'], subtitles_info['season'],
                      subtitles_info['episode']), logger.DEBUG)
        return existing_subtitles, None

    subtitles_path = get_subtitles_path(subtitles_info['location']).encode(sickbeard.SYS_ENCODING)
    video_path = subtitles_info['location'].encode(sickbeard.SYS_ENCODING)
    user_score = 132 if sickbeard.SUBTITLES_PERFECT_MATCH else 111

    video = get_video(video_path, subtitles_path=subtitles_path)
    if not video:
        logger.log(u'Exception caught in subliminal.scan_video for %s S%02dE%02d'
                   % (subtitles_info['show_name'], subtitles_info['season'],
                      subtitles_info['episode']), logger.DEBUG)
        return existing_subtitles, None

    providers = enabled_service_list()
    provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                     'password': sickbeard.ADDIC7ED_PASS},
                        'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                       'password': sickbeard.LEGENDASTV_PASS},
                        'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                          'password': sickbeard.OPENSUBTITLES_PASS}}

    pool = subliminal.api.ProviderPool(providers=providers, provider_configs=provider_configs)

    try:
        subtitles_list = pool.list_subtitles(video, languages)
        if not subtitles_list:
            logger.log(u'No subtitles found for %s S%02dE%02d on any provider'
                       % (subtitles_info['show_name'], subtitles_info['season'],
                          subtitles_info['episode']), logger.DEBUG)
            return existing_subtitles, None

        for subtitle in subtitles_list:
            matches = subtitle.get_matches(video, hearing_impaired=False)
            score = subliminal.subtitle.compute_score(matches, video)
            logger.log(u"[%s] Subtitle score for %s is: %s (min=%s)"
                       % (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

        found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                       hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED,
                                                       min_score=user_score, only_one=not sickbeard.SUBTITLES_MULTI)

        subliminal.save_subtitles(video, found_subtitles, directory=subtitles_path,
                                  single=not sickbeard.SUBTITLES_MULTI)
    except IOError as error:
        if 'No space left on device' in ex(error):
            logger.log(u'Not enough space on the drive to save subtitles', logger.WARNING)
        else:
            logger.log(traceback.format_exc(), logger.WARNING)
    except Exception:
        logger.log(u"Error occurred when downloading subtitles for: %s" % video_path)
        logger.log(traceback.format_exc(), logger.ERROR)
        return existing_subtitles, None

    for subtitle in found_subtitles:
        subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                              None if not sickbeard.SUBTITLES_MULTI else
                                                              subtitle.language)
        if subtitles_path is not None:
            subtitle_path = ek(os.path.join, subtitles_path, ek(os.path.split, subtitle_path)[1])

        sickbeard.helpers.chmodAsParent(subtitle_path)
        sickbeard.helpers.fixSetGroupID(subtitle_path)

        if sickbeard.SUBTITLES_HISTORY:
            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)

        if sickbeard.SUBTITLES_EXTRA_SCRIPTS and isMediaFile(video_path) and not sickbeard.EMBEDDED_SUBTITLES_ALL:
            run_subs_extra_scripts(subtitles_info, subtitle, video, single=not sickbeard.SUBTITLES_MULTI)

    new_subtitles = sorted({subtitle.language.opensubtitles for subtitle in found_subtitles})
    current_subtitles = sorted({subtitle for subtitle in new_subtitles + existing_subtitles}) if existing_subtitles else new_subtitles
    if not sickbeard.SUBTITLES_MULTI and len(found_subtitles) == 1:
        new_code = found_subtitles[0].language.opensubtitles
        if new_code not in existing_subtitles:
            current_subtitles.remove(new_code)
        current_subtitles.append('und')

    return current_subtitles, new_subtitles
开发者ID:madtrix74,项目名称:SickRage,代码行数:96,代码来源:subtitles.py


示例7: subtitles_download_in_pp

    def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = enabled_service_list()
        provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                         'password': sickbeard.ADDIC7ED_PASS},
                            'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                           'password': sickbeard.LEGENDASTV_PASS},
                            'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                              'password': sickbeard.OPENSUBTITLES_PASS}}

        pool = ProviderPool(providers=providers, provider_configs=provider_configs)

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):

            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                rar_files = [x for x in files if isRarFile(x)]
                if rar_files and sickbeard.UNPACK:
                    video_files = [x for x in files if isMediaFile(x)]
                    if u'_UNPACK' not in root and (not video_files or root == sickbeard.TV_DOWNLOAD_DIR):
                        logger.log(u'Found rar files in post-process folder: {}'.format(rar_files), logger.DEBUG)
                        result = processTV.ProcessResult()
                        processTV.unRAR(root, rar_files, False, result)
                elif rar_files and not sickbeard.UNPACK:
                    logger.log(u'Unpack is disabled. Skipping: {}'.format(rar_files), logger.WARNING)

            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for video_filename in sorted(files):
                    try:
                        # Remove non release groups from video file. Needed to match subtitles
                        new_video_filename = remove_non_release_groups(video_filename)
                        if new_video_filename != video_filename:
                            os.rename(video_filename, new_video_filename)
                            video_filename = new_video_filename
                    except Exception as error:
                        logger.log(u'Couldn\'t remove non release groups from video file. Error: {}'.format
                                   (ex(error)), logger.DEBUG)
                    if isMediaFile(video_filename):
                        try:
                            video = subliminal.scan_video(os.path.join(root, video_filename),
                                                          subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)

                            for provider in providers:
                                if provider in pool.discarded_providers:
                                    logger.log(u'Could not search in {} provider. Discarding for now'.format(provider), logger.DEBUG)

                            if not subtitles_list:
                                logger.log(u'No subtitles found for {}'.format
                                           (os.path.join(root, video_filename)), logger.DEBUG)
                                continue

                            logger.log(u'Found subtitle(s) canditate(s) for {}'.format(video_filename), logger.INFO)
                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            user_score = 213 if sickbeard.SUBTITLES_PERFECT_MATCH else 204
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                                           hearing_impaired=hearing_impaired,
                                                                           min_score=user_score,
                                                                           only_one=not sickbeard.SUBTITLES_MULTI)

                            for subtitle in subtitles_list:
                                score = subliminal.score.compute_score(subtitle, video, hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED)
                                logger.log(u'[{}] Subtitle score for {} is: {} (min={})'.format
                                           (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(u'Found subtitle for {} in {} provider with language {}'.format
                                           (os.path.join(root, video_filename), subtitle.provider_name,
                                            subtitle.language.opensubtitles), logger.DEBUG)
                                subliminal.save_subtitles(video, found_subtitles, directory=root,
                                                          single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                                                      None if subtitles_multi else
                                                                                      subtitle.language)
                                if root is not None:
                                    subtitle_path = os.path.join(root, os.path.split(subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(u'Error occurred when downloading subtitles for: {}. Error: {}'.format
                                       (os.path.join(root, video_filename), ex(error)))
            if run_post_process:
                logger.log(u'Starting post-process with default settings now that we found subtitles')
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
开发者ID:pedro2d10,项目名称:SickRage-FR,代码行数:100,代码来源:subtitles.py


示例8: download_subtitles

def download_subtitles(subtitles_info):  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
    existing_subtitles = subtitles_info['subtitles']

    if not needs_subtitles(existing_subtitles):
        logger.log(u'Episode already has all needed subtitles, skipping {} {}'.format
                   (subtitles_info['show_name'], episode_num(subtitles_info['season'], subtitles_info['episode']) or
                    episode_num(subtitles_info['season'], subtitles_info['episode'], numbering='absolute')), logger.DEBUG)
        return existing_subtitles, None

    # Check if we really need subtitles
    languages = get_needed_languages(existing_subtitles)
    if not languages:
        logger.log(u'No subtitles needed for {} {}'.format
                   (subtitles_info['show_name'], episode_num(subtitles_info['season'], subtitles_info['episode']) or
                    episode_num(subtitles_info['season'], subtitles_info['episode'], numbering='absolute')), logger.DEBUG)
        return existing_subtitles, None

    subtitles_path = get_subtitles_path(subtitles_info['location'])
    video_path = subtitles_info['location']
    
    # Perfect match = hash score - hearing impaired score - resolution score (subtitle for 720p its the same for 1080p)
    # Perfect match = 215 -1 -1 = 213
    # No-perfect match = hash score - hearing impaired score - resolution score - release_group score
    # No-perfect match = 215 -1 -1 -9 = 204
    # From latest subliminal code:
    # episode_scores = {'hash': 215, 'series': 108, 'year': 54, 'season': 18, 'episode': 18, 'release_group': 9,
    #                   'format': 4, 'audio_codec': 2, 'resolution': 1, 'hearing_impaired': 1, 'video_codec': 1}
    user_score = 213 if sickbeard.SUBTITLES_PERFECT_MATCH else 204

    video = get_video(video_path, subtitles_path=subtitles_path)
    if not video:
        logger.log(u'Exception caught in subliminal.scan_video for {} {}'.format
                   (subtitles_info['show_name'], episode_num(subtitles_info['season'], subtitles_info['episode']) or
                    episode_num(subtitles_info['season'], subtitles_info['episode'], numbering='absolute')), logger.DEBUG)
        return existing_subtitles, None

    providers = enabled_service_list()
    provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                     'password': sickbeard.ADDIC7ED_PASS},
                        'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                       'password': sickbeard.LEGENDASTV_PASS},
                        'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                          'password': sickbeard.OPENSUBTITLES_PASS}}

    pool = ProviderPool(providers=providers, provider_configs=provider_configs)

    try:
        subtitles_list = pool.list_subtitles(video, languages)

        for provider in providers:
            if provider in pool.discarded_providers:
                logger.log(u'Could not search in {} provider. Discarding for now'.format(provider), logger.DEBUG)

        if not subtitles_list:
            logger.log(u'No subtitles found for {} {}'.format
                       (subtitles_info['show_name'], episode_num(subtitles_info['season'], subtitles_info['episode']) or
                        episode_num(subtitles_info['season'], subtitles_info['episode'], numbering='absolute')), logger.DEBUG)
            return existing_subtitles, None

        for subtitle in subtitles_list:
            score = subliminal.score.compute_score(subtitle, video, hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED)
            logger.log(u'[{}] Subtitle score for {} is: {} (min={})'.format
                       (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

        found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                       hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED,
                                                       min_score=user_score, only_one=not sickbeard.SUBTITLES_MULTI)

        subliminal.save_subtitles(video, found_subtitles, directory=subtitles_path,
                                  single=not sickbeard.SUBTITLES_MULTI)
    except IOError as error:
        if 'No space left on device' in ex(error):
            logger.log(u'Not enough space on the drive to save subtitles', logger.WARNING)
        else:
            logger.log(traceback.format_exc(), logger.WARNING)
    except Exception:
        logger.log(u'Error occurred when downloading subtitles for: {}'.format(video_path))
        logger.log(traceback.format_exc(), logger.ERROR)
        return existing_subtitles, None

    for subtitle in found_subtitles:
        subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                              None if not sickbeard.SUBTITLES_MULTI else
                                                              subtitle.language)
        if subtitles_path is not None:
            subtitle_path = os.path.join(subtitles_path, os.path.split(subtitle_path)[1])

        sickbeard.helpers.chmodAsParent(subtitle_path)
        sickbeard.helpers.fixSetGroupID(subtitle_path)

        if sickbeard.SUBTITLES_HISTORY:
            logger.log(u'history.logSubtitle {}, {}'.format
                       (subtitle.provider_name, subtitle.language.opensubtitles), logger.DEBUG)

            history.logSubtitle(subtitles_info['show_indexerid'], subtitles_info['season'],
                                subtitles_info['episode'], subtitles_info['status'], subtitle)

        if sickbeard.SUBTITLES_EXTRA_SCRIPTS and isMediaFile(video_path) and not sickbeard.EMBEDDED_SUBTITLES_ALL:
            run_subs_extra_scripts(subtitles_info, subtitle, video, single=not sickbeard.SUBTITLES_MULTI)

#.........这里部分代码省略.........
开发者ID:pedro2d10,项目名称:SickRage-FR,代码行数:101,代码来源:subtitles.py


示例9: _finish_download_process

 def _finish_download_process():
     """
     Finish downloading a pid
     (this is a closure, called in another thread)
     """
     
     last_reported_perc = 0.0
     
     while p.poll() is None:
         line = p.stdout.readline()
         if line:
             line = line.rstrip()
             match = re.match(IPLAYER_DL_PROGRESS_PATTERN, line, re.IGNORECASE)
             if match:
                 dlSize = match.group('size')
                 dlTime = match.group('time')
                 dlPerc = float(match.group('perc'))
                 if dlPerc - last_reported_perc >= 10.0:
                     # only report progress every 10% or so.
                     logger.log(u"RUNNING iPLAYER: "+line, logger.DEBUG)
                     last_reported_perc = dlPerc
             else:
                 # not a progress line, echo it to debug
                 logger.log(u"RUNNING iPLAYER: "+line, logger.DEBUG)
                     
                 
     
     logger.log(u"RUNNING iPLAYER: process has ended, returncode was " + 
                repr(p.returncode) , logger.DEBUG)
     
     # We will need to rename some of the files in the folder to ensure 
     # that sb is comfortable with them.
     videoFiles = listMediaFiles(tmp_dir)
     for videoFile in videoFiles:
         filePrefix, fileExt = os.path.splitext(videoFile)
         if fileExt and fileExt[0] == '.': 
             fileExt = fileExt[1:]
         
         # split again to get the quality
         filePrePrefix, fileQuality = os.path.splitext(filePrefix)   
         if fileQuality and fileQuality[0] == '.': 
             fileQuality = fileQuality[1:]   
         qual_str = cls.iplayer_quality_to_sb_quality_string(fileQuality)
         
         # reassemble the filename again, with new quality
         newFilePrefix = filePrePrefix + '.' + qual_str
         newFileName = newFilePrefix + '.' + fileExt
         
         if newFileName != videoFile:    # just in case!
             logger.log('Renaming {0} to {1}'.format(videoFile, newFileName), logger.DEBUG)
             os.rename(videoFile, newFileName)
             
             # Also need to rename any associated files (nfo and srt)
             for otherFile in glob.glob(newFilePrefix + '.*'):
                 if otherFile == newFileName:
                     continue
                 otherFilePrefix, otherFileExt = os.path.splitext(otherFile)
                 newOtherFile = newFilePrefix + otherFileExt
                 logger.log('Renaming {0} to {1}'.format(otherFile, newOtherFile), logger.DEBUG)
                 os.rename(otherFile, newOtherFile)
             
     
     # Ok, we're done with *our* post-processing, so let SB do its own.
     processResult = processDir(tmp_dir)
     #logger.log(u"processDir returned " + processResult , logger.DEBUG) - this is long, and quite useless!
     
     files_remaining = os.listdir(tmp_dir)
     can_delete = True
     for filename in files_remaining:
         fullFilePath = os.path.join(tmp_dir, filename)
         isVideo = isMediaFile(fullFilePath)
         if isVideo:
             can_delete = False # keep the folder - something prob went wrong
             logger.log('Found a media file after processing, something probably went wrong: ' + fullFilePath, logger.MESSAGE)
         else:
             logger.log('Extra file left over (will be deleted if no media found): ' + fullFilePath, logger.DEBUG)
     
     # tidy up - delete our temp dir
 
     if can_delete and os.path.isdir(tmp_dir):
         logger.log('Removing temp dir: ' + tmp_dir, logger.DEBUG)
         shutil.rmtree(tmp_dir)
开发者ID:SvenVdB,项目名称:Sick-Beard,代码行数:82,代码来源:iplayer.py


示例10: run

    def run(self):
        """
        Called every few seconds to handle any running/finished torrents
        """

        if not LIBTORRENT_AVAILABLE:
            return

        if not self.loadedRunningTorrents:
            torrent_save_file = _get_running_torrents_pickle_path(False)
            if os.path.isfile(torrent_save_file):
                logger.log(u"Saved torrents found in %s, loading" % (torrent_save_file), logger.DEBUG)
                _load_saved_torrents()

            self.loadedRunningTorrents = True

        sess = _get_session(False)
        if sess is not None:
            while 1:
                a = sess.pop_alert()
                if not a:
                    break

                if type(a) == str:
                    logger.log(a, logger.DEBUG)
                else:
                    logger.log(u"(%s): %s" % (type(a).__name__, ek.fixStupidEncodings(a.message(), True)), logger.DEBUG)

            logTorrentStatus = (time.time() - self.lastTorrentStatusLogTS) >= 600

            for torrent_data in running_torrents:
                if torrent_data["handle"].has_metadata():
                    ti = torrent_data["handle"].get_torrent_info()
                    name = ti.name()
                    torrent_data["name"] = name
                    torrent_data["total_size"] = ti.total_size()

                    if not torrent_data["have_torrentFile"]:
                        # if this was a magnet or url, and we now have downloaded the metadata
                        # for it, best to save it locally in case we need to resume
                        ti = torrent_data["handle"].get_torrent_info()
                        torrentFile = lt.create_torrent(ti)
                        torrent_data["torrent"] = lt.bencode(torrentFile.generate())
                        torrent_data["have_torrentFile"] = True
                        logger.log(
                            u"Created torrent file for %s as metadata d/l is now complete" % (name), logger.DEBUG
                        )

                else:
                    name = "-"

                s = torrent_data["handle"].status()
                torrent_data["status"] = str(s.state)
                torrent_data["progress"] = s.progress
                torrent_data["rate_down"] = s.download_rate
                torrent_data["rate_up"] = s.upload_rate
                torrent_data["paused"] = s.paused
                torrent_data["error"] = s.error

                # currentRatio = 0.0 if s.total_download == 0 else float(s.total_upload)/float(s.total_download)
                currentRatio = (
                    0.0 if s.all_time_download == 0 else float(s.all_time_upload) / float(s.all_time_download)
                )
                torrent_data["ratio"] = currentRatio

                if s.state in [lt.torrent_status.seeding, lt.torrent_status.finished]:
                    with torrent_data["lock"]:
                        # this is the post-processing & removing code, so make sure that there's
                        # only one thread doing either here, as the two could easily interfere with
                        # one another
                        if not torrent_data["post_processed"]:
                            # torrent has just completed download, so we need to do
                            # post-processing on it.
                            ti = torrent_data["handle"].get_torrent_info()
                            any_file_success = False
                            for f in ti.files():
                                fullpath = os.path.join(sickbeard.LIBTORRENT_WORKING_DIR, "data", f.path)
                                logger.log(u'Post-processing "%s"' % (fullpath), logger.DEBUG)
                                if isMediaFile(fullpath):
                                    logger.log(u"this is a media file", logger.DEBUG)
                                    try:
                                        processor = postProcessor.PostProcessor(fullpath, name)
                                        if processor.process(forceKeepOriginalFiles=True):
                                            logger.log(u'Success post-processing "%s"' % (fullpath), logger.DEBUG)
                                            any_file_success = True
                                    except exceptions.PostProcessingFailed, e:
                                        logger.log(
                                            u'Failed post-processing file "%s" with error "%s"' % (fullpath, ex(e)),
                                            logger.ERROR,
                                        )

                                ## Richard Hills [email protected] 2013-07-20 : if your file is downloaded but does not match we remove torrent and leave files for manual processing.
                                ## any file success can match a single file from a multi file torrent - we will lose some data regardless if we have 1 file in a multi file torrent which matches and the others fail
                                if not any_file_success:
                                    logger.log(
                                        u'Post processing found no useful information for file "%s" please process this manually (rename/move and manually trigger processing)'
                                        % (fullpath),
                                        logger.ERROR,
                                    )
                                    _remove_torrent_by_handle(torrent_data["handle"], False)
#.........这里部分代码省略.........
开发者ID:phlunk3,项目名称:Sick-Beard,代码行数:101,代码来源:downloader.py


示例11: run

    def run(self):
        """
        Called every few seconds to handle any running/finished torrents
        """
        
        if not LIBTORRENT_AVAILABLE:
            return
        
        if not self.loadedRunningTorrents:
            torrent_save_file = _get_running_torrents_pickle_path(False)
            if os.path.isfile(torrent_save_file):
                logger.log(u'Saved torrents found in %s, loading' % (torrent_save_file), logger.DEBUG)
                _load_saved_torrents()
            
            self.loadedRunningTorrents = True    

        sess = _get_session(False)
        if sess is not None:
            while 1:
                a = sess.pop_alert()
                if not a: break
                
                if type(a) == str:
                    logger.log(a, logger.DEBUG)
                else:
                    logger.log(u'(%s): %s' % (type(a).__name__, ek.fixStupidEncodings(a.message(), True)), logger.DEBUG)
                    
            logTorrentStatus = (time.time() - self.lastTorrentStatusLogTS) >= 600
                
            for torrent_data in running_torrents:
                if torrent_data['handle'].has_metadata():
                    ti = torrent_data['handle'].get_torrent_info()
                    name = ti.name()
                    torrent_data['name'] = name
                    torrent_data['total_size'] = ti.total_size()
                    
                    if not torrent_data['have_torrentFile']:
                        # if this was a magnet or url, and we now have downloaded the metadata
                        # for it, best to save it locally in case we need to resume
                        ti = torrent_data['handle'].get_torrent_info()
                        torrentFile = lt.create_torrent(ti)
                        torrent_data['torrent'] = lt.bencode(torrentFile.generate())
                        torrent_data['have_torrentFile'] = True
                        logger.log(u'Created torrent file for %s as metadata d/l is now complete' % (name), logger.DEBUG)

                    if not torrent_data['checkedForMedia']:
                        with torrent_data['lock']:
                            # Torrent has metadata, but hasn't been checked for valid media yet.  Do so now.
                            if not _torrent_has_any_media_files(ti):
                                logger.log(u'Torrent %s has no media files! Deleting it.' % (name), logger.ERROR)
                                _on_failed_torrent(torrent_data['key'], removeFromRunningTorrents=True,
                                               markEpisodesWanted=True)
                                break  # continue here would be nice, but safer to break b/c we have modified the list

                            torrent_data['checkedForMedia'] = True

                else:
                    name = '-'
                    
                s = torrent_data['handle'].status()
                torrent_data['status'] = str(s.state)
                torrent_data['progress'] = s.progress
                torrent_data['rate_down'] = s.download_rate
                torrent_data['rate_up'] = s.upload_rate
                torrent_data['paused'] = s.paused
                torrent_data['error'] = s.error
                
                #currentRatio = 0.0 if 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python helpers.isRarFile函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.indentXML函数代码示例发布时间: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