def getStoryline(number, title, sites: list = None, 无码=None): start_time = time.time() conf = config.getInstance() if not conf.is_storyline(): return '' debug = conf.debug() or conf.storyline_show() == 2 storyine_sites = conf.storyline_site().split( ',') if sites is None else sites unc = 无码 if isinstance(无码, bool) else is_uncensored(number) if unc: storyine_sites += conf.storyline_uncensored_site().split(',') else: storyine_sites += conf.storyline_censored_site().split(',') r_dup = set() sort_sites = [] for s in storyine_sites: ns = re.sub(r'.*?:', '', s, re.A) if ns in G_registered_storyline_site and ns not in r_dup: sort_sites.append(s) r_dup.add(ns) sort_sites.sort() apply_sites = [re.sub(r'.*?:', '', s, re.A) for s in sort_sites] mp_args = ((site, number, title, debug) for site in apply_sites) cores = min(len(apply_sites), os.cpu_count()) if cores == 0: return '' run_mode = 1 if conf.storyline_mode() > 0 else 0 with ThreadPool(cores) if run_mode > 0 else noThread() as pool: results = pool.map(getStoryline_mp, mp_args) sel = '' if not debug and conf.storyline_show() == 0: for value in results: if isinstance(value, str) and len(value): if not is_japanese(value): return value if not len(sel): sel = value return sel # 以下debug结果输出会写入日志 s = f'[!]Storyline{G_mode_txt[run_mode]}模式运行{len(apply_sites)}个任务共耗时(含启动开销){time.time() - start_time:.3f}秒,结束于{time.strftime("%H:%M:%S")}' sel_site = '' for site, desc in zip(apply_sites, results): if isinstance(desc, str) and len(desc): if not is_japanese(desc): sel_site, sel = site, desc break if not len(sel_site): sel_site, sel = site, desc for site, desc in zip(apply_sites, results): sl = len(desc) if isinstance(desc, str) else 0 s += f',[选中{site}字数:{sl}]' if site == sel_site else f',{site}字数:{sl}' if sl else f',{site}:空' print(s) return sel
def core_main_no_net_op(movie_path, number): conf = config.getInstance() part = '' leak_word = '' leak = 0 c_word = '' cn_sub = '' hack = '' hack_word = '' ext = '.jpg' imagecut = 1 path = str(Path(movie_path).parent) if re.search('[-_]CD\d+', movie_path, re.IGNORECASE): 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' # 中文字幕影片后缀 uncensored = 1 if is_uncensored(number) else 0 if '流出' in movie_path or 'uncensored' in movie_path.lower(): leak_word = '-流出' # 流出影片后缀 leak = 1 if 'hack'.upper() in str(movie_path).upper() or '破解' in movie_path: hack = 1 hack_word = "-hack" prestr = f"{number}{leak_word}{c_word}{hack_word}" fanart_path = f"{prestr}-fanart{ext}" poster_path = f"{prestr}-poster{ext}" thumb_path = f"{prestr}-thumb{ext}" full_fanart_path = os.path.join(path, fanart_path) full_poster_path = os.path.join(path, poster_path) full_thumb_path = os.path.join(path, thumb_path) full_nfo = Path(path) / f"{prestr}{part}.nfo" if full_nfo.is_file(): if full_nfo.read_text(encoding='utf-8').find(r'<tag>无码</tag>') >= 0: uncensored = 1 else: return if not all(os.path.isfile(f) for f in (full_fanart_path, full_thumb_path)): return cutImage(imagecut, path, fanart_path, poster_path, bool(conf.face_uncensored_only() and not uncensored)) if conf.is_watermark(): add_mark(full_poster_path, full_thumb_path, cn_sub, leak, uncensored, hack)
def getStoryline(number, title, sites: list=None): start_time = time.time() conf = config.getInstance() debug = conf.debug() or conf.storyline_show() == 2 storyine_sites = conf.storyline_site().split(',') if sites is None else sites if is_uncensored(number): storyine_sites += conf.storyline_uncensored_site().split(',') else: storyine_sites += conf.storyline_censored_site().split(',') r_dup = set() apply_sites = [] for s in storyine_sites: if s in G_registered_storyline_site and s not in r_dup: apply_sites.append(s) r_dup.add(s) mp_args = ((site, number, title, debug) for site in apply_sites) cores = min(len(apply_sites), os.cpu_count()) if cores == 0: return '' run_mode = conf.storyline_mode() assert run_mode in (0,1,2) with ThreadPool(cores) if run_mode == 1 else Pool(cores) if run_mode == 2 else noThread() as pool: result = pool.map(getStoryline_mp, mp_args) result = list(result) if run_mode == 0 else result if not debug and conf.storyline_show() == 0: for value in result: if isinstance(value, str) and len(value): return value return '' # 以下debug结果输出会写入日志,进程池中的则不会,只在标准输出中显示 cnt = len(apply_sites) s = f'[!]Storyline{G_mode_txt[run_mode]}模式运行{cnt}个进程总用时(含启动开销){time.time() - start_time:.3f}秒,结束于{time.strftime("%H:%M:%S")}' first = True sel = '' for i in range(cnt): sl = len(result[i])if isinstance(result[i], str) else 0 if sl and first: s += f',[选中{apply_sites[i]}字数:{sl}]' first = False sel = result[i] elif sl: s += f',{apply_sites[i]}字数:{sl}' else: s += f',{apply_sites[i]}:空' print(s) return sel
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)
def core_main_no_net_op(movie_path, number): conf = config.getInstance() part = '' leak_word = '' leak = 0 c_word = '' cn_sub = '' hack = '' hack_word = '' imagecut = 1 multi = False part = '' path = str(Path(movie_path).parent) if re.search('-CD\d+', movie_path, re.IGNORECASE): part = re.findall('-CD\d+', movie_path, re.IGNORECASE)[0].upper() multi = True if re.search( r'[-_]C(\.\w+$|-\w+)|\d+ch(\.\w+$|-\w+)', movie_path, re.I ) or '中文' in movie_path or '字幕' in movie_path or ".chs" in movie_path or '.cht' in movie_path: cn_sub = '1' c_word = '-C' # 中文字幕影片后缀 uncensored = 1 if is_uncensored(number) else 0 if '流出' in movie_path or 'uncensored' in movie_path.lower(): leak_word = '-流出' # 流出影片后缀 leak = 1 if 'hack'.upper() in str(movie_path).upper() or '破解' in movie_path: hack = 1 hack_word = "-hack" prestr = f"{number}{leak_word}{c_word}{hack_word}" full_nfo = Path(path) / f"{prestr}{part}.nfo" if full_nfo.is_file(): if full_nfo.read_text(encoding='utf-8').find(r'<tag>无码</tag>') >= 0: uncensored = 1 try: nfo_xml = etree.parse(full_nfo) nfo_fanart_path = nfo_xml.xpath('//fanart/text()')[0] ext = Path(nfo_fanart_path).suffix if conf.download_actor_photo_for_kodi(): actors_fullpath = full_nfo.with_name('.actors') actors_name = nfo_xml.xpath('//actor/name/text()') local_cnt = 0 for actor_name in actors_name: pic_fullpath = actors_fullpath / f'{actor_name}.jpg' if conf.download_only_missing_images( ) and not file_not_exist_or_empty(pic_fullpath): continue if copy_from_local_gfriends(actor_name, pic_fullpath): local_cnt += 1 if local_cnt: print( f"[+]Successfully link or copy {local_cnt} actor photo from local gfriends git repository" ) except: return else: return fanart_path = f"{prestr}-fanart{ext}" poster_path = f"{prestr}-poster{ext}" thumb_path = f"{prestr}-thumb{ext}" full_fanart_path = os.path.join(path, fanart_path) full_poster_path = os.path.join(path, poster_path) full_thumb_path = os.path.join(path, thumb_path) if not all(os.path.isfile(f) for f in (full_fanart_path, full_thumb_path)): return cutImage(imagecut, path, fanart_path, poster_path, bool(conf.face_uncensored_only() and not uncensored)) if conf.is_watermark(): add_mark(full_poster_path, full_thumb_path, cn_sub, leak, uncensored, hack) if multi and conf.jellyfin_multi_part_fanart(): linkImage(path, number, part, leak_word, c_word, hack_word, ext) if conf.is_extrafanart(): unzip_local_gallery(path)
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)