From db80b929ca2ca7a96dc02468b7e0361c3da6988b Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Fri, 16 Jun 2023 15:51:57 +0200 Subject: [PATCH] Fix #25 --- src/lib/server/timeline.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/server/timeline.ts b/src/lib/server/timeline.ts index 36191b8..b2a68fb 100644 --- a/src/lib/server/timeline.ts +++ b/src/lib/server/timeline.ts @@ -27,6 +27,7 @@ import sharp from 'sharp'; import { WebSocket } from 'ws'; const URL_REGEX = new RegExp(/href="(?[^>]+?)" target="_blank"/gm); +const INVIDIOUS_REGEX = new RegExp(/invidious.*?watch.*?v=(?[a-zA-Z_0-9-]+)/gm); export class TimelineReader { private static _instance: TimelineReader; @@ -71,8 +72,12 @@ export class TimelineReader { return null; } + const videoId = INVIDIOUS_REGEX.exec(url.href)?.groups?.videoId; + const urlString = + videoId !== undefined ? `https://youtube.com/watch?v=${videoId}` : url.toString(); + const odesliParams = new URLSearchParams(); - odesliParams.append('url', url.toString()); + odesliParams.append('url', urlString); odesliParams.append('userCountry', 'DE'); odesliParams.append('songIfSingle', 'true'); if (ODESLI_API_KEY && ODESLI_API_KEY !== 'CHANGE_ME') {