A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
refactor: extract yt-dlp args to shared module
Christian Fei31ebfd7f4d0d
diff --git a/lib/workers/video.js b/lib/workers/video.jsindex 155b2fb..915749d 100644--- a/lib/workers/video.js+++ b/lib/workers/video.js@@ -1,32 +1,10 @@// videoWorker.js-import fs from 'fs'import { spawn } from 'child_process'import { parentPort, workerData } from 'worker_threads'--function getOptionalCookiesPath () {- if (fs.existsSync('/app/cookies.txt')) return '/app/cookies.txt'- if (fs.existsSync('./cookies.txt')) return './cookies.txt'-}-const videoYTDLPArgs = quality => [- '--concurrent-fragments',- '10',- '--newline',- '--progress',- '--progress-delta',- '1',- '--sponsorblock-remove',- 'all,-filler',- '--merge-output-format',- 'mp4',- '-f',- `bestvideo[height<=${quality}]+bestaudio/best`,- '--check-formats',- '--verbose'-]+import { videoYTDLPArgs, buildCookiesOption } from '../yt-dlp-args.js'function video (id, quality) {- const cookiesPath = getOptionalCookiesPath()- const cookiesOption = cookiesPath ? ['--cookies', cookiesPath] : []+ const cookiesOption = buildCookiesOption()return spawn('yt-dlp', ['-o',`./data/videos/${id}.%(ext)s`,diff --git a/lib/yt-dlp-args.js b/lib/yt-dlp-args.jsnew file mode 100644index 0000000..5ce443b--- /dev/null+++ b/lib/yt-dlp-args.js@@ -0,0 +1,41 @@+import fs from 'fs'++const subtitlesYTDLPArgs = [+ '--write-subs',+ '--write-auto-subs',+ '--sub-format',+ 'vtt',+ '--convert-subs',+ 'srt',+ '-k',+ '--verbose'+]++const videoYTDLPArgs = quality => [+ '--concurrent-fragments',+ '10',+ '--newline',+ '--progress',+ '--progress-delta',+ '1',+ '--sponsorblock-remove',+ 'all,-filler',+ '--merge-output-format',+ 'mp4',+ '-f',+ `bestvideo[height<=${quality}]+bestaudio/best`,+ '--check-formats',+ '--verbose'+]++function getOptionalCookiesPath () {+ if (fs.existsSync('/app/cookies.txt')) return '/app/cookies.txt'+ if (fs.existsSync('./cookies.txt')) return './cookies.txt'+}++export function buildCookiesOption () {+ const cookiesPath = getOptionalCookiesPath()+ return cookiesPath ? ['--cookies', cookiesPath] : []+}++export { subtitlesYTDLPArgs, videoYTDLPArgs }diff --git a/lib/yt-dlp.js b/lib/yt-dlp.jsindex e7e6fa3..ab8c321 100644--- a/lib/yt-dlp.js+++ b/lib/yt-dlp.js@@ -1,36 +1,8 @@-import fs from 'fs'import spawn from 'nano-spawn'--const subtitlesYTDLPArgs = [- '--write-subs',- '--write-auto-subs',- '--sub-format',- 'vtt',- '--convert-subs',- 'srt',- '-k',- '--verbose'-]-const videoYTDLPArgs = quality => [- '--concurrent-fragments',- '10',- '--newline',- '--progress',- '--progress-delta',- '1',- '--sponsorblock-remove',- 'all,-filler',- '--merge-output-format',- 'mp4',- '-f',- `bestvideo[height<=${quality}]+bestaudio/best`,- '--check-formats',- '--verbose'-]+import { subtitlesYTDLPArgs, videoYTDLPArgs, buildCookiesOption } from './yt-dlp-args.js'export function video (id, quality) {- const cookiesPath = getOptionalCookiesPath()- const cookiesOption = cookiesPath ? ['--cookies', cookiesPath] : []+ const cookiesOption = buildCookiesOption()return spawn('yt-dlp', ['-o',`./data/videos/${id}.%(ext)s`,@@ -42,8 +14,7 @@ export function video (id, quality) {])}export function subtitles (id) {- const cookiesPath = getOptionalCookiesPath()- const cookiesOption = cookiesPath ? ['--cookies', cookiesPath] : []+ const cookiesOption = buildCookiesOption()return spawn('yt-dlp', ['-o',`./data/videos/${id}`,@@ -54,8 +25,3 @@ export function subtitles (id) {id])}--function getOptionalCookiesPath () {- if (fs.existsSync('/app/cookies.txt')) return '/app/cookies.txt'- if (fs.existsSync('./cookies.txt')) return './cookies.txt'-}diff --git a/package-lock.json b/package-lock.jsonindex dab8508..f57b512 100644--- a/package-lock.json+++ b/package-lock.json@@ -1889,9 +1889,9 @@}},"node_modules/basic-ftp": {- "version": "5.2.0",- "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.2.0.tgz",- "integrity": "sha512-VoMINM2rqJwJgfdHq6RiUudKt2BV+FY5ZFezP/ypmwayk68+NzzAQy4XXLlqsGD4MCzq3DrmNFD/uUmBJuGoXw==",+ "version": "5.3.1",+ "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.3.1.tgz",+ "integrity": "sha512-bopVNp6ugyA150DDuZfPFdt1KZ5a94ZDiwX4hMgZDzF+GttD80lEy8kj98kbyhLXnPvhtIo93mdnLIjpCAeeOw==","dev": true,"license": "MIT","engines": {@@ -1899,9 +1899,9 @@}},"node_modules/brace-expansion": {- "version": "1.1.12",- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",- "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",+ "version": "1.1.14",+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.14.tgz",+ "integrity": "sha512-MWPGfDxnyzKU7rNOW9SP/c50vi3xrmrua/+6hfPbCS2ABNWfx24vPidzvC7krjU/RTo235sV776ymlsMtGKj8g==","dev": true,"license": "MIT","dependencies": {@@ -4310,15 +4310,11 @@}},"node_modules/ip-address": {- "version": "9.0.5",- "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",- "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==",+ "version": "10.2.0",+ "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.2.0.tgz",+ "integrity": "sha512-/+S6j4E9AHvW9SWMSEY9Xfy66O5PWvVEJ08O0y5JGyEKQpojb0K0GKpz/v5HJ/G0vi3D2sjGK78119oXZeE0qA==","dev": true,"license": "MIT",- "dependencies": {- "jsbn": "1.1.0",- "sprintf-js": "^1.1.3"- },"engines": {"node": ">= 12"}@@ -4927,13 +4923,6 @@"js-yaml": "bin/js-yaml.js"}},- "node_modules/jsbn": {- "version": "1.1.0",- "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",- "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==",- "dev": true,- "license": "MIT"- },"node_modules/json-buffer": {"version": "3.0.1","resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",@@ -6947,13 +6936,13 @@}},"node_modules/socks": {- "version": "2.8.4",- "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.4.tgz",- "integrity": "sha512-D3YaD0aRxR3mEcqnidIs7ReYJFVzWdd6fXJYUM8ixcQcJRGTka/b3saV0KflYhyVJXKhb947GndU35SxYNResQ==",+ "version": "2.8.8",+ "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.8.tgz",+ "integrity": "sha512-NlGELfPrgX2f1TAAcz0WawlLn+0r3FyhhCRpFFK2CemXenPYvzMWWZINv3eDNo9ucdwme7oCHRY0Jnbs4aIkog==","dev": true,"license": "MIT","dependencies": {- "ip-address": "^9.0.5",+ "ip-address": "^10.1.1","smart-buffer": "^4.2.0"},"engines": {@@ -6986,13 +6975,6 @@"node": ">= 8"}},- "node_modules/sprintf-js": {- "version": "1.1.3",- "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",- "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==",- "dev": true,- "license": "BSD-3-Clause"- },"node_modules/standard": {"version": "17.1.2","resolved": "https://registry.npmjs.org/standard/-/standard-17.1.2.tgz",