From 4d83f0e65afffe80110492e084d6f95791813bd9 Mon Sep 17 00:00:00 2001 From: mo_yy Date: Fri, 7 Feb 2020 20:08:20 +0800 Subject: [PATCH] 3.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持批量添加emby头像 --- ADC_function.py | 4 ++ AVDC.py | 45 +++++++++++++- AVDC.ui | 132 ++++++++++++++++++++++++++++++++++++++- AVDC_Main.py | 154 +++++++++++++++++++++++++++++++++++++++++++++- config.ini | 4 ++ update_check.json | 4 +- 6 files changed, 337 insertions(+), 6 deletions(-) diff --git a/ADC_function.py b/ADC_function.py index f03d3e863..9939bccfc 100755 --- a/ADC_function.py +++ b/ADC_function.py @@ -42,6 +42,10 @@ def save_config(json_config): print("", file=code) print("[debug_mode]", file=code) print("switch = " + str(json_config['switch_debug']), file=code) + print("", file=code) + print("[emby]", file=code) + print("emby_url = " + json_config['emby_url'], file=code) + print("api_key = " + json_config['api_key'], file=code) code.close() diff --git a/AVDC.py b/AVDC.py index c6af7a330..06b35e351 100644 --- a/AVDC.py +++ b/AVDC.py @@ -53,7 +53,7 @@ def setupUi(self, AVDV): self.lineEdit_escape_dir_move.setGeometry(QtCore.QRect(310, 30, 431, 24)) self.lineEdit_escape_dir_move.setObjectName("lineEdit_escape_dir_move") self.groupBox_7 = QtWidgets.QGroupBox(self.page_tool) - self.groupBox_7.setGeometry(QtCore.QRect(10, 140, 751, 121)) + self.groupBox_7.setGeometry(QtCore.QRect(10, 140, 751, 111)) self.groupBox_7.setObjectName("groupBox_7") self.label = QtWidgets.QLabel(self.groupBox_7) self.label.setGeometry(QtCore.QRect(230, 60, 511, 41)) @@ -74,6 +74,37 @@ def setupUi(self, AVDV): self.label_2 = QtWidgets.QLabel(self.groupBox_7) self.label_2.setGeometry(QtCore.QRect(230, 30, 72, 21)) self.label_2.setObjectName("label_2") + self.groupBox_12 = QtWidgets.QGroupBox(self.page_tool) + self.groupBox_12.setGeometry(QtCore.QRect(10, 270, 751, 191)) + self.groupBox_12.setObjectName("groupBox_12") + self.pushButton_add_actor_pic = QtWidgets.QPushButton(self.groupBox_12) + self.pushButton_add_actor_pic.setGeometry(QtCore.QRect(10, 30, 201, 71)) + self.pushButton_add_actor_pic.setObjectName("pushButton_add_actor_pic") + self.lineEdit_emby_url = QtWidgets.QLineEdit(self.groupBox_12) + self.lineEdit_emby_url.setGeometry(QtCore.QRect(310, 30, 431, 21)) + self.lineEdit_emby_url.setObjectName("lineEdit_emby_url") + self.label_3 = QtWidgets.QLabel(self.groupBox_12) + self.label_3.setGeometry(QtCore.QRect(230, 30, 72, 15)) + self.label_3.setObjectName("label_3") + self.label_4 = QtWidgets.QLabel(self.groupBox_12) + self.label_4.setGeometry(QtCore.QRect(230, 74, 72, 21)) + self.label_4.setObjectName("label_4") + self.lineEdit_api_key = QtWidgets.QLineEdit(self.groupBox_12) + self.lineEdit_api_key.setGeometry(QtCore.QRect(310, 70, 431, 21)) + self.lineEdit_api_key.setObjectName("lineEdit_api_key") + self.label_5 = QtWidgets.QLabel(self.groupBox_12) + self.label_5.setGeometry(QtCore.QRect(230, 110, 511, 71)) + self.label_5.setObjectName("label_5") + self.pushButton_show_pic_actor = QtWidgets.QPushButton(self.groupBox_12) + self.pushButton_show_pic_actor.setGeometry(QtCore.QRect(10, 140, 201, 31)) + self.pushButton_show_pic_actor.setObjectName("pushButton_show_pic_actor") + self.comboBox_pic_actor = QtWidgets.QComboBox(self.groupBox_12) + self.comboBox_pic_actor.setGeometry(QtCore.QRect(10, 110, 201, 21)) + self.comboBox_pic_actor.setObjectName("comboBox_pic_actor") + self.comboBox_pic_actor.addItem("") + self.comboBox_pic_actor.addItem("") + self.comboBox_pic_actor.addItem("") + self.comboBox_pic_actor.addItem("") self.stackedWidget.addWidget(self.page_tool) self.page_setting = QtWidgets.QWidget() self.page_setting.setObjectName("page_setting") @@ -303,6 +334,18 @@ def retranslateUi(self, AVDV): self.comboBox_website.setItemText(5, _translate("AVDV", "fanza")) self.comboBox_website.setItemText(6, _translate("AVDV", "siro")) self.label_2.setText(_translate("AVDV", "刮削网站:")) + self.groupBox_12.setTitle(_translate("AVDV", "Emby-女优头像")) + self.pushButton_add_actor_pic.setText(_translate("AVDV", "添加头像")) + self.label_3.setText(_translate("AVDV", "Emby地址:")) + self.label_4.setText(_translate("AVDV", "API密钥:")) + self.label_5.setText(_translate("AVDV", "说明:\n" +" 1、头像请放在程序目录下的Actor目录中。\n" +" 2、密钥创建方法:Emby控制台->高级->API密钥->添加(APP名称任意)。")) + self.pushButton_show_pic_actor.setText(_translate("AVDV", "查看")) + self.comboBox_pic_actor.setItemText(0, _translate("AVDV", "可添加头像的女优")) + self.comboBox_pic_actor.setItemText(1, _translate("AVDV", "没有头像的女优")) + self.comboBox_pic_actor.setItemText(2, _translate("AVDV", "已有头像的女优")) + self.comboBox_pic_actor.setItemText(3, _translate("AVDV", "所有女优")) self.pushButton_save_config.setText(_translate("AVDV", "保存")) self.groupBox_8.setTitle(_translate("AVDV", "命名规则")) self.label_43.setText(_translate("AVDV", " 目录命名: ")) diff --git a/AVDC.ui b/AVDC.ui index bef933f82..e48686ad3 100644 --- a/AVDC.ui +++ b/AVDC.ui @@ -150,7 +150,7 @@ p, li { white-space: pre-wrap; } 10 140 751 - 121 + 111 @@ -241,6 +241,136 @@ p, li { white-space: pre-wrap; } + + + + 10 + 270 + 751 + 191 + + + + Emby-女优头像 + + + + + 10 + 30 + 201 + 71 + + + + 添加头像 + + + + + + 310 + 30 + 431 + 21 + + + + + + + 230 + 30 + 72 + 15 + + + + Emby地址: + + + + + + 230 + 74 + 72 + 21 + + + + API密钥: + + + + + + 310 + 70 + 431 + 21 + + + + + + + 230 + 110 + 511 + 71 + + + + 说明: + 1、头像请放在程序目录下的Actor目录中。 + 2、密钥创建方法:Emby控制台->高级->API密钥->添加(APP名称任意)。 + + + + + + 10 + 140 + 201 + 31 + + + + 查看 + + + + + + 10 + 110 + 201 + 21 + + + + + 可添加头像的女优 + + + + + 没有头像的女优 + + + + + 已有头像的女优 + + + + + 所有女优 + + + + diff --git a/AVDC_Main.py b/AVDC_Main.py index 98481ff26..55d333e62 100644 --- a/AVDC_Main.py +++ b/AVDC_Main.py @@ -19,6 +19,9 @@ from core import * from fanza import * import requests +import re +import shutil +import base64 class MyMAinWindow(QMainWindow, Ui_AVDV): @@ -29,7 +32,9 @@ def __init__(self, parent=None): self.Ui = Ui_AVDV() # 实例化 Ui self.Ui.setupUi(self) # 初始化Ui self.Init_Ui() - self.version = '3.32' + self.version = '3.4' + self.m_drag = False + self.m_DragPosition = 0 self.Init() self.Load_Config() self.show_version() @@ -98,7 +103,7 @@ def Init_Ui(self): border-radius:20px; padding:2px 4px; } - QPushButton#pushButton_save_config, #pushButton_start_javdb{ + QPushButton#pushButton_save_config,#pushButton_start_javdb,#pushButton_add_actor_pic,#pushButton_show_pic_actor{ font-size:18px; background:#F0F8FF; border:2px solid white; @@ -121,6 +126,8 @@ def Init(self): self.Ui.pushButton_start_cap.clicked.connect(self.pushButton_start_cap_clicked) self.Ui.pushButton_save_config.clicked.connect(self.pushButton_save_config_clicked) self.Ui.pushButton_move_mp4.clicked.connect(self.move_file) + self.Ui.pushButton_add_actor_pic.clicked.connect(self.pushButton_add_actor_pic_clicked) + self.Ui.pushButton_show_pic_actor.clicked.connect(self.pushButton_show_pic_actor_clicked) # ========================================================================加载config def Load_Config(self): @@ -163,6 +170,8 @@ def Load_Config(self): self.Ui.lineEdit_dir_name.setText(config['Name_Rule']['location_rule']) self.Ui.lineEdit_media_name.setText(config['Name_Rule']['naming_rule']) self.Ui.lineEdit_escape_dir_move.setText(config['escape']['folders']) + self.Ui.lineEdit_emby_url.setText(config['emby']['emby_url']) + self.Ui.lineEdit_api_key.setText(config['emby']['api_key']) # ========================================================================显示版本号 def show_version(self): @@ -271,6 +280,8 @@ def save_config_clicked(self): 'naming_rule': self.Ui.lineEdit_media_name.text(), 'literals': self.Ui.lineEdit_escape_char.text(), 'folders': self.Ui.lineEdit_escape_dir.text(), + 'emby_url': self.Ui.lineEdit_emby_url.text(), + 'api_key': self.Ui.lineEdit_api_key.text(), } save_config(json_config) @@ -340,6 +351,145 @@ def move_file_thread(self): self.add_text_main("[+]Move Movies All Finished!!!") self.add_text_main("[*]======================================================") + # ========================================================================小工具-emby女优头像 + def pushButton_add_actor_pic_clicked(self): # 添加头像按钮响应 + self.Ui.stackedWidget.setCurrentIndex(0) + emby_url = self.Ui.lineEdit_emby_url.text() + api_key = self.Ui.lineEdit_api_key.text() + if emby_url == '': + self.add_text_main('[-]The emby_url is empty!') + self.add_text_main("[*]======================================================") + return + elif api_key == '': + self.add_text_main('[-]The api_key is empty!') + self.add_text_main("[*]======================================================") + return + try: + t = threading.Thread(target=self.found_profile_picture, args=(1,)) + t.start() # 启动线程,即让线程开始执行 + except Exception as error_info: + self.add_text_main('[-]Error in pushButton_add_actor_pic_clicked: ' + str(error_info)) + + def pushButton_show_pic_actor_clicked(self): # 查看按钮响应 + self.Ui.stackedWidget.setCurrentIndex(0) + emby_url = self.Ui.lineEdit_emby_url.text() + api_key = self.Ui.lineEdit_api_key.text() + if emby_url == '': + self.add_text_main('[-]The emby_url is empty!') + self.add_text_main("[*]======================================================") + return + elif api_key == '': + self.add_text_main('[-]The api_key is empty!') + self.add_text_main("[*]======================================================") + return + if self.Ui.comboBox_pic_actor.currentIndex() == 0: # 可添加头像的女优 + try: + t = threading.Thread(target=self.found_profile_picture, args=(2,)) + t.start() # 启动线程,即让线程开始执行 + except Exception as error_info: + self.add_text_main('[-]Error in pushButton_show_pic_actor_clicked: ' + str(error_info)) + else: + try: + t = threading.Thread(target=self.show_actor, args=(self.Ui.comboBox_pic_actor.currentIndex(),)) + t.start() # 启动线程,即让线程开始执行 + except Exception as error_info: + self.add_text_main('[-]Error in pushButton_show_pic_actor_clicked: ' + str(error_info)) + + def show_actor(self, mode): # 按模式显示相应列表 + actor_list = self.get_emby_actor_list() + count = 1 + actor_list_temp = '' + if mode == 1: # 没有头像的女优 + self.add_text_main('[+]没有头像的女优!') + elif mode == 2: # 有头像的女优 + self.add_text_main('[+]有头像的女优!') + elif mode == 3: # 所有女优 + self.add_text_main('[+]所有女优!') + for actor in actor_list['Items']: + if mode == 3: # 所有女优 + actor_list_temp += str(count) + '.' + actor['Name'] + ',' + count += 1 + elif mode == 2 and actor['ImageTags'] != {}: # 有头像的女优 + actor_list_temp += str(count) + '.' + actor['Name'] + ',' + count += 1 + elif mode == 1 and actor['ImageTags'] == {}: # 没有头像的女优 + actor_list_temp += str(count) + '.' + actor['Name'] + ',' + count += 1 + if (count - 1) % 5 == 0 and actor_list_temp != '': + self.add_text_main('[+]' + actor_list_temp) + actor_list_temp = '' + self.add_text_main("[*]======================================================") + + def get_emby_actor_list(self): # 获取emby的演员列表 + emby_url = self.Ui.lineEdit_emby_url.text() + api_key = self.Ui.lineEdit_api_key.text() + emby_url = emby_url.replace(':', ':') + url = 'http://' + emby_url + '/emby/Persons?api_key=' + api_key + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/60.0.3100.0 Safari/537.36'} + getweb = requests.get(str(url), headers=headers, timeout=10) + getweb.encoding = 'utf-8' + actor_list = json.loads(getweb.text) + return actor_list + + def found_profile_picture(self, mode): # mode=1,上传头像,mode=2,显示可添加头像的女优 + path = 'Actor' + profile_pictures = os.listdir(path) + actor_list = self.get_emby_actor_list() + if mode == 1: + self.add_text_main('[+]Start upload profile pictures!') + elif mode ==2: + self.add_text_main('[+]可添加头像的女优!') + count = 1 + for actor in actor_list['Items']: + flag = 0 + pic_name = '' + if actor['ImageTags'] == {}: + if actor['Name'] + '.jpg' in profile_pictures: + flag = 1 + pic_name = actor['Name'] + '.jpg' + elif actor['Name'] + '.png' in profile_pictures: + flag = 1 + pic_name = actor['Name'] + '.png' + if flag == 0: + byname_list = re.split('[,()]', actor['Name']) + for byname in byname_list: + if byname + '.jpg' in profile_pictures: + pic_name = byname + '.jpg' + flag = 1 + break + elif byname + '.png' in profile_pictures: + pic_name = byname + '.png' + flag = 1 + break + if flag == 1: + if mode == 1: + self.upload_profile_picture(count, actor, path + '/' + pic_name) + else: + self.add_text_main('[+]' + "%4s" % str(count) + '.Actor name: ' + actor['Name'] + ' Pic name: ' + + pic_name) + count += 1 + self.add_text_main("[*]======================================================") + + def upload_profile_picture(self, count, actor, pic_path): # 上传头像 + emby_url = self.Ui.lineEdit_emby_url.text() + api_key = self.Ui.lineEdit_api_key.text() + emby_url = emby_url.replace(':', ':') + f = open(pic_path, 'rb') # 二进制方式打开图文件 + b6_pic = base64.b64encode(f.read()) # 读取文件内容,转换为base64编码 + f.close() + url = 'http://' + emby_url + '/emby/Items/' + actor['Id'] + '/Images/Primary?api_key=' + api_key + if pic_path.endswith('jpg'): + header = {"Content-Type": 'image/png', } + else: + header = {"Content-Type": 'image/jpeg', } + try: + respones = requests.post(url=url, data=b6_pic, headers=header) + self.add_text_main('[+]' + "%4s" % str(count) + '.Success upload profile picture for ' + actor['Name'] + '!') + except Exception as error_info: + self.add_text_main('[-]Error in upload_profile_picture! ' + str(error_info)) + # ========================================================================core.py def add_text_main(self, text): time.sleep(0.1) diff --git a/config.ini b/config.ini index 0e7807711..9d1dd927d 100644 --- a/config.ini +++ b/config.ini @@ -28,3 +28,7 @@ folders = failed,JAV_output [debug_mode] switch = 0 + +[emby] +emby_url = localhost:8096 +api_key = diff --git a/update_check.json b/update_check.json index 4d1d2668a..24262324c 100644 --- a/update_check.json +++ b/update_check.json @@ -1,5 +1,5 @@ { - "version": "3.32", - "version_show":"3.32", + "version": "3.4", + "version_show":"3.4", "download": "https://github.com/moyy996/AVDC/releases" }