diff --git a/src/sources/ytdlp.ts b/src/sources/ytdlp.ts index 213a63c..64a1c63 100644 --- a/src/sources/ytdlp.ts +++ b/src/sources/ytdlp.ts @@ -103,13 +103,41 @@ function runYtDlp(args: string[], timeoutMs = 45_000): Promise { }); } +/** yt-dlp messages people actually hit, in words that suggest what to do. */ +const ERROR_PATTERNS: Array<[RegExp, string]> = [ + [/unsupported url/i, "Не понимаю эту ссылку — проверьте, что она открывается в браузере"], + [/is not a valid url/i, "Это не похоже на ссылку"], + [/video unavailable|this video is not available/i, "Видео недоступно"], + [/private video/i, "Видео приватное"], + [/members[- ]only|join this channel/i, "Видео только для участников канала"], + [/confirm your age|age[- ]restricted/i, "Возрастное ограничение — нужны cookies аккаунта (YTDLP_COOKIES)"], + [/confirm you'?re not a bot|sign in to confirm/i, "YouTube требует вход — добавьте cookies.txt (YTDLP_COOKIES)"], + [/not available in your country|geo[- ]?restricted|blocked it in your country/i, "Недоступно в регионе сервера"], + [/page needs to be reloaded/i, "YouTube сменил API — обновите yt-dlp (см. README)"], + [/unable to download|network|timed out|connection/i, "Не удалось связаться с источником"], +]; + +/** Percent-encoded URLs are unreadable in a chat message. */ +function decodeUrls(text: string): string { + return text.replace(/https?:\/\/\S+/g, (url) => { + try { + return decodeURI(url); + } catch { + return url; + } + }); +} + function firstUsefulError(stderr: string): string { const line = stderr .split(/\r?\n/) .map((l) => l.trim()) .find((l) => l.toUpperCase().startsWith("ERROR")); if (!line) return "Не удалось получить трек"; - return line.replace(/^ERROR:\s*/i, "").slice(0, 300); + + const raw = decodeUrls(line.replace(/^ERROR:\s*/i, "")).slice(0, 300); + const known = ERROR_PATTERNS.find(([pattern]) => pattern.test(raw)); + return known ? known[1] : raw; } function sourceOf(entry: YtDlpEntry): SourceKind { diff --git a/web/src/components/SearchPanel.tsx b/web/src/components/SearchPanel.tsx index 789fe9d..5bfe29d 100644 --- a/web/src/components/SearchPanel.tsx +++ b/web/src/components/SearchPanel.tsx @@ -12,6 +12,7 @@ const SOURCE_BADGE: Record = { interface Props { serverId: string; canControl: boolean; + /** Adds the local library to the source picker. */ localLibrary: boolean; onError(message: string | null): void; } @@ -126,16 +127,6 @@ export function SearchPanel({ serverId, canControl, localLibrary, onError }: Pro ))} )} - -

- Префиксы: sc: — искать в SoundCloud, yt: — в YouTube - {localLibrary ? ( - <> - , local: — в локальной медиатеке - - ) : null} - . -

); }