mirror of
https://github.com/yt-dlp/ejs.git
synced 2026-06-25 07:41:58 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
508dddae12 | ||
|
|
32e6af5fb2 | ||
|
|
e0560ee403 | ||
|
|
b57ce18965 | ||
|
|
52a4f9d19a | ||
|
|
5d7bf090bb | ||
|
|
6a73fa37ba | ||
|
|
bf12d399b2 | ||
|
|
c9bbdcb445 | ||
|
|
4d0d39eca4 | ||
|
|
398f81bbed |
365
.github/workflows/ci.yml
vendored
Normal file
365
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
name: CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- 'LICENSE'
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- 'LICENSE'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ci-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ruff-format:
|
||||||
|
name: Ruff format check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
args: "check --output-format github"
|
||||||
|
|
||||||
|
ruff-lint:
|
||||||
|
name: Ruff linting check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
args: "format --check --diff"
|
||||||
|
|
||||||
|
prettier:
|
||||||
|
name: Prettier check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Deno v2.x (latest)
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: v2.x
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Run Prettier check
|
||||||
|
run: |
|
||||||
|
deno task fmt:check
|
||||||
|
|
||||||
|
eslint:
|
||||||
|
name: ESLint check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Deno v2.x (latest)
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: v2.x
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Run ESLint check
|
||||||
|
run: |
|
||||||
|
deno task lint
|
||||||
|
|
||||||
|
python_tests:
|
||||||
|
name: Python tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', pypy-3.11]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Deno v2.x (latest)
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: v2.x
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v6
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Build project
|
||||||
|
run: |
|
||||||
|
# `pip install -e` omits the force-included JS, so use `build` instead
|
||||||
|
python -m pip install -U build
|
||||||
|
python -m build
|
||||||
|
unzip -u dist/yt_dlp_ejs-*.whl "yt_dlp_ejs/*"
|
||||||
|
- name: Run Python tests
|
||||||
|
timeout-minutes: 5
|
||||||
|
run: |
|
||||||
|
python -Werror -m unittest
|
||||||
|
|
||||||
|
prepare:
|
||||||
|
name: Prepare JS runtime tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Deno v2.x (latest)
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: v2.x
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Build control bundle
|
||||||
|
run: |
|
||||||
|
deno task bundle
|
||||||
|
- name: Generate bundle hashes
|
||||||
|
run: |
|
||||||
|
pushd dist
|
||||||
|
sha256sum -- yt.solver.*.js | tee SHA2-256SUMS
|
||||||
|
popd
|
||||||
|
- name: Upload bundle hashes
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: bundle-hashes
|
||||||
|
path: |
|
||||||
|
dist/SHA2-256SUMS
|
||||||
|
compression-level: 0
|
||||||
|
- name: Cache player JS files
|
||||||
|
uses: actions/cache@v4
|
||||||
|
env:
|
||||||
|
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
src/yt/solver/test/players
|
||||||
|
key: test-player-js-${{ hashFiles('src/yt/solver/test/tests.ts') }}
|
||||||
|
- name: Download player JS files
|
||||||
|
run: |
|
||||||
|
deno run \
|
||||||
|
--no-prompt \
|
||||||
|
--allow-read=src/yt/solver/test/players/ \
|
||||||
|
--allow-write=src/yt/solver/test/players/ \
|
||||||
|
--allow-net=www.youtube.com \
|
||||||
|
--allow-sys=uid \
|
||||||
|
src/yt/solver/test/download.ts
|
||||||
|
- name: Upload player JS artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: player-js
|
||||||
|
path: |
|
||||||
|
src/yt/solver/test/players/*
|
||||||
|
compression-level: 0
|
||||||
|
|
||||||
|
deno_build:
|
||||||
|
name: Test Deno build
|
||||||
|
needs: [prepare]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Deno
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: "2.0.0" # minimum supported version
|
||||||
|
- uses: actions/setup-python@v6
|
||||||
|
with:
|
||||||
|
python-version: "3.10" # minimum supported version
|
||||||
|
- name: Install Python requirements
|
||||||
|
run: |
|
||||||
|
python -m pip install -U build
|
||||||
|
- name: Test Deno build
|
||||||
|
run: |
|
||||||
|
python -m build
|
||||||
|
- name: Verify artifact contents
|
||||||
|
run: |
|
||||||
|
tar -tvzf dist/yt_dlp_ejs-*.tar.gz
|
||||||
|
unzip -l dist/yt_dlp_ejs-*.whl | tee .wheel_contents
|
||||||
|
grep -q 'yt_dlp_ejs/yt/solver/core\.min\.js' .wheel_contents
|
||||||
|
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Bundle with Deno
|
||||||
|
run: |
|
||||||
|
deno task bundle
|
||||||
|
- name: Download bundle hashes
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
path: dist
|
||||||
|
name: bundle-hashes
|
||||||
|
- name: Verify bundle hashes
|
||||||
|
run: |
|
||||||
|
cd dist
|
||||||
|
sha256sum -c SHA2-256SUMS
|
||||||
|
|
||||||
|
deno_tests:
|
||||||
|
name: Run Deno tests
|
||||||
|
needs: [prepare]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Deno
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: "2.0.0" # minimum supported version
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Download player JS artifact
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
path: src/yt/solver/test/players
|
||||||
|
name: player-js
|
||||||
|
- name: Run Deno tests
|
||||||
|
run: |
|
||||||
|
deno test \
|
||||||
|
--no-prompt \
|
||||||
|
--allow-read=src/yt/solver/test/players/
|
||||||
|
|
||||||
|
bun_build:
|
||||||
|
name: Test Bun build
|
||||||
|
needs: [prepare]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: "1.0.31" # minimum supported version
|
||||||
|
- uses: actions/setup-python@v6
|
||||||
|
with:
|
||||||
|
python-version: "3.10" # minimum supported version
|
||||||
|
- name: Install Python requirements
|
||||||
|
run: |
|
||||||
|
python -m pip install -U build
|
||||||
|
- name: Test Bun build
|
||||||
|
run: |
|
||||||
|
python -m build
|
||||||
|
- name: Verify artifact contents
|
||||||
|
run: |
|
||||||
|
tar -tvzf dist/yt_dlp_ejs-*.tar.gz
|
||||||
|
unzip -l dist/yt_dlp_ejs-*.whl | tee .wheel_contents
|
||||||
|
grep -q 'yt_dlp_ejs/yt/solver/core\.min\.js' .wheel_contents
|
||||||
|
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||||
|
- name: Install Bun requirements
|
||||||
|
run: |
|
||||||
|
bun install
|
||||||
|
- name: Bundle with Bun
|
||||||
|
run: |
|
||||||
|
bun --bun run bundle
|
||||||
|
- name: Download bundle hashes
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
path: dist
|
||||||
|
name: bundle-hashes
|
||||||
|
- name: Verify bundle hashes
|
||||||
|
run: |
|
||||||
|
cd dist
|
||||||
|
sha256sum -c SHA2-256SUMS
|
||||||
|
|
||||||
|
bun_tests:
|
||||||
|
name: Run Bun tests
|
||||||
|
needs: [prepare]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: "1.2.11" # XXX: We support 1.0.31, but test suite requires 1.2.11+
|
||||||
|
- name: Install Bun requirements
|
||||||
|
run: |
|
||||||
|
bun install
|
||||||
|
- name: Download player JS artifact
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
path: src/yt/solver/test/players
|
||||||
|
name: player-js
|
||||||
|
- name: Run Bun tests
|
||||||
|
run: |
|
||||||
|
bun test
|
||||||
|
|
||||||
|
node_build:
|
||||||
|
name: Test Node build
|
||||||
|
needs: [prepare]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Node
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: "20.0" # minimum supported version
|
||||||
|
- uses: actions/setup-python@v6
|
||||||
|
with:
|
||||||
|
python-version: "3.10" # minimum supported version
|
||||||
|
- name: Install Python requirements
|
||||||
|
run: |
|
||||||
|
python -m pip install -U build
|
||||||
|
- name: Test Node build
|
||||||
|
run: |
|
||||||
|
python -m build
|
||||||
|
- name: Verify artifact contents
|
||||||
|
run: |
|
||||||
|
tar -tvzf dist/yt_dlp_ejs-*.tar.gz
|
||||||
|
unzip -l dist/yt_dlp_ejs-*.whl | tee .wheel_contents
|
||||||
|
grep -q 'yt_dlp_ejs/yt/solver/core\.min\.js' .wheel_contents
|
||||||
|
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||||
|
- name: Install Node requirements
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
- name: Bundle with Node
|
||||||
|
run: |
|
||||||
|
npm run bundle
|
||||||
|
- name: Download bundle hashes
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
path: dist
|
||||||
|
name: bundle-hashes
|
||||||
|
- name: Verify bundle hashes
|
||||||
|
run: |
|
||||||
|
cd dist
|
||||||
|
sha256sum -c SHA2-256SUMS
|
||||||
|
|
||||||
|
node_tests:
|
||||||
|
name: Run Node tests
|
||||||
|
needs: [prepare]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Node
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: "22.18" # XXX: We support 20.0, but test suite requires 22.18+
|
||||||
|
- name: Install Node requirements
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
- name: Download player JS artifact
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
path: src/yt/solver/test/players
|
||||||
|
name: player-js
|
||||||
|
- name: Run Node tests
|
||||||
|
run: |
|
||||||
|
node --test
|
||||||
|
|
||||||
|
all_passed:
|
||||||
|
needs:
|
||||||
|
- ruff-format
|
||||||
|
- ruff-lint
|
||||||
|
- prettier
|
||||||
|
- eslint
|
||||||
|
- deno_build
|
||||||
|
- deno_tests
|
||||||
|
- bun_build
|
||||||
|
- bun_tests
|
||||||
|
- node_build
|
||||||
|
- node_tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: All checks passed
|
||||||
|
run: |
|
||||||
|
echo "All checks passed!"
|
||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -88,7 +88,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
gh release create "${TAG}" \
|
gh release create "${TAG}" \
|
||||||
--title "yt-dlp-ejs ${TAG}" \
|
--title "yt-dlp-ejs ${TAG}" \
|
||||||
--notes-from-tag \
|
--generate-notes \
|
||||||
--verify-tag \
|
--verify-tag \
|
||||||
dist/yt.solver.*.js \
|
dist/yt.solver.*.js \
|
||||||
dist/yt_dlp_ejs-*.whl \
|
dist/yt_dlp_ejs-*.whl \
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@
|
|||||||
/deno.lock
|
/deno.lock
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
/.idea
|
/.idea
|
||||||
|
/.venv
|
||||||
|
|||||||
54
README.md
54
README.md
@@ -1,16 +1,13 @@
|
|||||||
# yt-dlp-ejs
|
# yt-dlp-ejs
|
||||||
|
|
||||||
> [!CAUTION]
|
|
||||||
> This is currently in development
|
|
||||||
|
|
||||||
External JavaScript for yt-dlp supporting many runtimes
|
External JavaScript for yt-dlp supporting many runtimes
|
||||||
|
|
||||||
## Manual Installation
|
## Manual Installation
|
||||||
|
|
||||||
In the yt-dlp repository, install the python package, either directly or from url:
|
Install ejs into the same environment as yt-dlp:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
pip install git+https://github.com/yt-dlp/ejs@main
|
pip install -U yt-dlp-ejs
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
@@ -18,7 +15,7 @@ pip install git+https://github.com/yt-dlp/ejs@main
|
|||||||
While this project does pin its dependencies,
|
While this project does pin its dependencies,
|
||||||
it does not use lockfiles or enforce a particular package manager.
|
it does not use lockfiles or enforce a particular package manager.
|
||||||
You may install dependencies using any compatible package manager.
|
You may install dependencies using any compatible package manager.
|
||||||
If you notice differences between different runtimes builds
|
If you notice differences between different runtimes' builds
|
||||||
please open an issue [here](<https://github.com/yt-dlp/ejs/issues/new>).
|
please open an issue [here](<https://github.com/yt-dlp/ejs/issues/new>).
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
@@ -26,13 +23,52 @@ please open an issue [here](<https://github.com/yt-dlp/ejs/issues/new>).
|
|||||||
To build the Python package you need a PEP518 compatible builder.
|
To build the Python package you need a PEP518 compatible builder.
|
||||||
The build hook will automatically invoke `deno`, `bun` or `node` as required.
|
The build hook will automatically invoke `deno`, `bun` or `node` as required.
|
||||||
|
|
||||||
Alternatively, to only build the JavaScript files you can run the `bundle` script manually.
|
Alternatively, to only build the JavaScript files you can run the `bundle` script manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Deno:
|
||||||
|
deno install
|
||||||
|
deno task bundle
|
||||||
|
|
||||||
|
# Bun:
|
||||||
|
bun install
|
||||||
|
bun --bun run bundle
|
||||||
|
|
||||||
|
# Node:
|
||||||
|
npm install
|
||||||
|
npm run bundle
|
||||||
|
```
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
First, to download the player files, run `src/yt/solver/test/download.ts`.
|
First, make sure the project's dependencies are installed and download the player JS files:
|
||||||
|
|
||||||
After running that once, use any of `deno test`, `bun test` or `node --test`.
|
```bash
|
||||||
|
# Deno:
|
||||||
|
deno install
|
||||||
|
deno run src/yt/solver/test/download.ts
|
||||||
|
|
||||||
|
# Bun:
|
||||||
|
bun install
|
||||||
|
bun --bun run src/yt/solver/test/download.ts
|
||||||
|
|
||||||
|
# Node 22.6+:
|
||||||
|
npm install
|
||||||
|
node --experimental-strip-types src/yt/solver/test/download.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
Then the tests can be run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Deno
|
||||||
|
deno test
|
||||||
|
|
||||||
|
# Bun
|
||||||
|
bun test
|
||||||
|
|
||||||
|
# Node
|
||||||
|
node --test
|
||||||
|
```
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
|
|||||||
14
eslint.config.js
Normal file
14
eslint.config.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
import { defineConfig } from "eslint/config";
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
{
|
||||||
|
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
|
||||||
|
plugins: { js },
|
||||||
|
extends: ["js/recommended"],
|
||||||
|
languageOptions: { globals: globals.node },
|
||||||
|
},
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
]);
|
||||||
@@ -2,7 +2,6 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||||
|
|
||||||
|
|
||||||
@@ -16,23 +15,28 @@ class CustomBuildHook(BuildHookInterface):
|
|||||||
|
|
||||||
elif shutil.which("bun"):
|
elif shutil.which("bun"):
|
||||||
print("Building with bun...", flush=True)
|
print("Building with bun...", flush=True)
|
||||||
subprocess.run(["bun", "install", "--frozen-lockfile"], check=True)
|
subprocess.run(["bun", "install"], check=True)
|
||||||
subprocess.run(["bun", "run", "bundle"], check=True)
|
subprocess.run(["bun", "--bun", "run", "bundle"], check=True)
|
||||||
|
|
||||||
elif shutil.which("npm"):
|
elif shutil.which("npm"):
|
||||||
print("Building with npm...", flush=True)
|
print("Building with npm...", flush=True)
|
||||||
# npm is a batch file (`npm.cmd`) on windows, which requires `shell=True`
|
# npm is a batch file (`npm.cmd`) on windows, which requires `shell=True`
|
||||||
requires_shell = os.name == "nt"
|
requires_shell = os.name == "nt"
|
||||||
subprocess.run(["npm", "ci"], check=True, shell=requires_shell)
|
subprocess.run(["npm", "install"], check=True, shell=requires_shell)
|
||||||
subprocess.run(["npm", "run", "bundle"], check=True, shell=requires_shell)
|
subprocess.run(["npm", "run", "bundle"], check=True, shell=requires_shell)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"One of 'deno', 'bun', or 'npm' could not be found. "
|
"One of 'deno', 'bun', or 'npm' could not be found. "
|
||||||
"Please install one of them to proceed with the build.")
|
"Please install one of them to proceed with the build."
|
||||||
|
)
|
||||||
|
|
||||||
build_data["force_include"]["dist/yt.solver.core.min.js"] = "yt_dlp_ejs/yt/solver/core.min.js"
|
build_data["force_include"].update(
|
||||||
build_data["force_include"]["dist/yt.solver.lib.min.js"] = "yt_dlp_ejs/yt/solver/lib.min.js"
|
{
|
||||||
|
"dist/yt.solver.core.min.js": "yt_dlp_ejs/yt/solver/core.min.js",
|
||||||
|
"dist/yt.solver.lib.min.js": "yt_dlp_ejs/yt/solver/lib.min.js",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def clean(self, versions):
|
def clean(self, versions):
|
||||||
shutil.rmtree('node_modules', ignore_errors=True)
|
shutil.rmtree("node_modules", ignore_errors=True)
|
||||||
|
|||||||
12
package.json
12
package.json
@@ -3,21 +3,27 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bundle": "rollup -c",
|
"bundle": "rollup -c",
|
||||||
"fmt": "prettier --write \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\""
|
"fmt": "prettier --write \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\" \"eslint.config.js\"",
|
||||||
|
"fmt:check": "prettier --check \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\" \"eslint.config.js\"",
|
||||||
|
"lint": "eslint src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"astring": "1.9.0",
|
"astring": "1.9.0",
|
||||||
"meriyah": "6.1.4"
|
"meriyah": "6.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "9.38.0",
|
||||||
"@rollup/plugin-node-resolve": "16.0.3",
|
"@rollup/plugin-node-resolve": "16.0.3",
|
||||||
"@rollup/plugin-sucrase": "5.0.2",
|
"@rollup/plugin-sucrase": "5.0.2",
|
||||||
"@rollup/plugin-terser": "0.4.4",
|
"@rollup/plugin-terser": "0.4.4",
|
||||||
"rollup-plugin-license": "3.6.0",
|
|
||||||
"@types/bun": "1.3.0",
|
"@types/bun": "1.3.0",
|
||||||
"@types/deno": "2.5.0",
|
"@types/deno": "2.5.0",
|
||||||
"@types/node": "24.8.1",
|
"@types/node": "24.8.1",
|
||||||
|
"eslint": "9.38.0",
|
||||||
|
"globals": "16.4.0",
|
||||||
|
"prettier": "3.6.2",
|
||||||
"rollup": "4.52.5",
|
"rollup": "4.52.5",
|
||||||
"prettier": "3.6.2"
|
"rollup-plugin-license": "3.6.0",
|
||||||
|
"typescript-eslint": "8.46.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ classifiers = [
|
|||||||
]
|
]
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"ruff>=0.14.1",
|
||||||
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Documentation = "https://github.com/yt-dlp/ejs#readme"
|
Documentation = "https://github.com/yt-dlp/ejs#readme"
|
||||||
Issues = "https://github.com/yt-dlp/ejs/issues"
|
Issues = "https://github.com/yt-dlp/ejs/issues"
|
||||||
@@ -44,7 +49,40 @@ exclude = [
|
|||||||
"/src/yt/solver/test/players/*",
|
"/src/yt/solver/test/players/*",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.hatch.build.targets.wheel]
|
||||||
|
packages = ["yt_dlp_ejs"]
|
||||||
|
|
||||||
[tool.hatch.build.hooks.vcs]
|
[tool.hatch.build.hooks.vcs]
|
||||||
version-file = "yt_dlp_ejs/_version.py"
|
version-file = "yt_dlp_ejs/_version.py"
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel.hooks.custom]
|
[tool.hatch.build.targets.wheel.hooks.custom]
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = [
|
||||||
|
"C4",
|
||||||
|
"E",
|
||||||
|
"F",
|
||||||
|
"I",
|
||||||
|
"PLC",
|
||||||
|
"PLE",
|
||||||
|
"PLW",
|
||||||
|
"PYI",
|
||||||
|
"RET",
|
||||||
|
"RUF",
|
||||||
|
"SIM",
|
||||||
|
"TD",
|
||||||
|
"TID",
|
||||||
|
"W",
|
||||||
|
]
|
||||||
|
ignore = [
|
||||||
|
"TD003",
|
||||||
|
"E402",
|
||||||
|
"E501",
|
||||||
|
"PLR09",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
force-single-line = true
|
||||||
|
|
||||||
|
[tool.ruff.lint.flake8-tidy-imports]
|
||||||
|
ban-relative-imports = "all"
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ function printHash() {
|
|||||||
for (const [fileName, assetInfo] of Object.entries(bundle)) {
|
for (const [fileName, assetInfo] of Object.entries(bundle)) {
|
||||||
if (assetInfo.code) {
|
if (assetInfo.code) {
|
||||||
try {
|
try {
|
||||||
const digest = createHash("sha3-512").update(assetInfo.code).digest("hex");
|
const digest = createHash("sha3-512")
|
||||||
|
.update(assetInfo.code)
|
||||||
|
.digest("hex");
|
||||||
console.log(`SHA3-512 for ${assetInfo.fileName}: ${digest}`);
|
console.log(`SHA3-512 for ${assetInfo.fileName}: ${digest}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Error hashing ${fileName}:`, err.message);
|
console.error(`Error hashing ${fileName}:`, err.message);
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ export function matchesStructure<T extends ESTree.Node>(
|
|||||||
// Handle `{ or: [a, b] }`
|
// Handle `{ or: [a, b] }`
|
||||||
return structure.or.some((node) => matchesStructure(obj, node));
|
return structure.or.some((node) => matchesStructure(obj, node));
|
||||||
}
|
}
|
||||||
|
if ("anykey" in structure && Array.isArray(structure.anykey)) {
|
||||||
|
// Handle `{ anykey: [a, b] }`
|
||||||
|
const haystack = Array.isArray(obj) ? obj : Object.values(obj);
|
||||||
|
return structure.anykey.every((value) =>
|
||||||
|
haystack.some((el) => matchesStructure(el, value)),
|
||||||
|
);
|
||||||
|
}
|
||||||
for (const [key, value] of Object.entries(structure)) {
|
for (const [key, value] of Object.entries(structure)) {
|
||||||
if (!matchesStructure(obj[key as keyof typeof obj], value)) {
|
if (!matchesStructure(obj[key as keyof typeof obj], value)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ export const setupNodes = parse(`
|
|||||||
if (typeof globalThis.XMLHttpRequest === "undefined") {
|
if (typeof globalThis.XMLHttpRequest === "undefined") {
|
||||||
globalThis.XMLHttpRequest = { prototype: {} };
|
globalThis.XMLHttpRequest = { prototype: {} };
|
||||||
}
|
}
|
||||||
if (typeof globalThis.window === "undefined") {
|
const window = Object.create(null);
|
||||||
globalThis.window = Object.create(null);
|
|
||||||
}
|
|
||||||
if (typeof URL === "undefined") {
|
if (typeof URL === "undefined") {
|
||||||
globalThis.window.location = {
|
window.location = {
|
||||||
hash: "",
|
hash: "",
|
||||||
host: "www.youtube.com",
|
host: "www.youtube.com",
|
||||||
hostname: "www.youtube.com",
|
hostname: "www.youtube.com",
|
||||||
@@ -22,7 +20,7 @@ if (typeof URL === "undefined") {
|
|||||||
username: "",
|
username: "",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
globalThis.window.location = new URL("https://www.youtube.com/watch?v=yt-dlp-wins");
|
window.location = new URL("https://www.youtube.com/watch?v=yt-dlp-wins");
|
||||||
}
|
}
|
||||||
if (typeof globalThis.document === "undefined") {
|
if (typeof globalThis.document === "undefined") {
|
||||||
globalThis.document = Object.create(null);
|
globalThis.document = Object.create(null);
|
||||||
|
|||||||
@@ -82,6 +82,20 @@ const identifier = {
|
|||||||
type: "FunctionDeclaration",
|
type: "FunctionDeclaration",
|
||||||
params: [{}, {}, {}],
|
params: [{}, {}, {}],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "VariableDeclaration",
|
||||||
|
declarations: {
|
||||||
|
anykey: [
|
||||||
|
{
|
||||||
|
type: "VariableDeclarator",
|
||||||
|
init: {
|
||||||
|
type: "FunctionExpression",
|
||||||
|
params: [{}, {}, {}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
@@ -93,14 +107,27 @@ export function extract(
|
|||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const block =
|
let block: ESTree.BlockStatement | undefined | null;
|
||||||
node.type === "ExpressionStatement" &&
|
if (node.type === "ExpressionStatement" &&
|
||||||
node.expression.type === "AssignmentExpression" &&
|
node.expression.type === "AssignmentExpression" &&
|
||||||
node.expression.right.type === "FunctionExpression"
|
node.expression.right.type === "FunctionExpression") {
|
||||||
? node.expression.right.body
|
block = node.expression.right.body;
|
||||||
: node.type === "FunctionDeclaration"
|
} else if (node.type === "VariableDeclaration") {
|
||||||
? node.body
|
for (const decl of node.declarations) {
|
||||||
: null;
|
if (
|
||||||
|
decl.type === "VariableDeclarator" &&
|
||||||
|
decl.init?.type === "FunctionExpression" &&
|
||||||
|
decl.init?.params.length === 3
|
||||||
|
) {
|
||||||
|
block = decl.init.body;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (node.type === "FunctionDeclaration") {
|
||||||
|
block = node.body;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const relevantExpression = block?.body.at(-2);
|
const relevantExpression = block?.body.at(-2);
|
||||||
if (!matchesStructure(relevantExpression!, logicalExpression)) {
|
if (!matchesStructure(relevantExpression!, logicalExpression)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ export async function getIO(): Promise<IO> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function _getIO(): Promise<IO> {
|
async function _getIO(): Promise<IO> {
|
||||||
if (globalThis.process?.release?.name === "node") {
|
// Old Deno requires casting to any as globalThis lacks an index signature
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
if ((globalThis as any).process?.release?.name === "node") {
|
||||||
// Assume node compatibility
|
// Assume node compatibility
|
||||||
const { access, readFile } = await import("node:fs/promises");
|
const { access, readFile } = await import("node:fs/promises");
|
||||||
const { deepStrictEqual } = await import("node:assert");
|
const { deepStrictEqual } = await import("node:assert");
|
||||||
|
|||||||
@@ -236,7 +236,9 @@ export const tests: {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// TODO: es6/tv_es6 variants currently fail
|
||||||
player: "2b83d2e0",
|
player: "2b83d2e0",
|
||||||
|
variants: ["main", "tcc", "tce", "es5", "tv", "phone", "tablet"],
|
||||||
n: [
|
n: [
|
||||||
// Synthetic test
|
// Synthetic test
|
||||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "euHbygrCMLksxd" },
|
{ input: "0eRGgQWJGfT5rFHFj", expected: "euHbygrCMLksxd" },
|
||||||
@@ -251,6 +253,24 @@ export const tests: {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// TODO: es6/tv_es6 variants currently fail
|
||||||
|
player: "638ec5c6",
|
||||||
|
variants: ["main", "tcc", "tce", "es5", "tv", "phone", "tablet"],
|
||||||
|
n: [
|
||||||
|
// Synthetic test
|
||||||
|
{ input: "ZdZIqFPQK-Ty8wId", expected: "1qov8-KM-yH" },
|
||||||
|
],
|
||||||
|
sig: [
|
||||||
|
// Synthetic test
|
||||||
|
{
|
||||||
|
input:
|
||||||
|
"gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||||
|
expected:
|
||||||
|
"MhudCuAuP-6fByOk1_GNXN7gNHHShjyXS2VOgsEItAJz0tipeav0OmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const players = new Map([
|
export const players = new Map([
|
||||||
|
|||||||
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
24
test/test_modules.py
Normal file
24
test/test_modules.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import yt_dlp_ejs.yt.solver
|
||||||
|
|
||||||
|
BASE_PATH = Path(__file__).parent.parent
|
||||||
|
CORE_PATH = BASE_PATH / "yt_dlp_ejs/yt/solver/core.min.js"
|
||||||
|
LIB_PATH = BASE_PATH / "yt_dlp_ejs/yt/solver/lib.min.js"
|
||||||
|
|
||||||
|
|
||||||
|
class TestModules(unittest.TestCase):
|
||||||
|
def test_yt_solver(self):
|
||||||
|
self.assertEqual(
|
||||||
|
yt_dlp_ejs.yt.solver.core(),
|
||||||
|
CORE_PATH.read_text(encoding="utf-8"),
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
yt_dlp_ejs.yt.solver.lib(),
|
||||||
|
LIB_PATH.read_text(encoding="utf-8"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
from yt_dlp_ejs._version import version
|
from yt_dlp_ejs._version import version
|
||||||
from yt_dlp_ejs import yt
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ["version"]
|
||||||
"version",
|
|
||||||
"yt"
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
from . import solver
|
|
||||||
|
|
||||||
__all__ = ["solver"]
|
|
||||||
@@ -2,15 +2,16 @@ import importlib.resources
|
|||||||
|
|
||||||
import yt_dlp_ejs.yt.solver
|
import yt_dlp_ejs.yt.solver
|
||||||
|
|
||||||
|
|
||||||
def core() -> str:
|
def core() -> str:
|
||||||
"""
|
"""
|
||||||
Read the contents of the JavaScript core solver bundle as string.
|
Read the contents of the JavaScript core solver bundle as string.
|
||||||
"""
|
"""
|
||||||
return importlib.resources.read_text(yt_dlp_ejs.yt.solver, "core.min.js")
|
return (importlib.resources.files(yt_dlp_ejs.yt.solver) / "core.min.js").read_text()
|
||||||
|
|
||||||
|
|
||||||
def lib() -> str:
|
def lib() -> str:
|
||||||
"""
|
"""
|
||||||
Read the contents of the JavaScript library solver bundle as string.
|
Read the contents of the JavaScript library solver bundle as string.
|
||||||
"""
|
"""
|
||||||
return importlib.resources.read_text(yt_dlp_ejs.yt.solver, "lib.min.js")
|
return (importlib.resources.files(yt_dlp_ejs.yt.solver) / "lib.min.js").read_text()
|
||||||
|
|||||||
Reference in New Issue
Block a user