mirror of
https://github.com/alantang1977/X.git
synced 2024-12-29 11:33:09 +02:00
1 line
19 KiB
JavaScript
1 line
19 KiB
JavaScript
|
import{sortListByCN}from"./sortName.js";import{pdfa,pdfh}from"./pdf.js";import{_}from"assets://js/lib/cat.js";import{findBestLCS}from"./lib/similarity.js";String.prototype.rstrip=function(chars){chars=new RegExp(chars+"$");return this.replace(chars,"")};let key="xiaoya",url="https://xy.omii.link/",device={},siteKey="",siteType=0;var showMode="single",searchDriver="",limit_search_show=200,search_type="",detail_order="name";const request_timeout=5e3,VERSION="xiaoya_open v2/v3 20230721";function print(any){}const http=async function(url,options={}){"POST"===options.method&&options.data&&(options.body=JSON.stringify(options.data),options.headers=Object.assign({"content-type":"application/json"},options.headers),options.headers=Object.assign({Authorization:"alist-09ceb38a-f143-47f7-b255-c3eec819cd7b0lSmqjgBRIMJakAkbJIE2KzO6h2CUVBuEkqrLiA5cJJzOzYxJtCTIGBXXnhrg7Av"},options.headers)),options.timeout=request_timeout;try{const res=await req(url,options);return res.json=()=>res&&res.content?JSON.parse(res.content):null,res.text=()=>res&&res.content?res.content:"",res}catch(e){return{json(){return null},text(){return""}}}},__drives=(["get","post"].forEach(method=>{http[method]=function(url,options={}){return http(url,Object.assign(options,{method:method.toUpperCase()}))}}),{}),__subtitle_cache={};function isMedia(file){return/\.(dff|dsf|mp3|aac|wav|wma|cda|flac|m4a|mid|mka|mp2|mpa|mpc|ape|ofr|ogg|ra|wv|tta|ac3|dts|tak|webm|wmv|mpeg|mov|ram|swf|mp4|avi|rm|rmvb|flv|mpg|mkv|m3u8|ts|3gp|asf)$/.test(file.toLowerCase())}async function get_drives_path(tid){var index=tid.indexOf("$"),name=tid.substring(0,index),tid=tid.substring(index+1);return{drives:await get_drives(name),path:tid}}async function get_drives(name){var{settings,api,server}=__drives[name];return null==settings.v3&&(settings.v3=!1,server=(await http.get(server+"/api/public/settings")).json().data,Array.isArray(server)?(settings.title=server.find(x=>"title"===x.key)?.value,settings.v3=!1,settings.version=server.find(x=>"version"===x.key)?.value,settings.enableSearch="true"===server.find(x=>"enable search"===x.key)?.value):(settings.title=server.title,settings.v3=!0,settings.version=server.version,settings.enableSearch=!1),api.path=settings.v3?"/api/fs/list":"/api/public/path",api.file=settings.v3?"/api/fs/get":"/api/public/path",api.search=(settings.v3,"/api/public/search"),api.other=settings.v3?"/api/fs/other":null),__drives[name]}async function init(cfg){console.log("当前版本号:"+VERSION);let data;var alist_data,alist_data_url,ext=url+"/tvbox/json/alist_open.json";"object"==typeof ext?(data=ext,print("alist ext:object")):"string"==typeof ext&&(data=ext.startsWith("http")?(alist_data_url=(alist_data=ext.split(";"))[0],limit_search_show=1<alist_data.length&&Number(alist_data[1])||limit_search_show,search_type=2<alist_data.length?alist_data[2]:search_type,print(alist_data_url),(await http.get(alist_data_url)).json()):(print("alist ext:json string"),JSON.parse(ext)));let drives=[];Array.isArray(data)&&0<data.length&&data[0].hasOwnProperty("server")&&data[0].hasOwnProperty("name")?drives=data:!Array.isArray(data)&&data.hasOwnProperty("drives")&&Array.isArray(data.drives)&&(drives=data.drives.filter(it=>it.type&&"alist"===it.type||!it.type)),print(drives),print(searchDriver=!(searchDriver=(drives.find(x=>x.search)||{}).name||"")&&0<drives.length?drives[0].name:searchDriver),drives.forEach(item=>{let _path_param=[];item.params&&(_path_param=Object.keys(item.params)).sort((a,b)=>a.length-b.length),__drives[item.name]={name:item.name,server:item.server.endsWith("/")?item.server.rstrip("/"):item.server,startPage:item.startPage||"/",showAll:!0===item.showAll,search:!!item.search,params:item.params||{},_path_param:_path_param,settings:{},api:{},getParams(path){var key=this._path_param.find(x=>path.startsWith(x));return Object.assign({},this.params[key],{path:path})},async getPath(path){path=(await http.post(this.server+this.api.path,{data:this.getParams(path)})).json();return this.settings.v3?path.data.content:path.data.files},async getFile(path){path=(await http.post(this.server
|