Skip to content

Commit

Permalink
v0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed May 24, 2024
1 parent e721c85 commit 7ce37b7
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- uses: ncipollo/release-action@v1
with:
artifacts: "./es5/*.js"
artifacts: "./es5/*"
8 changes: 7 additions & 1 deletion build/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
8 changes: 8 additions & 0 deletions meta/open-file-dialog.meta.lua
Original file line number Diff line number Diff line change
@@ -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==
97 changes: 45 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
"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"
]
}
9 changes: 5 additions & 4 deletions scripts.json
Original file line number Diff line number Diff line change
@@ -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"
}
"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"
}
2 changes: 1 addition & 1 deletion src/autoload.meta → src/autoload.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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==
// ==/UserScript==
16 changes: 8 additions & 8 deletions src/autoload.ts
Original file line number Diff line number Diff line change
@@ -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
})
})
autoload(updatePlaylist, getMpvPlaylist, {
image: true,
video: true,
audio: true,
});
});
2 changes: 1 addition & 1 deletion src/speed.meta → src/speed.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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==
// ==/UserScript==
54 changes: 27 additions & 27 deletions src/speed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
2 changes: 1 addition & 1 deletion src/vlc-aspect-ratio.meta → src/vlc-aspect-ratio.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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==
// ==/UserScript==
107 changes: 59 additions & 48 deletions src/vlc-aspect-ratio.ts
Original file line number Diff line number Diff line change
@@ -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)
addKeyBinding("a", "toggle_stretch", onPress);
registerEvent("file-loaded", cleanup);

0 comments on commit 7ce37b7

Please sign in to comment.