diff --git a/README.md b/README.md index 17e2225..477af1e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - [插件自动更新 1.2](docs%2FPluginAutoUpdate.md) - [插件强制重装 1.2](docs%2FPluginReInstall.md) - [群辉Webhook通知 1.1](docs%2FSynologyNotify.md) -- [同步CookieCloud 1.2](docs%2FSyncCookieCloud.md) +- [同步CookieCloud 1.1](docs%2FSyncCookieCloud.md) - [日程提醒 1.0](docs%2FScheduleReminder.md) - [订阅提醒 1.1](docs%2FSubscribeReminder.md) diff --git a/docs/SyncCookieCloud.md b/docs/SyncCookieCloud.md index 329edfe..bad60df 100644 --- a/docs/SyncCookieCloud.md +++ b/docs/SyncCookieCloud.md @@ -2,10 +2,11 @@ ### 更新记录 -- 1.2 移除三方依赖 - 1.1 修复CookieCloud覆盖到浏览器 - 1.0 同步MoviePilot站点Cookie到CookieCloud 1、同步MoviePilot站点Cookie到CookieCloud -2、看到日志返回成功之后,浏览器的CookieCloud选择覆盖到浏览器,手动同步即可 \ No newline at end of file +2、看到日志返回成功之后,浏览器的CookieCloud选择覆盖到浏览器,手动同步即可 + +注:如果执行失败,进入mp容器执行 `pip install PyCookieCloud` \ No newline at end of file diff --git a/package.json b/package.json index a0ecdef..8e50bc3 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "SyncCookieCloud": { "name": "同步CookieCloud", "description": "同步MoviePilot站点Cookie到CookieCloud。", - "version": "1.2", + "version": "1.1", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cookiecloud.png", "author": "thsrite", "level": 1 diff --git a/plugins/synccookiecloud/__init__.py b/plugins/synccookiecloud/__init__.py index 81f31ae..7e20acb 100644 --- a/plugins/synccookiecloud/__init__.py +++ b/plugins/synccookiecloud/__init__.py @@ -1,14 +1,8 @@ -import hashlib -import json from datetime import datetime, timedelta -from urllib.parse import urljoin import pytz -import requests -from Cryptodome import Random -from Cryptodome.Cipher import AES -import base64 -from hashlib import md5 +from PyCookieCloud import PyCookieCloud + from app.core.config import settings from app.db.site_oper import SiteOper from app.plugins import _PluginBase @@ -26,7 +20,7 @@ class SyncCookieCloud(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cookiecloud.png" # 插件版本 - plugin_version = "1.2" + plugin_version = "1.1" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -98,8 +92,10 @@ class SyncCookieCloud(_PluginBase): if not sites: return - if not settings.COOKIECLOUD_HOST or not settings.COOKIECLOUD_KEY or not settings.COOKIECLOUD_PASSWORD: - logger.error('cookiecloud配置错误,请检查配置') + cookie_cloud = PyCookieCloud(settings.COOKIECLOUD_HOST, settings.COOKIECLOUD_KEY, settings.COOKIECLOUD_PASSWORD) + the_key = cookie_cloud.get_the_key() + if not the_key: + logger.error('链接cookiecloud异常,请检查配置') return cookies = {} @@ -127,65 +123,11 @@ class SyncCookieCloud(_PluginBase): # 覆盖到cookiecloud if cookies: - success = self.__update_cookie(cookies) + success = cookie_cloud.update_cookie(cookies) logger.info(cookies) logger.info(f"同步站点cookie到CookieCloud {'成功' if success else '失败'}") - def __update_cookie(self, cookie: Dict[str, Any]) -> bool: - """ - Update cookie data to CookieCloud. - - :param cookie: cookie value to update, if this cookie does not contain 'cookie_data' key, it will be added into 'cookie_data'. - :return: if update success, return True, else return False. - """ - if 'cookie_data' not in cookie: - cookie = {'cookie_data': cookie} - raw_data = json.dumps(cookie) - encrypted_data = self.__encrypt(raw_data.encode('utf-8'), self.__get_the_key().encode('utf-8')).decode('utf-8') - cookie_cloud_request = requests.post(urljoin(settings.COOKIECLOUD_HOST, '/update'), - data={'uuid': settings.COOKIECLOUD_KEY, 'encrypted': encrypted_data}) - if cookie_cloud_request.status_code == 200: - if cookie_cloud_request.json()['action'] == 'done': - return True - return False - - def __encrypt(self, message, passphrase): - salt = Random.new().read(8) - key_iv = self.__bytes_to_key(passphrase, salt, 32 + 16) - key = key_iv[:32] - iv = key_iv[32:] - aes = AES.new(key, AES.MODE_CBC, iv) - return base64.b64encode(b"Salted__" + salt + aes.encrypt(self.__pad(message))) - - @staticmethod - def __pad(data): - BLOCK_SIZE = 16 - length = BLOCK_SIZE - (len(data) % BLOCK_SIZE) - return data + (chr(length) * length).encode() - - @staticmethod - def __bytes_to_key(data, salt, output=48): - # extended from https://gist.github.com/gsakkis/4546068 - assert len(salt) == 8, len(salt) - data += salt - key = md5(data).digest() - final_key = key - while len(final_key) < output: - key = md5(key + data).digest() - final_key += key - return final_key[:output] - - def __get_the_key(self) -> str: - """ - Get the key used to encrypt and decrypt data. - - :return: the key. - """ - md5 = hashlib.md5() - md5.update((settings.COOKIECLOUD_KEY + '-' + settings.COOKIECLOUD_PASSWORD).encode('utf-8')) - return md5.hexdigest()[:16] - def __update_config(self): self.update_config({ "enabled": self._enabled, @@ -291,4 +233,4 @@ class SyncCookieCloud(_PluginBase): self._scheduler.shutdown() self._scheduler = None except Exception as e: - logger.error("退出插件失败:%s" % str(e)) \ No newline at end of file + logger.error("退出插件失败:%s" % str(e)) diff --git a/plugins/synccookiecloud/requirements.txt b/plugins/synccookiecloud/requirements.txt new file mode 100644 index 0000000..7d390da --- /dev/null +++ b/plugins/synccookiecloud/requirements.txt @@ -0,0 +1 @@ +PyCookieCloud~=1.0.3 \ No newline at end of file