From 4d7bf88ba23d184313bcfa64a8a98db996089044 Mon Sep 17 00:00:00 2001 From: yoshiko2 Date: Fri, 18 Sep 2020 08:24:51 +0800 Subject: [PATCH] Delete Useless file --- actor.py | 119 -------------------------- emby_actor.py | 226 -------------------------------------------------- 2 files changed, 345 deletions(-) delete mode 100644 actor.py delete mode 100644 emby_actor.py diff --git a/actor.py b/actor.py deleted file mode 100644 index 382ff51..0000000 --- a/actor.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - - -import requests, os -from configparser import RawConfigParser -from base64 import b64encode -from traceback import format_exc -from json import loads -from os.path import exists - -# 检查“actor_photos”文件夹是否就绪 -if not exists('actor_photos'): - print('\n“actor_photos” folder lost!Please put it to the same location with program\n') - os.system('pause') -# 读取配置文件,这个ini文件用来给用户设置emby网址和api id -print('Reading ini Setting...') -config_settings = RawConfigParser() -try: - config_settings.read('ap_config.ini', encoding='utf-8-sig') - url_emby = config_settings.get("emby/jellyfin", "website") - api_key = config_settings.get("emby/jellyfin", "api id") - bool_replace = True if config_settings.get("emby/jellyfin", "是否覆盖以前上传的头像?") == '是' else False -except: - print(format_exc()) - print('Cannot read ini files!') - os.system('pause') -print('Read Success!\n') -# 修正用户输入的emby网址,无论是不是带“/” -if not url_emby.endswith('/'): - url_emby += '/' -# 成功的个数 -num_suc = 0 -num_fail = 0 -num_exist = 0 -sep = os.sep -try: - print('Getting emby/jellyfin Person`s form...') - # curl -X GET "http://localhost:8096/emby/Persons?api_key=3291434710e342089565ad05b6b2f499" -H "accept: application/json" - # 得到所有“人员” emby api没有细分“演员”还是“导演”“编剧”等等 下面得到的是所有“有关人员” - url_emby_persons = url_emby + 'emby/Persons?api_key=' + api_key # &PersonTypes=Actor - try: - rqs_emby = requests.get(url=url_emby_persons) - except requests.exceptions.ConnectionError: - print('Cannot connect to emby/jellyfin server ,Please check:', url_emby, '\n') - os.system('pause') - except: - print(format_exc()) - print('Unkown Error ,Please submit screenshot to issues', url_emby, '\n') - os.system('pause') - # 401,无权访问 - if rqs_emby.status_code == 401: - print('Please check API KEY!\n') - os.system('pause') - # print(rqs_emby.text) - try: - list_persons = loads(rqs_emby.text)['Items'] - except: - print(rqs_emby.text) - print('Error! emby response:') - print('Please submit screenshot to issues!') - os.system('pause') - num_persons = len(list_persons) - print('There are currently' + str(num_persons) + ' People!\n') - # os.system('pause') - # 用户emby中的persons,在“actor_photos”文件夹中,已有头像的,记录下来 - f_txt = open("included.txt", 'w', encoding="utf-8") - f_txt.close() - f_txt = open("no_included.txt", 'w', encoding="utf-8") - f_txt.close() - for dic_each_actor in list_persons: - actor_name = dic_each_actor['Name'] - # 头像jpg/png在“actor_photos”中的路径 - actor_pic_path = 'actor_photos' + sep + actor_name[0] + sep + actor_name - if exists(actor_pic_path + '.jpg'): - actor_pic_path = actor_pic_path + '.jpg' - header = {"Content-Type": 'image/jpeg', } - elif exists(actor_pic_path + '.png'): - actor_pic_path = actor_pic_path + '.png' - header = {"Content-Type": 'image/png', } - else: - print('>>No image:', actor_name) - f_txt = open("no_included.txt", 'a', encoding="utf-8") - f_txt.write(actor_name + '\n') - f_txt.close() - num_fail += 1 - continue - # emby有某个演员,“actor_photos”文件夹也有这个演员的头像,记录一下 - f_txt = open("included.txt", 'a', encoding="utf-8") - f_txt.write(actor_name + '\n') - f_txt.close() - # emby有某个演员,已经有他的头像,不再进行下面“上传头像”的操作 - if dic_each_actor['ImageTags']: # emby已经收录头像 - num_exist += 1 - if not bool_replace: # 不需要覆盖已有头像 - continue # 那么不进行下面的上传操作 - f_pic = open(actor_pic_path, 'rb') # 二进制方式打开图文件 - b6_pic = b64encode(f_pic.read()) # 读取文件内容,转换为base64编码 - f_pic.close() - url_post_img = url_emby + 'emby/Items/' + dic_each_actor['Id'] + '/Images/Primary?api_key=' + api_key - requests.post(url=url_post_img, data=b6_pic, headers=header) - print('>>Success:', actor_name) - num_suc += 1 - - print('\nemby/jellyfin people: ', num_persons, '') - print('include photos: ', num_exist, '') - if bool_replace: - print('Mode:Overwrite existed images') - else: - print('Mode:Skip existed images') - print('Success Upload', num_suc, '个!') - print('No images', num_fail, '个!') - print('Saved to “no_included.txt”\n') - os.system('pause') -except: - print(format_exc()) - os.system('pause') - - diff --git a/emby_actor.py b/emby_actor.py deleted file mode 100644 index b1de49f..0000000 --- a/emby_actor.py +++ /dev/null @@ -1,226 +0,0 @@ -# -*- coding:utf-8 -*- -# Gfriends Inputer / 女友头像仓库导入工具 -# By xinxin8816, Many thanks for junerain123, ddd354, moyy996. - -import requests, os, sys -from configparser import RawConfigParser -from base64 import b64encode -from traceback import format_exc -from json import loads -from PIL import Image, ImageFilter -from alive_progress import alive_bar - - -def fix_size(path): - pic = Image.open(path) - (x, y) = pic.size - if not 2 / 3 - 0.05 <= x / y <= 2 / 3 + 0.05: # 仅处理会过度拉伸的图片 - fixed_pic = pic.resize((int(x), int(3 / 2 * x))) # 拉伸图片 - fixed_pic = fixed_pic.filter(ImageFilter.GaussianBlur(radius=50)) # 高斯模糊 - fixed_pic.paste(pic, (0, int((3 / 2 * x - y) / 2))) # 粘贴原图 - fixed_pic.save(path) - - -def get_gfriends_map(repository_url): - print('下载头像仓库文件树...') - if repository_url == '默认/': - repository_url = 'https://raw.githubusercontent.com/xinxin8816/gfriends/master/' - github_template = repository_url + '{}/{}/{}' - request_url = repository_url + 'Filetree.json' - try: - if proxy == '不使用': - response = session.get(request_url) - else: - response = session.get(request_url, proxies=proxies) - except: - print(format_exc()) - print('网络连接异常且重试 ' + max_retries + ' 次失败') - print('请尝试开启全局代理或配置 HTTP 局部代理;若已开启代理,请检查其可用性') - sys.exit() - if response.status_code != 200: - print('女友仓库返回了一个错误: {}'.format(response.status_code)) - sys.exit() - - map_json = loads(response.content) - output = {} - - first_lvls = map_json.keys() - for first in first_lvls: - second_lvls = map_json[first].keys() - for second in second_lvls: - for k, v in map_json[first][second].items(): - output[k[:-4]] = github_template.format(first, second, v) - - print('读取头像仓库文件树完成') - print('当前仓库头像数量:' + str(response.text.count('\n')) + '枚\n') - return output - - -def get_gfriends_link(name): - if name in gfriends_map: - output = gfriends_map[name] - return output - else: - return None - - -def read_config(): - if os.path.exists('config.ini'): - config_settings = RawConfigParser() - try: - config_settings.read('config.ini', encoding='UTF-8') - repository_url = config_settings.get("下载设置", "repository url") - host_url = config_settings.get("媒体服务器", "host url") - api_key = config_settings.get("媒体服务器", "api id") - max_retries = config_settings.get("下载设置", "max retry") - proxy = config_settings.get("下载设置", "proxy") - overwrite = True if config_settings.get("导入设置", "是否覆盖以前上传的头像?") == '是' else False - fixsize = True if config_settings.get("导入设置", "是否处理下载的头像?") == '是' else False - # 修正用户的URL - if not host_url.endswith('/'): - host_url += '/' - if not repository_url.endswith('/'): - repository_url += '/' - return (repository_url, host_url, api_key, overwrite, fixsize, max_retries, proxy) - except: - print(format_exc()) - print('无法读取 config.ini') - os.system('pause') - else: - content = '''[媒体服务器] -# Emby/Jellyfin 服务器地址 -host url = http://localhost:8096/ - -# Emby/Jellyfin API 密匙 -api id = - -[下载设置] -# 女友头像仓库地址,"默认"使用主分支:https://raw.githubusercontent.com/xinxin8816/gfriends/master/,网络不稳定可使用仓库备用镜像:https://gfriends.imfast.io/ -repository url = 默认 - -# HTTP局部代理地址,格式为"IP:端口",推荐开启全局代理而不是使用此处的局部代理 -proxy = 不使用 - -# 最大重试次数,若网络连接不稳定,丢包率或延迟较高,可适当增加重试次数 -max retry = 5 - -[导入设置] -# 处理以满足尺寸需求,能避免部分头像被拉伸但会牺牲一定质量 -是否处理下载的头像? = 是 - -是否覆盖以前上传的头像? = 是''' - write_txt("config.ini", content) - print('没有找到配置文件 config.ini,已为阁下生成,请修改配置后重新运行程序\n') - os.system('pause') - sys.exit() - - -def read_persons(host_url, api_key): - print('读取 Emby / Jellyfin 演员...') - host_url_persons = host_url + 'emby/Persons?api_key=' + api_key # &PersonTypes=Actor - try: - rqs_emby = requests.get(url=host_url_persons) - except requests.exceptions.ConnectionError: - print('连接 Emby / Jellyfin 服务器失败,请检查:', host_url, '\n') - sys.exit() - except: - print(format_exc()) - print('连接 Emby / Jellyfin 服务器未知错误', host_url, '\n') - sys.exit() - if rqs_emby.status_code == 401: - print('无权访问 Emby / Jellyfin 服务器,请检查 API 密匙\n') - sys.exit() - output = loads(rqs_emby.text)['Items'] - print('读取 Emby / Jellyfin 演员完成\n') - return output - - -def write_txt(filename, content): - txt = open(filename, 'a', encoding="utf-8") - txt.write(content) - txt.close() - - -os.system('title Gfriends 一键导入工具') -print('读取配置文件 config.ini') -(repository_url, host_url, api_key, overwrite, fixsize, max_retries, proxy) = read_config() -os.system('cls') - -num_suc = 0 -num_fail = 0 -num_exist = 0 -try: - print('Gfriends 一键导入工具') - print('https://github.com/xinxin8816/gfriends') - # 局部代理 - if proxy == '不使用': - print('推荐开启全局代理以加快下载速度\n') - else: - print('已配置 HTTP 局部代理:' + proxy + ',请确保其可用\n') - proxies = { - 'http': 'http://' + proxy, - 'https': 'https://' + proxy - } - os.system('pause') - # 持久会话 - session = requests.Session() - session.mount('http://', requests.adapters.HTTPAdapter(max_retries=max_retries)) - session.mount('https://', requests.adapters.HTTPAdapter(max_retries=max_retries)) - list_persons = read_persons(host_url, api_key) - gfriends_map = get_gfriends_map(repository_url) - # 下载文件夹 - folder_path = './Downloads/' - if os.path.exists(folder_path) == False: - os.makedirs(folder_path) - with alive_bar(len(list_persons), theme='ascii', enrich_print=False) as bar: - for dic_each_actor in list_persons: - actor_name = dic_each_actor['Name'] - bar() - if get_gfriends_link(actor_name) == None: - print('>> 未收录:', actor_name) - write_txt("未收录的演员清单.txt", actor_name + '\n') - num_fail += 1 - else: - write_txt("已匹配的演员清单.txt", actor_name + '\n') - if dic_each_actor['ImageTags']: - num_exist += 1 - if not overwrite: - print('>> 跳过:', actor_name) - continue - print('>> 下载并导入:', get_gfriends_link(actor_name)) - try: - if proxy == '不使用': - pic = session.get(get_gfriends_link(actor_name)) - else: - pic = session.get(get_gfriends_link(actor_name), proxies=proxies) - except (KeyboardInterrupt): - sys.exit() - except: - with bar.pause(): - print(format_exc()) - print('网络连接异常且重试 ' + max_retries + ' 次失败') - print('请尝试开启全局代理或配置 HTTP 局部代理;若已开启代理,请检查其可用性') - print('继续运行则跳过下载此头像:' + actor_name) - os.system('pause') - continue - with open("Downloads/" + actor_name + ".jpg", "wb") as code: - code.write(pic.content) - if fixsize: - fix_size("Downloads/" + actor_name + ".jpg") - pic = open("Downloads/" + actor_name + ".jpg", 'rb') - b6_pic = b64encode(pic.read()) - pic.close() - url_post_img = host_url + 'emby/Items/' + dic_each_actor['Id'] + '/Images/Primary?api_key=' + api_key - session.post(url=url_post_img, data=b6_pic, headers={"Content-Type": 'image/jpeg', }) - num_suc += 1 - print('\nEmby / Jellyfin 拥有演员', len(list_persons), '人,当前已有头像', num_exist, '人') - print('本次成功导入', num_suc, '人') - print('仓库未收录', num_fail, '人\n') - os.system('pause') -except (KeyboardInterrupt, SystemExit): - print('强制停止或已知致命错误!') - os.system('pause') -except: - print(format_exc()) - print('未知致命错误!') - os.system('pause')