-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"semicolons": "asNeeded" | ||
} | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "space", | ||
"indentWidth": 2 | ||
}, | ||
"files": { | ||
"ignore": [ | ||
"*.sh", | ||
"target", | ||
"output", | ||
"*.stackdump", | ||
"*.ps1", | ||
"*.yaml", | ||
"*.js", | ||
"./mpv-*/dist/**", | ||
"./mpv-*/es/**", | ||
"node_modules", | ||
".vscode", | ||
".github", | ||
"./common", | ||
"./coverage", | ||
"./html", | ||
"CHANGELOG.json" | ||
] | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"style": { | ||
"noNonNullAssertion": "off", | ||
"noParameterAssign": "off" | ||
}, | ||
"complexity": { | ||
"noBannedTypes": "off" | ||
}, | ||
"suspicious": { | ||
"noArrayIndexKey": "off", | ||
"noRedeclare": "off", | ||
"noUnsafeDeclarationMerging": "off", | ||
"noExplicitAny": "off", | ||
"noImplicitAnyLet": "off", | ||
"noFallthroughSwitchClause": "off", | ||
"noAssignInExpressions": "off" | ||
}, | ||
"correctness": { | ||
"useExhaustiveDependencies": "off" | ||
}, | ||
"recommended": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// ==UserScript== | ||
// @name autoload-sub | ||
// @version 0.1.1 | ||
// @description Automatically load sub files | ||
// @author mpv-easy | ||
// @downloadURL https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload-sub.js | ||
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import "@mpv-easy/polyfill"; | ||
import { | ||
isHttp, | ||
fetch, | ||
SubtitleTypes, | ||
getenv, | ||
getFileName, | ||
joinPath, | ||
writeFile, | ||
commandv, | ||
getPropertyNative, | ||
type TrackItem, | ||
existsSync, | ||
observeProperty, | ||
getProperty, | ||
registerEvent, | ||
mkdir, | ||
} from "@mpv-easy/tool"; | ||
|
||
registerEvent("file-loaded", autoloadSub); | ||
observeProperty("path", "string", autoloadSub); | ||
registerEvent("start-file", autoloadSub); | ||
|
||
export function autoloadSub() { | ||
const path = getProperty("path"); | ||
if (!path?.length) { | ||
return; | ||
} | ||
|
||
const trackList = (getPropertyNative<TrackItem[]>("track-list") || []).filter( | ||
(i) => i.type === "sub", | ||
); | ||
if (isHttp(path)) { | ||
const list = SubtitleTypes.map((i) => { | ||
const s = path.split(".").slice(0, -1); | ||
s.push(i); | ||
return s.join("."); | ||
}); | ||
const tmp = getenv("TMPDIR") || getenv("TMP") || getenv("tmp") || "./"; | ||
for (const url of list) { | ||
const name = getFileName(url); | ||
if (!name?.length) { | ||
continue; | ||
} | ||
|
||
if (trackList.find((i) => i.title === name)) { | ||
continue; | ||
} | ||
|
||
try { | ||
const resp = fetch(url); | ||
|
||
if (resp.status !== 200 || !resp.text?.length) { | ||
continue; | ||
} | ||
|
||
const subPath = joinPath(tmp, name); | ||
writeFile(subPath, resp.text); | ||
commandv("sub-add", subPath); | ||
} catch (e) { | ||
mkdir("./aaaa"); | ||
} | ||
} | ||
} else { | ||
const list = SubtitleTypes.map((i) => { | ||
const s = path.split(".").slice(0, -1); | ||
s.push(i); | ||
return s.join("."); | ||
}); | ||
for (const url of list) { | ||
const name = getFileName(url); | ||
if (trackList.find((i) => i.title === name)) { | ||
continue; | ||
} | ||
if (existsSync(url)) { | ||
commandv("sub-add", url); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters