A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
use nano-spawn
Christian Fei40367a7252a9
diff --git a/lib/youtube.js b/lib/youtube.jsindex bda5278..9a0b4e9 100644--- a/lib/youtube.js+++ b/lib/youtube.js@@ -1,10 +1,10 @@-import { execa } from 'execa'+import spawn from 'nano-spawn'import fs from 'fs'export async function downloadVideo(id, repo, callback = () => {}) {return new Promise(async (resolve, reject) => {try {- for await (const line of execa`yt-dlp --default-search ytsearch -f best[ext=mp4] "${id}" -o ./data/videos/${id}.mp4 --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt`.iterable()) {+ for await (const line of spawn('yt-dlp', `"${id}" --default-search ytsearch -f best[ext=mp4] -o ./data/videos/${id}.mp4 --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt`.split(' '))) {callback(line)}@@ -12,6 +12,7 @@ export async function downloadVideo(id, repo, callback = () => {}) {console.log('Download completed')resolve(id)} catch (error) {+ console.error(error)console.error('Error downloading video:', error.stderr)reject(error)}@@ -23,7 +24,7 @@ export async function getVideoSubtitles (id, callback = () => {}) {try {const transcriptPath = `./data/videos/${id}.en.srt`if (!fs.existsSync(transcriptPath)) {- for await (const line of execa`yt-dlp --default-search ytsearch "${id}" -o ./data/videos/${id} --skip-download --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt`.iterable()) {+ for await (const line of spawn('yt-dlp', `"${id}" --default-search ytsearch -o ./data/videos/${id} --skip-download --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt`.split(' '))) {callback(line)}}diff --git a/package-lock.json b/package-lock.jsonindex 142cd14..51e4745 100644--- a/package-lock.json+++ b/package-lock.json@@ -9,295 +9,19 @@"version": "1.0.0","license": "ISC","dependencies": {- "execa": "^9.5.2"+ "nano-spawn": "^0.2.0"}},- "node_modules/@sec-ant/readable-stream": {- "version": "0.4.1",- "resolved": "https://registry.npmjs.org/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz",- "integrity": "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==",- "license": "MIT"- },- "node_modules/@sindresorhus/merge-streams": {- "version": "4.0.0",- "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-4.0.0.tgz",- "integrity": "sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==",- "license": "MIT",- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/cross-spawn": {- "version": "7.0.6",- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",- "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",- "license": "MIT",- "dependencies": {- "path-key": "^3.1.0",- "shebang-command": "^2.0.0",- "which": "^2.0.1"- },- "engines": {- "node": ">= 8"- }- },- "node_modules/execa": {- "version": "9.5.2",- "resolved": "https://registry.npmjs.org/execa/-/execa-9.5.2.tgz",- "integrity": "sha512-EHlpxMCpHWSAh1dgS6bVeoLAXGnJNdR93aabr4QCGbzOM73o5XmRfM/e5FUqsw3aagP8S8XEWUWFAxnRBnAF0Q==",- "license": "MIT",- "dependencies": {- "@sindresorhus/merge-streams": "^4.0.0",- "cross-spawn": "^7.0.3",- "figures": "^6.1.0",- "get-stream": "^9.0.0",- "human-signals": "^8.0.0",- "is-plain-obj": "^4.1.0",- "is-stream": "^4.0.1",- "npm-run-path": "^6.0.0",- "pretty-ms": "^9.0.0",- "signal-exit": "^4.1.0",- "strip-final-newline": "^4.0.0",- "yoctocolors": "^2.0.0"- },- "engines": {- "node": "^18.19.0 || >=20.5.0"- },- "funding": {- "url": "https://github.com/sindresorhus/execa?sponsor=1"- }- },- "node_modules/figures": {- "version": "6.1.0",- "resolved": "https://registry.npmjs.org/figures/-/figures-6.1.0.tgz",- "integrity": "sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==",- "license": "MIT",- "dependencies": {- "is-unicode-supported": "^2.0.0"- },- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/get-stream": {- "version": "9.0.1",- "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-9.0.1.tgz",- "integrity": "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==",- "license": "MIT",- "dependencies": {- "@sec-ant/readable-stream": "^0.4.1",- "is-stream": "^4.0.1"- },- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/human-signals": {- "version": "8.0.0",- "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-8.0.0.tgz",- "integrity": "sha512-/1/GPCpDUCCYwlERiYjxoczfP0zfvZMU/OWgQPMya9AbAE24vseigFdhAMObpc8Q4lc/kjutPfUddDYyAmejnA==",- "license": "Apache-2.0",- "engines": {- "node": ">=18.18.0"- }- },- "node_modules/is-plain-obj": {- "version": "4.1.0",- "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-4.1.0.tgz",- "integrity": "sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==",- "license": "MIT",- "engines": {- "node": ">=12"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/is-stream": {- "version": "4.0.1",- "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz",- "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==",- "license": "MIT",- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/is-unicode-supported": {- "version": "2.1.0",- "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.1.0.tgz",- "integrity": "sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==",- "license": "MIT",- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/isexe": {- "version": "2.0.0",- "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",- "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",- "license": "ISC"- },- "node_modules/npm-run-path": {- "version": "6.0.0",- "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-6.0.0.tgz",- "integrity": "sha512-9qny7Z9DsQU8Ou39ERsPU4OZQlSTP47ShQzuKZ6PRXpYLtIFgl/DEBYEXKlvcEa+9tHVcK8CF81Y2V72qaZhWA==",- "license": "MIT",- "dependencies": {- "path-key": "^4.0.0",- "unicorn-magic": "^0.3.0"- },- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/npm-run-path/node_modules/path-key": {- "version": "4.0.0",- "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz",- "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==",- "license": "MIT",- "engines": {- "node": ">=12"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/parse-ms": {- "version": "4.0.0",- "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz",- "integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==",- "license": "MIT",- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/path-key": {- "version": "3.1.1",- "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",- "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",- "license": "MIT",- "engines": {- "node": ">=8"- }- },- "node_modules/pretty-ms": {- "version": "9.2.0",- "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.2.0.tgz",- "integrity": "sha512-4yf0QO/sllf/1zbZWYnvWw3NxCQwLXKzIj0G849LSufP15BXKM0rbD2Z3wVnkMfjdn/CB0Dpp444gYAACdsplg==",- "license": "MIT",- "dependencies": {- "parse-ms": "^4.0.0"- },- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/shebang-command": {- "version": "2.0.0",- "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",- "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",- "license": "MIT",- "dependencies": {- "shebang-regex": "^3.0.0"- },- "engines": {- "node": ">=8"- }- },- "node_modules/shebang-regex": {- "version": "3.0.0",- "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",- "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",- "license": "MIT",- "engines": {- "node": ">=8"- }- },- "node_modules/signal-exit": {- "version": "4.1.0",- "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",- "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",- "license": "ISC",- "engines": {- "node": ">=14"- },- "funding": {- "url": "https://github.com/sponsors/isaacs"- }- },- "node_modules/strip-final-newline": {- "version": "4.0.0",- "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-4.0.0.tgz",- "integrity": "sha512-aulFJcD6YK8V1G7iRB5tigAP4TsHBZZrOV8pjV++zdUwmeV8uzbY7yn6h9MswN62adStNZFuCIx4haBnRuMDaw==",- "license": "MIT",- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/unicorn-magic": {- "version": "0.3.0",- "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.3.0.tgz",- "integrity": "sha512-+QBBXBCvifc56fsbuxZQ6Sic3wqqc3WWaqxs58gvJrcOuN83HGTCwz3oS5phzU9LthRNE9VrJCFCLUgHeeFnfA==",- "license": "MIT",- "engines": {- "node": ">=18"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },- "node_modules/which": {- "version": "2.0.2",- "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",- "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",- "license": "ISC",- "dependencies": {- "isexe": "^2.0.0"- },- "bin": {- "node-which": "bin/node-which"- },- "engines": {- "node": ">= 8"- }- },- "node_modules/yoctocolors": {- "version": "2.1.1",- "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.1.tgz",- "integrity": "sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==",+ "node_modules/nano-spawn": {+ "version": "0.2.0",+ "resolved": "https://registry.npmjs.org/nano-spawn/-/nano-spawn-0.2.0.tgz",+ "integrity": "sha512-IjZBIOLxSlxu+m/kacg9JuP93oUpRemeV0mEuCy64nzBKKIL9m0aLJHtVPcVuzJDHFhElzjpwbW4a3tMzgKoZQ==","license": "MIT","engines": {- "node": ">=18"+ "node": ">=18.19"},"funding": {- "url": "https://github.com/sponsors/sindresorhus"+ "url": "https://github.com/sindresorhus/nano-spawn?sponsor=1"}}}diff --git a/package.json b/package.jsonindex 1997131..ce55c42 100644--- a/package.json+++ b/package.json@@ -12,6 +12,6 @@"license": "ISC","description": "","dependencies": {- "execa": "^9.5.2"+ "nano-spawn": "^0.2.0"}}