Skip to content

youtube.js yt-dlp switch#4225

Open
SkNightmare wants to merge 3 commits intopear-devs:masterfrom
SkNightmare:master
Open

youtube.js yt-dlp switch#4225
SkNightmare wants to merge 3 commits intopear-devs:masterfrom
SkNightmare:master

Conversation

@SkNightmare
Copy link

this is a purpose for an switch button for switch into download method with yt-dlp et youtube.js

i think my code isn't the best code but with my test all working i have tested on linux i can't test it on windows rip but all working fine with me

this is a purpose for an switch button for switch into download method with yt-dlp et youtube.js
@@ -1,8 +1,9 @@
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, writeFileSync, readdirSync } from 'node:fs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <@typescript-eslint/no-unused-vars> reported by reviewdog 🐶
'readdirSync' is defined but never used.

import { randomBytes } from 'node:crypto';

import { app, type BrowserWindow, dialog, ipcMain } from 'electron';
import { spawn, spawnSync } from 'node:child_process';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <importPlugin/order> reported by reviewdog 🐶
There should be at least one empty line between import groups

Suggested change
import { spawn, spawnSync } from 'node:child_process';
import { spawn, spawnSync } from 'node:child_process';

Comment on lines 5 to +6
import { app, type BrowserWindow, dialog, ipcMain } from 'electron';
import { spawn, spawnSync } from 'node:child_process';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <importPlugin/order> reported by reviewdog 🐶
node:child_process import should occur before import of electron

Suggested change
import { app, type BrowserWindow, dialog, ipcMain } from 'electron';
import { spawn, spawnSync } from 'node:child_process';
import { spawn, spawnSync } from 'node:child_process';
import { app, type BrowserWindow, dialog, ipcMain } from 'electron';

@SkNightmare
Copy link
Author

i dont have say'd why i have code that its because for some reason i dont know why but youtube.js method won't work somtime with me

Comment on lines 448 to 450
const candidates: (string | undefined)[] = [];
if (preferred) candidates.push(preferred);
candidates.push('/usr/bin/yt-dlp', '/usr/local/bin/yt-dlp', 'yt-dlp');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a hardcoded path of candidates, we should instead be searching based on PATH.
Something like which could be used.

Also, yt-dlp is a fork, it'd probably be a good idea to also support the original youtube-dl

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can try but normaly its over my comptence

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but honesly i have place an config on the extention configuration for choose the path with the path finder of the system file explorer avalible on the system personaly i think that probably good

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, yt-dlp is a fork, it'd probably be a good idea to also support the original youtube-dl

Supporting both is welcomed. But, if only 1 can be supported in this PR, I'll prefer yt-dlp. The original youtube-dl doesn't even get packaged by any Linux distributions anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can try but normaly its over my comptence

pnpm add which
pnpm add -D @types/which
import { which } from 'which';

const ytdlpExecutable = await which('yt-dlp', { nothrow: true })

this is over your competence? I beg to differ

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

eslint

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace 'plugins.downloader.backend.dialog.ytdlp-permission.message' with ⏎··················'plugins.downloader.backend.dialog.ytdlp-permission.message',⏎················

t('plugins.downloader.backend.dialog.ytdlp-permission.message') ||


🚫 [eslint] <@typescript-eslint/prefer-promise-reject-errors> reported by reviewdog 🐶
Expected the Promise rejection reason to be an Error.


🚫 [eslint] <importPlugin/order> reported by reviewdog 🐶
There should be at least one empty line between import groups

import { spawn, spawnSync } from 'node:child_process';


🚫 [eslint] <importPlugin/order> reported by reviewdog 🐶
node:child_process import should occur before import of electron

import { spawn, spawnSync } from 'node:child_process';


⚠️ [eslint] <@typescript-eslint/no-unused-vars> reported by reviewdog 🐶
'spawn' is defined but never used.

import { spawn, spawnSync } from 'node:child_process';


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····


🚫 [eslint] <@typescript-eslint/no-unsafe-assignment> reported by reviewdog 🐶
Unsafe assignment of an error typed value.

const foundPath = await which('yt-dlp', { nothrow: true });


🚫 [eslint] <@typescript-eslint/no-unsafe-call> reported by reviewdog 🐶
Unsafe call of a(n) error type typed value.

const foundPath = await which('yt-dlp', { nothrow: true });


🚫 [eslint] <@typescript-eslint/no-unsafe-return> reported by reviewdog 🐶
Unsafe return of a value of type error.

if (foundPath) return foundPath;


⚠️ [eslint] <@typescript-eslint/no-unused-vars> reported by reviewdog 🐶
'_' is defined but never used.


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace ·encoding:·'utf8',·stdio:·'ignore' with ⏎··········encoding:·'utf8',⏎··········stdio:·'ignore',⏎·······

const res = spawnSync(c, ['--version'], { encoding: 'utf8', stdio: 'ignore' });


⚠️ [eslint] <@typescript-eslint/no-unused-vars> reported by reviewdog 🐶
'_' is defined but never used.


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····


🚫 [eslint] <@typescript-eslint/no-unsafe-assignment> reported by reviewdog 🐶
Unsafe assignment of an error typed value.

const foundPath = await which('ffmpeg', { nothrow: true });


🚫 [eslint] <@typescript-eslint/no-unsafe-call> reported by reviewdog 🐶
Unsafe call of a(n) error type typed value.

const foundPath = await which('ffmpeg', { nothrow: true });


🚫 [eslint] <@typescript-eslint/no-unsafe-return> reported by reviewdog 🐶
Unsafe return of a value of type error.

if (foundPath) return foundPath;


⚠️ [eslint] <@typescript-eslint/no-unused-vars> reported by reviewdog 🐶
'_' is defined but never used.


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ····


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ··


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Insert ⏎···

typeof engineTranslated === 'string' && !engineTranslated.includes(_engineKey)


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Insert ⏎···

typeof ffmpegTranslated === 'string' && !ffmpegTranslated.includes(_ffmpegKey)


🚫 [eslint] <@typescript-eslint/no-unsafe-assignment> reported by reviewdog 🐶
Unsafe assignment of an error typed value.

const ytdlpPath = await findYtdlpExecutable(config.ytdlpPath ?? undefined);


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace config.ytdlpPath·??·undefined with ⏎··············config.ytdlpPath·??·undefined,⏎············

const ytdlpPath = await findYtdlpExecutable(config.ytdlpPath ?? undefined);


🚫 [eslint] <@typescript-eslint/no-unsafe-assignment> reported by reviewdog 🐶
Unsafe assignment of an error typed value.

const ffmpegPath = await findFfmpegExecutable(config.ytdlpFfmpegPath ?? undefined);


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace config.ytdlpFfmpegPath·??·undefined); with ⏎··············config.ytdlpFfmpegPath·??·undefined,

const ffmpegPath = await findFfmpegExecutable(config.ytdlpFfmpegPath ?? undefined);


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Insert );⏎


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace "yt-dlp·not·found.·Please·install·yt-dlp·or·provide·the·path·in·the·settings." with 'yt-dlp·not·found.·Please·install·yt-dlp·or·provide·the·path·in·the·settings.'

"yt-dlp not found. Please install yt-dlp or provide the path in the settings.",


🚫 [eslint] <stylistic/quotes> reported by reviewdog 🐶
Strings must use singlequote.

"yt-dlp not found. Please install yt-dlp or provide the path in the settings.",


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ············


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace "ffmpeg·not·found.·Please·install·ffmpeg·or·provide·the·path·in·the·settings." with 'ffmpeg·not·found.·Please·install·ffmpeg·or·provide·the·path·in·the·settings.'

"ffmpeg not found. Please install ffmpeg or provide the path in the settings.",


🚫 [eslint] <stylistic/quotes> reported by reviewdog 🐶
Strings must use singlequote.

"ffmpeg not found. Please install ffmpeg or provide the path in the settings.",


🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ············

const findYtdlpExecutable = async (preferred?: string) => {
const candidates: (string | undefined)[] = [];
if (preferred) candidates.push(preferred);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete ······

Suggested change


// Try to find yt-dlp using the which command
try {
const foundPath = await which('yt-dlp', { nothrow: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <@typescript-eslint/no-unsafe-assignment> reported by reviewdog 🐶
Unsafe assignment of an error typed value.


// Try to find yt-dlp using the which command
try {
const foundPath = await which('yt-dlp', { nothrow: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <@typescript-eslint/no-unsafe-call> reported by reviewdog 🐶
Unsafe call of a(n) error type typed value.

// Try to find yt-dlp using the which command
try {
const foundPath = await which('yt-dlp', { nothrow: true });
if (foundPath) return foundPath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <@typescript-eslint/no-unsafe-return> reported by reviewdog 🐶
Unsafe return of a value of type error.

try {
const foundPath = await which('yt-dlp', { nothrow: true });
if (foundPath) return foundPath;
} catch (_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <@typescript-eslint/no-unused-vars> reported by reviewdog 🐶
'_' is defined but never used.

const args: string[] = ['--no-playlist', '--add-metadata', '--embed-thumbnail', '--output', outputTemplate];

if (targetFileExtension === 'mp3') {
args.unshift('--extract-audio', '--audio-format', 'mp3', '--audio-quality', '0');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace '--extract-audio',·'--audio-format',·'mp3',·'--audio-quality',·'0' with ⏎········'--extract-audio',⏎········'--audio-format',⏎········'mp3',⏎········'--audio-quality',⏎········'0',⏎······

Suggested change
args.unshift('--extract-audio', '--audio-format', 'mp3', '--audio-quality', '0');
args.unshift(
'--extract-audio',
'--audio-format',
'mp3',
'--audio-quality',
'0',
);

}

// Pass ffmpeg location to yt-dlp
args.push('--ffmpeg-location', ffmpegPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <@typescript-eslint/no-unsafe-argument> reported by reviewdog 🐶
Unsafe argument of type error typed assigned to a parameter of type string.


await new Promise<void>((resolve, reject) => {
try {
const proc = spawn(ytdlpExecutable, [...args, urlToDownload], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <@typescript-eslint/no-unsafe-argument> reported by reviewdog 🐶
Unsafe argument of type error typed assigned to a parameter of type string.

defaultId: 0,
title:
t('plugins.downloader.backend.dialog.ytdlp-error.title') ||
`yt-dlp erreur`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <stylistic/quotes> reported by reviewdog 🐶
Strings must use singlequote.

Suggested change
`yt-dlp erreur`,
'yt-dlp erreur',

`Derniers messages d'erreur:\n${tail(err)}\n\nSortie:\n${tail(out)}`,
});

reject(new Error(`yt-dlp exited with code ${code}: ${tail(err, 500)}`));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace new·Error(yt-dlp·exited·with·code·${code}:·${tail(err,·500)}) with ⏎············new·Error(yt-dlp·exited·with·code·${code}:·${tail(err,·500)}),⏎··········

Suggested change
reject(new Error(`yt-dlp exited with code ${code}: ${tail(err, 500)}`));
reject(
new Error(`yt-dlp exited with code ${code}: ${tail(err, 500)}`),
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants