mirror of
https://github.com/thsrite/MoviePilot-Plugins.git
synced 2026-03-27 10:05:57 +00:00
feat Strm文件模式转换插件
This commit is contained in:
@@ -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)
|
||||
|
||||
BIN
icons/convert.png
Normal file
BIN
icons/convert.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -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": "发送站点未读消息。",
|
||||
|
||||
322
plugins/strmconvert/__init__.py
Normal file
322
plugins/strmconvert/__init__.py
Normal file
@@ -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
|
||||
22
plugins_record/StrmConvert.md
Normal file
22
plugins_record/StrmConvert.md
Normal file
@@ -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`
|
||||
|
||||
|
||||
## 具体自己多尝试吧。
|
||||
Reference in New Issue
Block a user