core.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:axel 作者: craigcabrey 项目源码 文件源码
def handle_manual(torrent):
    auto_processed = False

    def handle_media(path, move):
        nonlocal auto_processed

        guess = guessit.guessit(path)

        if guess['type'] == 'episode':
            move_episode(path, guess, move)
            auto_processed = True
        elif guess['type'] == 'movie':
            move_movie(path, guess, move)
            auto_processed = True

    part_regex = re.compile('.*part(\d+).rar', re.IGNORECASE)
    for index, file in torrent.files().items():
        file_path = os.path.join(torrent.downloadDir, file['name'])
        if check_extension(file_path) and 'sample' not in file_path.lower():
            # Log and ignore mkv files of less than ~92MiB
            try:
                if os.path.getsize(file_path) >= 96811278:
                    handle_media(file_path, False)
                else:
                    syslog.syslog(
                        syslog.LOG_ERR, 'Detected false media file, skipping'
                    )
            except FileNotFoundError:
                syslog.syslog(syslog.LOG_ERR, 'Torrent file missing, skipping')
        elif file_path.endswith('rar'):
            # Ignore parts beyond the first in a rar series
            match = part_regex.match(file_path)
            if match and int(match.group(1)) > 1:
                continue

            with tempfile.TemporaryDirectory() as temp_dir:
                paths = extract(file_path, temp_dir)

                if paths:
                    for path in paths:
                        shutil.chown(path, group=plex_group)
                        os.chmod(path, 0o664)

                        handle_media(path, True)

    if auto_processed:
        pb_notify(
            textwrap.dedent(
                '''
                    Manually added torrent {0} finished downloading
                    and was auto-processed
                '''.format(torrent.name)
            ).strip()
        )
    else:
        pb_notify(
            'Manually added torrent {0} finished downloading'.format(
                torrent.name
            )
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号