From 7ce37b70ade672dec144d17dada62a89a0744c8f Mon Sep 17 00:00:00 2001 From: ahaoboy <504595380@qq.com> Date: Fri, 24 May 2024 11:38:08 +0800 Subject: [PATCH] v0.1.5 --- .github/workflows/release.yml | 2 +- build/meta.ts | 8 +- meta/open-file-dialog.meta.lua | 8 ++ package.json | 97 ++++++++-------- scripts.json | 9 +- src/{autoload.meta => autoload.meta.js} | 2 +- src/autoload.ts | 16 +-- src/{speed.meta => speed.meta.js} | 2 +- src/speed.ts | 54 ++++----- ...ct-ratio.meta => vlc-aspect-ratio.meta.js} | 2 +- src/vlc-aspect-ratio.ts | 107 ++++++++++-------- 11 files changed, 163 insertions(+), 144 deletions(-) create mode 100644 meta/open-file-dialog.meta.lua rename src/{autoload.meta => autoload.meta.js} (92%) rename src/{speed.meta => speed.meta.js} (92%) rename src/{vlc-aspect-ratio.meta => vlc-aspect-ratio.meta.js} (93%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f08e57..e04cf9f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,4 +23,4 @@ jobs: - uses: ncipollo/release-action@v1 with: - artifacts: "./es5/*.js" + artifacts: "./es5/*" diff --git a/build/meta.ts b/build/meta.ts index 9ee503e..657268d 100644 --- a/build/meta.ts +++ b/build/meta.ts @@ -3,10 +3,16 @@ import { join } from "node:path"; const files = readdirSync("./es5"); for (const name of files) { - const metaPath = join("./src", name.replace(".js", ".meta")); + const metaPath = join("./src", name.replace(".js", ".meta.js")); const jsPath = join("./es5", name); const meta = readFileSync(metaPath, "utf8"); const js = readFileSync(jsPath, "utf8"); writeFileSync(jsPath, [meta, js].join("\n\n")); } + +for (const name of readdirSync("./meta")) { + const outPath = join("./es5", name); + const srcPath = join("./meta", name); + writeFileSync(outPath, readFileSync(srcPath)); +} diff --git a/meta/open-file-dialog.meta.lua b/meta/open-file-dialog.meta.lua new file mode 100644 index 0000000..11fc533 --- /dev/null +++ b/meta/open-file-dialog.meta.lua @@ -0,0 +1,8 @@ +-- ==UserScript== +-- @name open-file-dialog +-- @version 0.1.0 +-- @description open-file-dialog is a script for mpv that can launch a regular Windows file open dialog from a key binding (default: Ctrl+O.) +-- @author mpv-easy +-- @downloadURL https://raw.githubusercontent.com/rossy/mpv-open-file-dialog/master/open-file-dialog.lua +-- @updateURL https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/open-file-dialog.meta.lua +-- ==/UserScript== \ No newline at end of file diff --git a/package.json b/package.json index 0c93db8..b760e90 100644 --- a/package.json +++ b/package.json @@ -1,53 +1,46 @@ { - "name": "@mpv-easy/mpsm-scripts", - "private": true, - "version": "0.1.4", - "files": [ - "bin", - "dist", - "es5", - "bundle", - "readme.md", - "package.json" - ], - "description": "@mpv-easy/mpsm-scripts", - "main": "./dist/index.js", - "bin": "./bin/cli", - "types": "./dist/index.d.ts", - "scripts": { - "bundle": "esbuild ./src/*.ts --bundle --outdir=./bundle", - "meta": "tsx ./build/meta.ts", - "build": "pnpm run bundle && pnpm run es5 && pnpm run meta", - "dev": "chokidar \"./src/*.(ts|tsx|json)\" -c \"pnpm run build && pnpm run copy\" -t 3000 --initial", - "copy": "cp -r ./es5/*.js $MPV_SCRIPT_DIR/", - "es5": "babel --presets @babel/preset-env ./bundle -d es5 --plugins ./babel/hack.js", - "lint": "biome check --apply-unsafe ./", - "format": "biome format --write ./" - }, - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "@babel/cli": "^7.23.9", - "@babel/core": "^7.23.9", - "@babel/preset-env": "^7.23.9", - "@babel/preset-typescript": "^7.23.3", - "@biomejs/biome": "^1.5.3", - "@mpv-easy/autoload": "0.1.6-alpha.7", - "@mpv-easy/plugin": "^0.1.5", - "@mpv-easy/tool": "^0.1.5", - "@types/node": "^20.12.12", - "chokidar": "^3.6.0", - "chokidar-cli": "^3.0.0", - "esbuild": "^0.21.3", - "tsx": "^4.10.5", - "typescript": "^5.3.3" - }, - "browserslist": [ - "iOS >= 9", - "Android >= 4.4", - "last 2 versions", - "> 0.2%", - "not dead" - ] -} \ No newline at end of file + "name": "@mpv-easy/mpsm-scripts", + "private": true, + "version": "0.1.5", + "files": ["bin", "dist", "es5", "bundle", "readme.md", "package.json"], + "description": "@mpv-easy/mpsm-scripts", + "main": "./dist/index.js", + "bin": "./bin/cli", + "types": "./dist/index.d.ts", + "scripts": { + "bundle": "esbuild ./src/*.ts --bundle --outdir=./bundle", + "meta": "tsx ./build/meta.ts", + "build": "pnpm run bundle && pnpm run es5 && pnpm run meta", + "dev": "chokidar \"./src/*.(ts|tsx|json)\" -c \"pnpm run build && pnpm run copy\" -t 3000 --initial", + "copy": "cp -r ./es5/*.js $MPV_SCRIPT_DIR/", + "es5": "babel --presets @babel/preset-env ./bundle -d es5 --plugins ./babel/hack.js", + "lint": "biome check --apply-unsafe ./", + "format": "biome format --write ./" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@babel/cli": "^7.23.9", + "@babel/core": "^7.23.9", + "@babel/preset-env": "^7.23.9", + "@babel/preset-typescript": "^7.23.3", + "@biomejs/biome": "^1.5.3", + "@mpv-easy/autoload": "0.1.6-alpha.7", + "@mpv-easy/plugin": "^0.1.5", + "@mpv-easy/tool": "^0.1.5", + "@types/node": "^20.12.12", + "chokidar": "^3.6.0", + "chokidar-cli": "^3.0.0", + "esbuild": "^0.21.3", + "tsx": "^4.10.5", + "typescript": "^5.3.3" + }, + "browserslist": [ + "iOS >= 9", + "Android >= 4.4", + "last 2 versions", + "> 0.2%", + "not dead" + ] +} diff --git a/scripts.json b/scripts.json index 66a7e28..6bd38d5 100644 --- a/scripts.json +++ b/scripts.json @@ -1,5 +1,6 @@ { - "autoload": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload.js", - "speed": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/speed.js", - "vlc-aspect-ratio": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/vlc-aspect-ratio.js" -} \ No newline at end of file + "autoload": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload.js", + "speed": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/speed.js", + "open-file-dialog": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/open-file-dialog.meta.lua", + "vlc-aspect-ratio": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/vlc-aspect-ratio.js" +} diff --git a/src/autoload.meta b/src/autoload.meta.js similarity index 92% rename from src/autoload.meta rename to src/autoload.meta.js index ba9244d..517711c 100644 --- a/src/autoload.meta +++ b/src/autoload.meta.js @@ -4,4 +4,4 @@ // @description Automatically load playable files // @author mpv-easy // @downloadURL https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload.js -// ==/UserScript== \ No newline at end of file +// ==/UserScript== diff --git a/src/autoload.ts b/src/autoload.ts index d430cca..7ba7900 100644 --- a/src/autoload.ts +++ b/src/autoload.ts @@ -1,10 +1,10 @@ -import { autoload } from "@mpv-easy/autoload" -import { updatePlaylist, getMpvPlaylist, registerEvent } from "@mpv-easy/tool" +import { autoload } from "@mpv-easy/autoload"; +import { updatePlaylist, getMpvPlaylist, registerEvent } from "@mpv-easy/tool"; registerEvent("start-file", () => { - autoload(updatePlaylist, getMpvPlaylist, { - image: true, - video: true, - audio: true - }) -}) \ No newline at end of file + autoload(updatePlaylist, getMpvPlaylist, { + image: true, + video: true, + audio: true, + }); +}); diff --git a/src/speed.meta b/src/speed.meta.js similarity index 92% rename from src/speed.meta rename to src/speed.meta.js index 425f353..02978f7 100644 --- a/src/speed.meta +++ b/src/speed.meta.js @@ -4,4 +4,4 @@ // @description Speed ​​up the video by pressing the mouse // @author mpv-easy // @downloadURL https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/speed.js -// ==/UserScript== \ No newline at end of file +// ==/UserScript== diff --git a/src/speed.ts b/src/speed.ts index b4f5317..9056364 100644 --- a/src/speed.ts +++ b/src/speed.ts @@ -4,34 +4,34 @@ const speed = new PropertyNumber("speed"); let mpvSpeed = speed.value; let handle = 0; -const delay = 200 +const delay = 200; addKeyBinding( - "MOUSE_BTN0", - "MPV_EASY_SPEED", - ({ event }) => { - switch (event) { - case "down": { - mpvSpeed = speed.value + "MOUSE_BTN0", + "MPV_EASY_SPEED", + ({ event }) => { + switch (event) { + case "down": { + mpvSpeed = speed.value; - handle = +setTimeout(() => { - speed.value = mpvSpeed * 2; - }, delay); + handle = +setTimeout(() => { + speed.value = mpvSpeed * 2; + }, delay); - break; - } - case "up": { - speed.value = mpvSpeed - clearTimeout(handle) - break; - } - case "press": { - break; - } - } - }, - { - complex: true, - repeatable: true, - forced: false, - }, + break; + } + case "up": { + speed.value = mpvSpeed; + clearTimeout(handle); + break; + } + case "press": { + break; + } + } + }, + { + complex: true, + repeatable: true, + forced: false, + }, ); diff --git a/src/vlc-aspect-ratio.meta b/src/vlc-aspect-ratio.meta.js similarity index 93% rename from src/vlc-aspect-ratio.meta rename to src/vlc-aspect-ratio.meta.js index f79f196..59ce147 100644 --- a/src/vlc-aspect-ratio.meta +++ b/src/vlc-aspect-ratio.meta.js @@ -4,4 +4,4 @@ // @description vlc style aspect ratio stretch for mpv // @author mpv-easy // @downloadURL https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/vlc-aspect-ratio.js -// ==/UserScript== \ No newline at end of file +// ==/UserScript== diff --git a/src/vlc-aspect-ratio.ts b/src/vlc-aspect-ratio.ts index b865f6d..4f6236d 100644 --- a/src/vlc-aspect-ratio.ts +++ b/src/vlc-aspect-ratio.ts @@ -1,60 +1,71 @@ -import { print, addKeyBinding, getPropertyNative, info, osdMessage, setProperty, setPropertyString, registerEvent, } from '@mpv-easy/tool' +import { + print, + addKeyBinding, + getPropertyNative, + info, + osdMessage, + setProperty, + setPropertyString, + registerEvent, +} from "@mpv-easy/tool"; let arOption = 0; function hasVideo() { - const trackList = getPropertyNative<{ type: string, selected: boolean, albumart: string }[]>("track-list"); - for (const i of trackList) { - if (i.type === 'video' && i.selected) { - return !i.albumart - } - } - return + const trackList = + getPropertyNative<{ type: string; selected: boolean; albumart: string }[]>( + "track-list", + ); + for (const i of trackList) { + if (i.type === "video" && i.selected) { + return !i.albumart; + } + } + return; } function onPress() { - if (!hasVideo()) { - return - } - - let arText = ''; - arOption = (arOption + 1) % 10; - - const ar = [ - -1, - "16:9", - "4:3", - "1:1", - "16:10", - "2.21:1", - "2.35:1", - "2.39:1", - "5:4", - 0 - ][arOption] - - if (typeof ar === 'number') { - if (ar === 0) { - arText = "Force PAR 1:1" - } else if (ar === -1) { - arText = "Default" - } - } else { - arText = ar.toString() - } - - - info(`Aspect Ratio: ${arText}`) - osdMessage(`Aspect Ratio: ${arText}`) - setPropertyString("video-aspect-override", ar.toString()) + if (!hasVideo()) { + return; + } + + let arText = ""; + arOption = (arOption + 1) % 10; + + const ar = [ + -1, + "16:9", + "4:3", + "1:1", + "16:10", + "2.21:1", + "2.35:1", + "2.39:1", + "5:4", + 0, + ][arOption]; + + if (typeof ar === "number") { + if (ar === 0) { + arText = "Force PAR 1:1"; + } else if (ar === -1) { + arText = "Default"; + } + } else { + arText = ar.toString(); + } + + info(`Aspect Ratio: ${arText}`); + osdMessage(`Aspect Ratio: ${arText}`); + setPropertyString("video-aspect-override", ar.toString()); } function cleanup() { - print("Cleanup") - arOption = 0 - setPropertyString("video-aspect-override", '-1') - return true + print("Cleanup"); + arOption = 0; + setPropertyString("video-aspect-override", "-1"); + return true; } -addKeyBinding("a", "toggle_stretch", onPress) -registerEvent("file-loaded", cleanup) \ No newline at end of file +addKeyBinding("a", "toggle_stretch", onPress); +registerEvent("file-loaded", cleanup);