From 99ef0a8e0d1ef5fa42856bac2c67a30955008fde Mon Sep 17 00:00:00 2001 From: thsrite Date: Wed, 22 Nov 2023 11:11:14 +0800 Subject: [PATCH] =?UTF-8?q?feat=20Strm=E6=96=87=E4=BB=B6=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- icons/convert.png | Bin 0 -> 3381 bytes package.json | 9 + plugins/strmconvert/__init__.py | 322 ++++++++++++++++++++++++++++++++ plugins_record/StrmConvert.md | 22 +++ 5 files changed, 356 insertions(+), 2 deletions(-) create mode 100644 icons/convert.png create mode 100644 plugins/strmconvert/__init__.py create mode 100644 plugins_record/StrmConvert.md diff --git a/README.md b/README.md index dda27d1..cb78688 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,10 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ ### 插件新增 -- [站点数据统计 1.0](plugins_record%2FSiteStatisticNoMsg.md) +- [站点数据统计 1.0](plugins_record%2FSiteStatisticNoMsg.md) (无未读消息版本) - [站点未读消息 1.2](plugins_record%2FSiteUnreadMsg.md) -- [云盘strm生成 1.7](plugins_record%2FCloudStrm.md) +- [云盘strm生成 1.6](plugins_record%2FCloudStrm.md) +- [Strm文件模式转换 1.0](plugins_record%2FStrmConvert.md) - [清理订阅缓存 1.0](plugins_record%2FSubscribeClear.md) - [添加种子下载 1.0](plugins_record%2FDownloadTorrent.md) - [安全删除站点 1.0](plugins_record%2FSiteRemoveSafe.md) diff --git a/icons/convert.png b/icons/convert.png new file mode 100644 index 0000000000000000000000000000000000000000..5fd5a2d86cf138c4a1e3ba80a7baa5e8a3809ccc GIT binary patch literal 3381 zcmds(i8s{W|Htop7{(xD56Rn7mJ%b0vb)iW%-Ph}!*E#p`x@jlPjd=0mcmM#eF_}bR z*`9wUj)S${IaOE4GEgYR$N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I8V@hrI9q5MH=4?J|H9Zq%tciJYud`DMWg*GMjrFb2wR z4vk6!cJ#6^BDoSH!-9sIE$Wcs6McckmHGhNRM(bkdFkXv#W_2zC6kf!D#C>2C;N>3 z@WZ^lA8NS!bU`8>SGt3kR~`-F}W&0AI{Y_UD}B}I#Z+j)?y3>I_`nFO34S; za9~zG(mcZ#qML703V#$ZhMx*{06F=o4gVUfT+0i4iL`a)+WTyOqli=gtr-@YLMJyI z!yqBA3uYchAtilMy7`6netRF~3+f(Xo#UVbKCjtft~K)2doS|XQK9}g13NR2P08vn zNBt&%1WLHyQfzz>H7$>0y!0J7dul{T6)4`=POQtr$ldlSx+2%Gi^z-M?45_ov=B8o z&Fq<8E{k?vdbeu!LcNKkAIhRY+9OOq#|!FBA}z3Xe{XZh31)wP5smw8@OtqPNTiNn z&GI503HfX>8eTjQ2n)>bkVr-`+C-;q0qrk{1BIsyi0nbZqI` zV+@l1QKwn30TpWf6t#c7$u@X!a&l(Vk|CxF3FsvBcxG_45?nJ>oifuY zU8s{fZgTzmt4Q}R0XVms>rywuU+9Q&qd&y1RK$J|@k^V|dG$0f$u$$#$XP{mZyUoQ z6i;(MP6XF7fH2OIAXv{Gb=+^Do324`|I_YwXG$q-^U$u{)IXJ~3AGwJJ@NKSo+ID= z_P834xp}(Je~r#+j8Rc&*J*Ey87LfETup$;(qUGv##6Cz?(-8gqBPTzZcr$?czkln z<_8Zdl(F2E=@pj2^cvPWdf{{U{>8QFEB`RQco{pIbMtnKq?YLVpI@y9e3v-Tt9X@v z72&QB^*CeaDq1 zgK}#Cm{sD4wqXUanN6;DV*T*#i0^7B0IkFy&i}+>bW{3cmunb6vT2&#ZwG<@n$%lT Xg;r$!5POSGz#7Je=A=3U*M$E7Ftfn4 literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 8d67116..e2c2a34 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,15 @@ "author": "thsrite", "level": 1 }, + "StrmConvert": { + "name": "Strm文件模式转换", + "description": "Strm文件内容转为本地路径或者cd2/alist API路径。", + "version": "1.0", + "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/convert.png", + "color": "#7eabf3", + "author": "thsrite", + "level": 1 + }, "SiteUnreadMsg": { "name": "站点未读消息", "description": "发送站点未读消息。", diff --git a/plugins/strmconvert/__init__.py b/plugins/strmconvert/__init__.py new file mode 100644 index 0000000..fe05f1b --- /dev/null +++ b/plugins/strmconvert/__init__.py @@ -0,0 +1,322 @@ +import re +import urllib.parse +from pathlib import Path + +from app.plugins import _PluginBase +from typing import Any, List, Dict, Tuple +from app.log import logger + + +class StrmConvert(_PluginBase): + # 插件名称 + plugin_name = "Strm文件模式转换" + # 插件描述 + plugin_desc = "Strm文件内容转为本地路径或者cd2/alist API路径。" + # 插件图标 + plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/convert.png" + # 主题色 + plugin_color = "#7eabf3" + # 插件版本 + plugin_version = "1.0" + # 插件作者 + plugin_author = "thsrite" + # 作者主页 + author_url = "https://github.com/thsrite" + # 插件配置项ID前缀 + plugin_config_prefix = "strmconvert_" + # 加载顺序 + plugin_order = 27 + # 可使用的用户级别 + auth_level = 1 + + # 私有属性 + _to_local = False + _to_api = False + _convert_confs = None + _library_path = None + _api_url = None + + def init_plugin(self, config: dict = None): + if config: + self._to_local = config.get("to_local") + self._to_api = config.get("to_api") + self._convert_confs = config.get("convert_confs") + + if self._to_local and self._to_api: + logger.error(f"本地模式和API模式同时只能开启一个") + return + + convert_confs = self._convert_confs.split("\n") + if not convert_confs: + return + + self.update_config({ + "to_local": False, + "to_api": False, + "convert_confs": self._convert_confs + }) + + if self._to_local: + self.__convert_to_local(convert_confs) + + if self._to_api: + self.__convert_to_api(convert_confs) + + def __convert_to_local(self, convert_confs: list): + """ + 转为本地模式 + """ + for convert_conf in convert_confs: + if str(convert_conf).count("#") != 1: + logger.error(f"转换配置 {convert_conf} 格式错误,已跳过处理") + continue + source_path = str(convert_conf).split("#")[0] + library_path = str(convert_conf).split("#")[1] + logger.info(f"{source_path} 开始转为本地模式") + self.__to_local(source_path, library_path) + logger.info(f"{source_path} 转换本地模式已结束") + + def __to_local(self, source_path: str, library_path: str): + files = self.__list_files(Path(source_path), ['.strm']) + for f in files: + logger.debug(f"开始处理文件 {f}") + try: + with open(f, 'r') as file: + content = file.read() + # 获取扩展名 + ext = str(content).split(".")[-1] + library_file = str(f).replace(source_path, library_path) + library_file = Path(library_file).parent.joinpath(Path(library_file).stem + "." + ext) + with open(f, 'w') as file2: + logger.debug(f"开始写入 媒体库路径 {library_file}") + file2.write(str(library_file)) + except Exception as e: + print(e) + + def __convert_to_api(self, convert_confs: list): + """ + 转为api模式 + """ + for convert_conf in convert_confs: + if str(convert_conf).count("#") != 3: + logger.error(f"转换配置 {convert_conf} 格式错误,已跳过处理") + continue + source_path = str(convert_conf).split("#")[0] + library_path = str(convert_conf).split("#")[1] + cloud_type = str(convert_conf).split("#")[2] + cloud_url = str(convert_conf).split("#")[3] + logger.info(f"{source_path} 开始转为API模式") + self.__to_api(source_path, library_path, cloud_type, cloud_url) + logger.info(f"{source_path} 转换本地模式已结束") + + def __to_api(self, source_path: str, library_path: str, cloud_type: str, cloud_url: str): + files = self.__list_files(Path(source_path), ['.strm']) + for f in files: + logger.debug(f"开始处理文件 {f}") + try: + library_file = str(f).replace(source_path, library_path) + # 对盘符之后的所有内容进行url转码 + library_file = urllib.parse.quote(library_file, safe='') + + if str(cloud_type) == "cd2": + # 将路径的开头盘符"/mnt/user/downloads"替换为"http://localhost:19798/static/http/localhost:19798/False/" + # http://192.168.31.103:19798/static/http/192.168.31.103:19798/False/%2F115%2Femby%2Fanime%2F%20%E4%B8%83%E9%BE%99%E7%8F%A0%20%281986%29%2FSeason%201.%E5%9B%BD%E8%AF%AD%2F%E4%B8%83%E9%BE%99%E7%8F%A0%20-%20S01E002%20-%201080p%20AAC%20h264.mp4 + api_file = f"http://{cloud_url}/static/http/{cloud_url}/False/{library_file}" + else: + api_file = f"http://{cloud_url}/d/{library_file}" + with open(f, 'w') as file2: + logger.debug(f"开始写入 api路径 {api_file}") + file2.write(str(api_file)) + except Exception as e: + print(e) + + @staticmethod + def __list_files(directory: Path, extensions: list, min_filesize: int = 0) -> List[Path]: + """ + 获取目录下所有指定扩展名的文件(包括子目录) + """ + if not min_filesize: + min_filesize = 0 + + if not directory.exists(): + return [] + + if directory.is_file(): + return [directory] + + if not min_filesize: + min_filesize = 0 + + files = [] + pattern = r".*(" + "|".join(extensions) + ")$" + + # 遍历目录及子目录 + for path in directory.rglob('**/*'): + if path.is_file() \ + and re.match(pattern, path.name, re.IGNORECASE) \ + and path.stat().st_size >= min_filesize * 1024 * 1024: + files.append(path) + + return files + + def get_state(self) -> bool: + return False + + @staticmethod + def get_command() -> List[Dict[str, Any]]: + pass + + def get_api(self) -> List[Dict[str, Any]]: + pass + + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: + """ + 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 + """ + return [ + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'to_local', + 'label': '转为本地模式', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'to_api', + 'label': '转为API模式', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12 + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'convert_confs', + 'label': '转换配置', + 'rows': 3, + 'placeholder': 'strm文件根路径#转换路径' + } + } + ] + }, + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '转换配置(转为本地模式):' + 'strm文件根路径#转换路径。' + '转换路径为源文件挂载进媒体服务器的路径。' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '转换配置(转为API模式):' + 'strm文件根路径#转换路径#cd2/alist#cd2/alist服务地址(ip:port)。' + '转换路径为云盘根路径。' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '配置说明:' + 'https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/plugins_record/PluginAutoUpdate.md' + } + } + ] + } + ] + } + ] + } + ], { + "to_local": False, + "to_api": False, + "convert_confs": "" + } + + def get_page(self) -> List[dict]: + pass + + def stop_service(self): + """ + 退出插件 + """ + pass diff --git a/plugins_record/StrmConvert.md b/plugins_record/StrmConvert.md new file mode 100644 index 0000000..cfff58a --- /dev/null +++ b/plugins_record/StrmConvert.md @@ -0,0 +1,22 @@ +# Strm文件模式转换 + +### 更新记录 + +- 1.0 Strm文件内容转为本地路径或者cd2/alist API路径 + +### 使用说明 + +#### 本地模式 +- MoviePilot上strm视频根路径 /mnt/link/aliyun`/tvshow/爸爸去哪儿/Season 5/14.特别版.strm` +- 云盘源文件挂载本地后 挂载`进媒体服务器的路径`,与上方对应 /mount/cloud/aliyun/emby`/tvshow/爸爸去哪儿/Season 5/14.特别版.mp4` + +- 转换配置为:`/mnt/link/aliyun#/mount/cloud/aliyun/emby` + +#### API模式 +- MoviePilot上strm视频根路径 /mnt/link/aliyun`/tvshow/爸爸去哪儿/Season 5/14.特别版.strm` +- cd2挂载后路径 /aliyun/emby`/tvshow/爸爸去哪儿/Season 5/14.特别版.mp4` + +- 转换配置为:`/mnt/link/aliyun#/aliyun/emby#cd2#192.168.31.103:19798` + + +## 具体自己多尝试吧。 \ No newline at end of file