下载演员头像到.actors目录,KODI用;不联网的Jellyfin封面图文件名
This commit is contained in:
95
core.py
95
core.py
@@ -172,6 +172,7 @@ def download_file_with_filename(url, filename, path, filepath):
|
||||
moveFailedFolder(filepath)
|
||||
return
|
||||
|
||||
|
||||
def trailer_download(trailer, leak_word, c_word, hack_word, number, path, filepath):
|
||||
if download_file_with_filename(trailer, number + leak_word + c_word + hack_word + '-trailer.mp4', path, filepath) == 'failed':
|
||||
return
|
||||
@@ -187,12 +188,50 @@ def trailer_download(trailer, leak_word, c_word, hack_word, number, path, filepa
|
||||
return
|
||||
print('[+]Video Downloaded!', path + '/' + number + leak_word + c_word + hack_word + '-trailer.mp4')
|
||||
|
||||
|
||||
def actor_photo_download(actors, save_dir, number):
|
||||
if not isinstance(actors, dict) or not len(actors) or not len(save_dir):
|
||||
return
|
||||
save_dir = Path(save_dir)
|
||||
if not save_dir.is_dir():
|
||||
return
|
||||
conf = config.getInstance()
|
||||
actors_dir = save_dir / '.actors'
|
||||
download_only_missing_images = conf.download_only_missing_images()
|
||||
dn_list = []
|
||||
for actor_name, url in actors.items():
|
||||
res = re.match(r'^http.*(\.\w+)$', url, re.A)
|
||||
if not res:
|
||||
continue
|
||||
ext = res.group(1)
|
||||
pic_fullpath = actors_dir / f'{actor_name}{ext}'
|
||||
if download_only_missing_images and not file_not_exist_or_empty(pic_fullpath):
|
||||
continue
|
||||
dn_list.append((url, pic_fullpath))
|
||||
if not len(dn_list):
|
||||
return
|
||||
parallel = min(len(dn_list), conf.extrafanart_thread_pool_download())
|
||||
if parallel > 100:
|
||||
print('[!]Warrning: Parallel download thread too large may cause website ban IP!')
|
||||
result = parallel_download_files(dn_list, parallel)
|
||||
failed = 0
|
||||
for i, r in enumerate(result):
|
||||
if not r:
|
||||
failed += 1
|
||||
print(f"[-]Actor photo '{dn_list[i][0]}' to '{dn_list[i][1]}' download failed!")
|
||||
if failed: # 非致命错误,电影不移入失败文件夹,将来可以用模式3补齐
|
||||
print(f"[-]Failed downloaded {failed}/{len(result)} actor photo for [{number}] to '{actors_dir}', you may retry run mode 3 later.")
|
||||
else:
|
||||
print(f"[+]Successfully downloaded {len(result)} actor photo.")
|
||||
|
||||
|
||||
# 剧照下载成功,否则移动到failed
|
||||
def extrafanart_download(data, path, number, filepath):
|
||||
if config.getInstance().extrafanart_thread_pool_download():
|
||||
return extrafanart_download_threadpool(data, path, number)
|
||||
extrafanart_download_one_by_one(data, path, filepath)
|
||||
|
||||
|
||||
def extrafanart_download_one_by_one(data, path, filepath):
|
||||
tm_start = time.perf_counter()
|
||||
j = 1
|
||||
@@ -252,12 +291,14 @@ def extrafanart_download_threadpool(url_list, save_dir, number):
|
||||
if conf.debug():
|
||||
print(f'[!]Extrafanart download ThreadPool mode runtime {time.perf_counter() - tm_start:.3f}s')
|
||||
|
||||
|
||||
def image_ext(url):
|
||||
try:
|
||||
return os.path.splitext(url)[-1]
|
||||
except:
|
||||
return ".jpg"
|
||||
|
||||
|
||||
# 封面是否下载成功,否则移动到failed
|
||||
def image_download(cover, fanart_path, thumb_path, path, filepath):
|
||||
full_filepath = os.path.join(path, fanart_path)
|
||||
@@ -676,12 +717,14 @@ def core_main_no_net_op(movie_path, number):
|
||||
cn_sub = ''
|
||||
hack = ''
|
||||
hack_word = ''
|
||||
ext = '.jpg'
|
||||
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:
|
||||
cn_sub = '1'
|
||||
@@ -696,19 +739,24 @@ def core_main_no_net_op(movie_path, number):
|
||||
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
|
||||
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)
|
||||
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
|
||||
@@ -717,6 +765,9 @@ def core_main_no_net_op(movie_path, number):
|
||||
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)
|
||||
|
||||
|
||||
def core_main(movie_path, number_th, oCC):
|
||||
conf = config.getInstance()
|
||||
@@ -808,16 +859,17 @@ def core_main(movie_path, number_th, oCC):
|
||||
# 下载预告片
|
||||
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)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
|
||||
# 下载剧照 data, path, filepath
|
||||
if conf.is_extrafanart() and json_data.get('extrafanart'):
|
||||
extrafanart_download(json_data.get('extrafanart'), path, number, movie_path)
|
||||
|
||||
# 下载演员头像 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))
|
||||
|
||||
@@ -857,13 +909,20 @@ def core_main(movie_path, number_th, oCC):
|
||||
image_download( cover, fanart_path, thumb_path, path, movie_path)
|
||||
|
||||
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, hack_word, number, path, movie_path)
|
||||
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)
|
||||
# 下载剧照 data, path, filepath
|
||||
if conf.is_extrafanart() and json_data.get('extrafanart'):
|
||||
extrafanart_download(json_data.get('extrafanart'), path, number, movie_path)
|
||||
|
||||
# 下载演员头像 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))
|
||||
|
||||
Reference in New Issue
Block a user