From 711bfcc9526ec208a6591b075d5b19a9211e7faa Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 29 Oct 2024 08:21:01 -0400 Subject: [PATCH 1/2] Add support for hms timestamp in query string --- src/main/index.js | 23 ++++++++++++++++++++++- src/renderer/helpers/utils.js | 21 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 3e671abccaf58..4c10b4a76db0a 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -146,7 +146,28 @@ function runApp() { } if (params.has('timestamp')) { - newParams.set('t', params.get('timestamp')) + let timestamp = params.get('timestamp') + if (timestamp && (timestamp.includes('h') || timestamp.includes('m') || timestamp.includes('s'))) { + if (timestamp && (timestamp.includes('h') || timestamp.includes('m') || timestamp.includes('s'))) { + const { seconds, minutes, hours } = timestamp.match(/(?:(?(\d+))h)?(?:(?(\d+))m)?(?:(?(\d+))s)?/).groups + let time = 0 + + if (seconds) { + time += Number(seconds) + } + + if (minutes) { + time += 60 * Number(minutes) + } + + if (hours) { + time += 3600 * Number(hours) + } + + timestamp = time + } + } + newParams.set('t', timestamp) hasParams = true } diff --git a/src/renderer/helpers/utils.js b/src/renderer/helpers/utils.js index 697cec8c9c5e9..12871b1779bb6 100644 --- a/src/renderer/helpers/utils.js +++ b/src/renderer/helpers/utils.js @@ -611,7 +611,26 @@ export function getVideoParamsFromUrl(url) { function extractParams(videoId) { paramsObject.videoId = videoId - paramsObject.timestamp = urlObject.searchParams.get('t') + let timestamp = urlObject.searchParams.get('t') + if (timestamp && (timestamp.includes('h') || timestamp.includes('m') || timestamp.includes('s'))) { + const { seconds, minutes, hours } = timestamp.match(/(?:(?(\d+))h)?(?:(?(\d+))m)?(?:(?(\d+))s)?/).groups + let time = 0 + + if (seconds) { + time += Number(seconds) + } + + if (minutes) { + time += 60 * Number(minutes) + } + + if (hours) { + time += 3600 * Number(hours) + } + + timestamp = time + } + paramsObject.timestamp = timestamp } const extractors = [ From eb760f490a7c4a6d1239d0206d9b1c9afa04739b Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:25:30 -0400 Subject: [PATCH 2/2] undo change in index.js --- src/main/index.js | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 4c10b4a76db0a..3e671abccaf58 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -146,28 +146,7 @@ function runApp() { } if (params.has('timestamp')) { - let timestamp = params.get('timestamp') - if (timestamp && (timestamp.includes('h') || timestamp.includes('m') || timestamp.includes('s'))) { - if (timestamp && (timestamp.includes('h') || timestamp.includes('m') || timestamp.includes('s'))) { - const { seconds, minutes, hours } = timestamp.match(/(?:(?(\d+))h)?(?:(?(\d+))m)?(?:(?(\d+))s)?/).groups - let time = 0 - - if (seconds) { - time += Number(seconds) - } - - if (minutes) { - time += 60 * Number(minutes) - } - - if (hours) { - time += 3600 * Number(hours) - } - - timestamp = time - } - } - newParams.set('t', timestamp) + newParams.set('t', params.get('timestamp')) hasParams = true }