def core_main(file_path, number_th):
    conf = config.getInstance()
    # =======================================================================初始化所需变量
    multi_part = 0
    part = ''
    leak_word = ''
    c_word = ''
    cn_sub = ''
    liuchu = ''

    filepath = file_path  # 影片的路径 绝对路径
    # 下面被注释的变量不需要
    #rootpath= os.getcwd
    number = number_th
    json_data = get_data_from_json(number)  # 定义番号

    # Return if blank dict returned (data not found)
    if not json_data:
        moveFailedFolder(filepath)
        return

    if json_data["number"] != number:
        # fix issue #119
        # the root cause is we normalize the search id
        # print_files() will use the normalized id from website,
        # but paste_file_to_folder() still use the input raw search id
        # so the solution is: use the normalized search id
        number = json_data["number"]
    imagecut = json_data.get('imagecut')
    tag = json_data.get('tag')
    # =======================================================================判断-C,-CD后缀
    if '-CD' in filepath or '-cd' in filepath:
        multi_part = 1
        part = get_part(filepath)
    if '-c.' in filepath or '-C.' in filepath or '中文' in filepath or '字幕' in filepath:
        cn_sub = '1'
        c_word = '-C'  # 中文字幕影片后缀

    # 判断是否无码
    uncensored = 1 if is_uncensored(number) else 0

    if '流出' in filepath or 'uncensored' in filepath:
        liuchu = '流出'
        leak = 1
        leak_word = '-uncensored'  # 流出影片后缀
    else:
        leak = 0

    # 调试模式检测
    if conf.debug():
        debug_print(json_data)

    # 创建文件夹
    #path = create_folder(rootpath + '/' + conf.success_folder(),  json_data.get('location_rule'), json_data)

    # main_mode
    #  1: 刮削模式 / Scraping mode
    #  2: 整理模式 / Organizing mode
    #  3:不改变路径刮削
    if conf.main_mode() == 1:
        # 创建文件夹
        path = create_folder(json_data)
        if multi_part == 1:
            number += part  # 这时number会被附加上CD1后缀

        # 检查小封面, 如果image cut为3,则下载小封面
        if imagecut == 3:
            small_cover_check(path, number, json_data.get('cover_small'),
                              leak_word, c_word, filepath)

        # creatFolder会返回番号路径
        image_download(json_data.get('cover'), number, leak_word, c_word, path,
                       filepath)

        if not multi_part or part.lower() == '-cd1':
            try:
                # 下载预告片
                if conf.is_trailer() and json_data.get('trailer'):
                    trailer_download(json_data.get('trailer'), leak_word,
                                     c_word, number, path, filepath)
            except:
                pass
            try:
                # 下载剧照 data, path, filepath
                if conf.is_extrafanart() and json_data.get('extrafanart'):
                    extrafanart_download(json_data.get('extrafanart'), path,
                                         filepath)
            except:
                pass

        # 裁剪图
        cutImage(imagecut, path, number, leak_word, c_word)

        # 添加水印
        poster_path = os.path.join(path,
                                   f"{number}{leak_word}{c_word}-poster.jpg")
        thumb_path = os.path.join(path,
                                  f"{number}{leak_word}{c_word}-thumb.jpg")
        if conf.is_watermark():
            add_mark(poster_path, thumb_path, cn_sub, leak, uncensored)

        # 移动电影
        paste_file_to_folder(filepath, path, number, leak_word, c_word)

        # 最后输出.nfo元数据文件,以完成.nfo文件创建作为任务成功标志
        print_files(path, leak_word, c_word, json_data.get('naming_rule'),
                    part, cn_sub, json_data, filepath, tag,
                    json_data.get('actor_list'), liuchu, uncensored)

    elif conf.main_mode() == 2:
        # 创建文件夹
        path = create_folder(json_data)
        # 移动文件
        paste_file_to_folder_mode2(filepath, path, multi_part, number, part,
                                   leak_word, c_word)
        poster_path = os.path.join(path,
                                   f"{number}{leak_word}{c_word}-poster.jpg")
        thumb_path = os.path.join(path,
                                  f"{number}{leak_word}{c_word}-thumb.jpg")
        if conf.is_watermark():
            add_mark(poster_path, thumb_path, cn_sub, leak, uncensored)

    elif conf.main_mode() == 3:
        path = str(Path(file_path).parent)
        if multi_part == 1:
            number += part  # 这时number会被附加上CD1后缀

        # 检查小封面, 如果image cut为3,则下载小封面
        if imagecut == 3:
            small_cover_check(path, number, json_data.get('cover_small'),
                              leak_word, c_word, filepath)

        # creatFolder会返回番号路径
        image_download(json_data.get('cover'), number, leak_word, c_word, path,
                       filepath)

        if not multi_part or part.lower() == '-cd1':
            # 下载预告片
            if conf.is_trailer() and json_data.get('trailer'):
                trailer_download(json_data.get('trailer'), leak_word, c_word,
                                 number, path, filepath)

            # 下载剧照 data, path, filepath
            if conf.is_extrafanart() and json_data.get('extrafanart'):
                extrafanart_download(json_data.get('extrafanart'), path,
                                     filepath)

        # 裁剪图
        cutImage(imagecut, path, number, leak_word, c_word)

        # 添加水印
        poster_path = os.path.join(path,
                                   f"{number}{leak_word}{c_word}-poster.jpg")
        thumb_path = os.path.join(path,
                                  f"{number}{leak_word}{c_word}-thumb.jpg")
        if conf.is_watermark():
            add_mark(poster_path, thumb_path, cn_sub, leak, uncensored)

        # 最后输出.nfo元数据文件,以完成.nfo文件创建作为任务成功标志
        print_files(path, leak_word, c_word, json_data.get('naming_rule'),
                    part, cn_sub, json_data, filepath, tag,
                    json_data.get('actor_list'), liuchu, uncensored)
示例#2
0
def core_main(movie_path, number_th, oCC):
    conf = config.getInstance()
    # =======================================================================初始化所需变量
    multi_part = 0
    part = ''
    leak_word = ''
    c_word = ''
    cn_sub = ''
    liuchu = ''
    hack = ''
    hack_word = ''

    # 下面被注释的变量不需要
    #rootpath= os.getcwd
    number = number_th
    json_data = get_data_from_json(number, oCC)  # 定义番号

    # Return if blank dict returned (data not found)
    if not json_data:
        moveFailedFolder(movie_path)
        return

    if json_data["number"] != number:
        # fix issue #119
        # the root cause is we normalize the search id
        # print_files() will use the normalized id from website,
        # but paste_file_to_folder() still use the input raw search id
        # so the solution is: use the normalized search id
        number = json_data["number"]
    imagecut = json_data.get('imagecut')
    tag = json_data.get('tag')
    # =======================================================================判断-C,-CD后缀
    if re.search('-CD\d+', movie_path, re.IGNORECASE):
        multi_part = 1
        part = re.findall('-CD\d+', movie_path, re.IGNORECASE)[0].upper()
    if re.search(r'[-_]C(\.\w+$|-\w+)|\d+ch(\.\w+$|-\w+)', movie_path,
                 re.I) or '中文' in movie_path or '字幕' in movie_path:
        cn_sub = '1'
        c_word = '-C'  # 中文字幕影片后缀

    # 判断是否无码
    unce = json_data.get('无码')
    uncensored = int(unce) if isinstance(unce, bool) else int(
        is_uncensored(number))

    if '流出' in movie_path or 'uncensored' in movie_path.lower():
        liuchu = '流出'
        leak = 1
        leak_word = '-流出'  # 流出影片后缀
    else:
        leak = 0

    if 'hack'.upper() in str(movie_path).upper() or '破解' in movie_path:
        hack = 1
        hack_word = "-hack"

    # 调试模式检测
    if conf.debug():
        debug_print(json_data)

    # 创建文件夹
    #path = create_folder(rootpath + '/' + conf.success_folder(),  json_data.get('location_rule'), json_data)

    cover = json_data.get('cover')
    ext = Path(cover).suffix
    fanart_path = f"{number}{leak_word}{c_word}{hack_word}-fanart{ext}"
    poster_path = f"{number}{leak_word}{c_word}{hack_word}-poster{ext}"
    thumb_path = f"{number}{leak_word}{c_word}{hack_word}-thumb{ext}"
    # main_mode
    #  1: 刮削模式 / Scraping mode
    #  2: 整理模式 / Organizing mode
    #  3:不改变路径刮削
    if conf.main_mode() == 1:
        # 创建文件夹
        path = create_folder(json_data)
        if multi_part == 1:
            number += part  # 这时number会被附加上CD1后缀

        # 检查小封面, 如果image cut为3,则下载小封面
        if imagecut == 3:
            small_cover_check(path, poster_path, json_data.get('cover_small'),
                              movie_path, json_data)

        # creatFolder会返回番号路径
        image_download(cover, fanart_path, thumb_path, path, movie_path,
                       json_data)

        if not multi_part or part.lower() == '-cd1':
            try:
                # 下载预告片
                if conf.is_trailer() and json_data.get('trailer'):
                    trailer_download(json_data.get('trailer'), leak_word,
                                     c_word, hack_word, number, path,
                                     movie_path)

                # 下载剧照 data, path, filepath
                if conf.is_extrafanart() and json_data.get('extrafanart'):
                    extrafanart_download(json_data.get('extrafanart'), path,
                                         number, movie_path, json_data)

                # 下载演员头像 KODI .actors 目录位置
                if conf.download_actor_photo_for_kodi():
                    actor_photo_download(json_data.get('actor_photo'), path,
                                         number)
            except:
                pass

        # 裁剪图
        cutImage(imagecut, path, fanart_path, poster_path,
                 bool(conf.face_uncensored_only() and not uncensored))

        # 添加水印
        if conf.is_watermark():
            add_mark(os.path.join(path, poster_path),
                     os.path.join(path, thumb_path), cn_sub, leak, uncensored,
                     hack)

        # 兼容Jellyfin封面图文件名规则
        if multi_part and conf.jellyfin_multi_part_fanart():
            linkImage(path, number_th, part, leak_word, c_word, hack_word, ext)

        # 移动电影
        paste_file_to_folder(movie_path, path, multi_part, number, part,
                             leak_word, c_word, hack_word)

        # 解压剧照压缩包
        if conf.is_extrafanart() and (not multi_part
                                      or part.lower() == '-cd1'):
            unzip_local_gallery(
                path)  # 这里有个小问题,如果影片只存在CD2不存在CD1,则不会解压缩,上面的-cd1条件也一样

        # 最后输出.nfo元数据文件,以完成.nfo文件创建作为任务成功标志
        print_files(path, leak_word, c_word, json_data.get('naming_rule'),
                    part, cn_sub, json_data, movie_path, tag,
                    json_data.get('actor_list'), liuchu, uncensored, hack_word,
                    fanart_path, poster_path, thumb_path)

    elif conf.main_mode() == 2:
        # 创建文件夹
        path = create_folder(json_data)
        # 移动文件
        paste_file_to_folder_mode2(movie_path, path, multi_part, number, part,
                                   leak_word, c_word, hack_word)
        if conf.is_watermark():
            add_mark(os.path.join(path, poster_path),
                     os.path.join(path, thumb_path), cn_sub, leak, uncensored,
                     hack)

    elif conf.main_mode() == 3:
        path = str(Path(movie_path).parent)
        if multi_part == 1:
            number += part  # 这时number会被附加上CD1后缀

        # 检查小封面, 如果image cut为3,则下载小封面
        if imagecut == 3:
            small_cover_check(path, poster_path, json_data.get('cover_small'),
                              movie_path, json_data)

        # creatFolder会返回番号路径
        image_download(cover, fanart_path, thumb_path, path, movie_path)

        if not multi_part or part.lower() == '-cd1':
            try:
                # 下载预告片
                if conf.is_trailer() and json_data.get('trailer'):
                    trailer_download(json_data.get('trailer'), leak_word,
                                     c_word, hack_word, number, path,
                                     movie_path)

                # 下载剧照 data, path, filepath
                if conf.is_extrafanart() and json_data.get('extrafanart'):
                    extrafanart_download(json_data.get('extrafanart'), path,
                                         number, movie_path, json_data)

                # 下载演员头像 KODI .actors 目录位置
                if conf.download_actor_photo_for_kodi():
                    actor_photo_download(json_data.get('actor_photo'), path,
                                         number)
            except:
                pass

        # 裁剪图
        cutImage(imagecut, path, fanart_path, poster_path,
                 bool(conf.face_uncensored_only() and not uncensored))

        # 添加水印
        if conf.is_watermark():
            add_mark(os.path.join(path, poster_path),
                     os.path.join(path, thumb_path), cn_sub, leak, uncensored,
                     hack)

        # 兼容Jellyfin封面图文件名规则
        if multi_part and conf.jellyfin_multi_part_fanart():
            linkImage(path, number_th, part, leak_word, c_word, hack_word, ext)

        # 解压剧照压缩包
        if conf.is_extrafanart() and (not multi_part
                                      or part.lower() == '-cd1'):
            unzip_local_gallery(path)

        # 最后输出.nfo元数据文件,以完成.nfo文件创建作为任务成功标志
        print_files(path, leak_word, c_word, json_data.get('naming_rule'),
                    part, cn_sub, json_data, movie_path, tag,
                    json_data.get('actor_list'), liuchu, uncensored, hack_word,
                    fanart_path, poster_path, thumb_path)