From 77e2c4681a849c08e8b183b309ea17ec4dac17af Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 18 Nov 2024 12:10:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=94=AF=E6=8C=81=E8=A7=A3=E7=A0=81URL?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=86=99=E5=85=A5Strm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 3 +- plugins.v2/strmredirect/__init__.py | 76 ++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/package.v2.json b/package.v2.json index b0c8026..edc70ac 100644 --- a/package.v2.json +++ b/package.v2.json @@ -429,12 +429,13 @@ "name": "Strm重定向", "description": "重写Strm文件内容。", "labels": "云盘", - "version": "1.0", + "version": "1.1", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlinkredirect.png", "author": "thsrite", "level": 1, "v2": true, "history": { + "v1.1": "支持解码URL重新写入Strm", "v1.0": "重写Strm文件内容" } }, diff --git a/plugins.v2/strmredirect/__init__.py b/plugins.v2/strmredirect/__init__.py index 08c440b..d3eb3b2 100644 --- a/plugins.v2/strmredirect/__init__.py +++ b/plugins.v2/strmredirect/__init__.py @@ -3,6 +3,7 @@ import re import urllib.parse from pathlib import Path from typing import List, Tuple, Dict, Any + from app.log import logger from app.plugins import _PluginBase @@ -15,7 +16,7 @@ class StrmRedirect(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlinkredirect.png" # 插件版本 - plugin_version = "1.0" + plugin_version = "1.1" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -29,6 +30,7 @@ class StrmRedirect(_PluginBase): # 私有属性 _onlyonce = False + _unquote = False _strm_path = None _origin_path = None _redirect_path = None @@ -37,6 +39,7 @@ class StrmRedirect(_PluginBase): # 读取配置 if config: self._onlyonce = config.get("onlyonce") + self._unquote = config.get("unquote") self._strm_path = config.get("strm_path") self._origin_path = config.get("origin_path") self._redirect_path = config.get("redirect_path") @@ -48,6 +51,7 @@ class StrmRedirect(_PluginBase): self._onlyonce = False self.update_config({ "onlyonce": self._onlyonce, + "unquote": self._unquote, "strm_path": self._strm_path, "origin_path": self._origin_path, "redirect_path": self._redirect_path @@ -69,20 +73,28 @@ class StrmRedirect(_PluginBase): unencoded = self.find_unencoded_parts(strm_content) # 解码url unercoded_strm_content = urllib.parse.unquote(strm_content) - if str(unercoded_strm_content).startswith(target_from): - strm_content = unercoded_strm_content.replace(target_from, target_to) - no_encoded = unencoded[0] - encoded = strm_content.replace(no_encoded, "") - encoded = urllib.parse.quote(encoded) - strm_content = no_encoded + encoded + if target_from and target_to: + if str(unercoded_strm_content).startswith(target_from): + strm_content = unercoded_strm_content.replace(target_from, target_to) + no_encoded = unencoded[0] + encoded = strm_content.replace(no_encoded, "") + # encoded = urllib.parse.quote(encoded) + strm_content = no_encoded + encoded - # 如果不是url,不进行编码 - if not str(strm_content).startswith("http"): - strm_content = urllib.parse.unquote(strm_content) + # 如果不是url,不进行编码 + if not str(strm_content).startswith("http"): + strm_content = urllib.parse.unquote(strm_content) + with open(str(file_path), 'w', encoding='utf-8') as file: + file.write(strm_content) + logger.info( + f"Updated Strm: {unercoded_strm_content} -> {strm_content} success") + elif self._unquote: with open(str(file_path), 'w', encoding='utf-8') as file: - file.write(strm_content) - logger.info( - f"Updated Strm: {unercoded_strm_content} -> {strm_content} success") + file.write(unercoded_strm_content) + logger.info(f"Unquote Strm: {strm_content} -> {unercoded_strm_content} success") + else: + logger.info(f"No target_from or target_to or unquote, stop update") + return @staticmethod def find_unencoded_parts(input_string: str): @@ -157,6 +169,22 @@ class StrmRedirect(_PluginBase): } } ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 3 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'unquote', + 'label': '解码URL', + } + } + ] } ] }, @@ -240,11 +268,33 @@ class StrmRedirect(_PluginBase): ] } ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '如想解码Strm中的url路径,仅需勾选解码URL和填写strm路径即可。' + } + } + ] + } + ] } ] } ], { "onlyonce": False, + "unquote": False, "strm_path": "", "origin_path": "", "redirect_path": "",