From be8fa594d3c3a98157ad747ebaf053dad032b1aa Mon Sep 17 00:00:00 2001 From: "Michael V." Date: Sat, 28 Jun 2025 14:52:01 +0200 Subject: [PATCH 1/6] Add startAt, endAt parameter and pass download sections After testing, it seems inaccurate. If you rely on the YouTube front end, pick second 50 and compare it with the download - it doesn't match with the download. It starts earlier or later even --- public/convert.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/public/convert.php b/public/convert.php index 9a339f6..7daf785 100644 --- a/public/convert.php +++ b/public/convert.php @@ -12,6 +12,8 @@ if(isset($_GET["youtubelink"]) && !empty($_GET["youtubelink"])) { $youtubelink = $_GET["youtubelink"]; + $startAt = $_GET["startAt"] ?? null; + $endAt = $_GET["endAt"] ?? null; $format = $_GET['format'] ?? 'mp3'; if(!in_array($format, POSSIBLE_FORMATS)) @@ -32,6 +34,26 @@ $exists = file_exists(Config::DOWNLOAD_FOLDER.$id.".".$format); + if (!empty($startAt) || !empty($endAt)) + { + $query = parse_url($youtubelink, PHP_URL_QUERY); + parse_str($query, $params); + + if (!empty($startAt)) + $params['start'] = $startAt; + + if (!empty($endAt)) + $params['end'] = $endAt; + + $youtubelink = strtok($youtubelink, '?') . '?' . http_build_query($params); + + if ($exists) + { + unlink(Config::DOWNLOAD_FOLDER.$id.".".$format); + $exists = false; + } + } + if(Config::DOWNLOAD_MAX_LENGTH > 0 || $exists) { try { @@ -70,6 +92,11 @@ ->cookies(file_exists(Config::COOKIE_FILE) ? Config::COOKIE_FILE : null) ->url($youtubelink); + if (!empty($startAt) || !empty($endAt)) + $options = $options->downloadSections('*from-url'); + else + $options = $options->noContinue(true); + if($format == 'mp3') { $options = $options->extractAudio(true) From b703fc4339005e7b0b56a17dd57d1e18d5d39acc Mon Sep 17 00:00:00 2001 From: "Michael V." Date: Sat, 28 Jun 2025 15:09:22 +0200 Subject: [PATCH 2/6] Add start, end input to front-end --- public/convert.php | 1 + public/index.php | 30 +++++++++++++++++++++++++++++- public/script.js | 10 +++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/public/convert.php b/public/convert.php index 7daf785..d942d4d 100644 --- a/public/convert.php +++ b/public/convert.php @@ -49,6 +49,7 @@ if ($exists) { + //todo this if can probably go when youtube-dl-php supports --force-overwrites options unlink(Config::DOWNLOAD_FOLDER.$id.".".$format); $exists = false; } diff --git a/public/index.php b/public/index.php index 00bc037..e7b820a 100644 --- a/public/index.php +++ b/public/index.php @@ -39,7 +39,35 @@ - +
+
+
+ + + + +
+ + +
+ +
+ + +
+ + + + +
+
+ Specify start and/or end times (in seconds) to trim the video. Leave both empty to download the complete video.
+ Start time only: downloads from that point to the end. End time only: downloads from the beginning to that point. +
+
+
+ + diff --git a/public/script.js b/public/script.js index a530e20..666d035 100644 --- a/public/script.js +++ b/public/script.js @@ -9,11 +9,19 @@ document.addEventListener('DOMContentLoaded', () => { const submitButton = frmConvert.querySelector("button[type=submit]"); const link = document.getElementById('link').value; const format = document.getElementById('format').value; + const startAt = document.getElementById('startAt').value; + const endAt = document.getElementById('endAt').value; submitButton.classList.add("disabled"); submitButton.innerHTML = " Converting..."; - const endpoint = `${frmConvert.getAttribute("action")}?youtubelink=${link}&format=${format}`; + let endpoint = `${frmConvert.getAttribute("action")}?youtubelink=${link}&format=${format}`; + + if (startAt.length > 0) + endpoint += `&startAt=${startAt}`; + + if (endAt.length > 0) + endpoint += `&endAt=${endAt}`; fetch(endpoint) .then(response => response.json()) From 7029e9625208521b9af7d7d21304f8a147e753ec Mon Sep 17 00:00:00 2001 From: "Michael V." Date: Sat, 28 Jun 2025 15:12:15 +0200 Subject: [PATCH 3/6] Add fillStartEnd() If already pasting a youtube url with start, end or t parameter, fill the corresponding inputs automaticly. --- public/index.php | 2 +- public/script.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index e7b820a..bc202a0 100644 --- a/public/index.php +++ b/public/index.php @@ -23,7 +23,7 @@
- +
diff --git a/public/script.js b/public/script.js index 666d035..eb88ae0 100644 --- a/public/script.js +++ b/public/script.js @@ -176,4 +176,37 @@ function handleInfoResponse(data, submitButton) tableCells[9].innerText = data.title; tableCells[10].innerHTML = `${data.url}`; } +} + +function fillStartEnd() +{ + const elLink = document.getElementById('link'); + const elStart = document.getElementById('startAt'); + const elEnd = document.getElementById('endAt'); + + const url = new URL(elLink.value); + const start = url.searchParams.get("start") || url.searchParams.get("t"); + const end = url.searchParams.get("end"); + + if (start && start.length > 0) + { + elStart.value = start; + elStart.setAttribute('readonly', 'readonly'); + } + else + { + elStart.value = ''; + elStart.removeAttribute('readonly'); + } + + if (end && end.length > 0) + { + elEnd.value = end; + elEnd.setAttribute('readonly', 'readonly'); + } + else + { + elEnd.value = ''; + elEnd.removeAttribute('readonly'); + } } \ No newline at end of file From 7d51b7360cfff36c4611aa6a639a3a6fec6780de Mon Sep 17 00:00:00 2001 From: "Michael V." Date: Wed, 2 Jul 2025 10:42:29 +0200 Subject: [PATCH 4/6] startAt should be lower than endAt --- public/convert.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/public/convert.php b/public/convert.php index d60e8e2..4e8d45c 100644 --- a/public/convert.php +++ b/public/convert.php @@ -35,6 +35,15 @@ if (!empty($startAt) || !empty($endAt)) { + if (!empty($startAt) && !empty($endAt)) + { + if ((int)$startAt >= (int)$endAt) + { + http_response_code(400); + die(json_encode(array("error" => true, "message" => "Invalid time range: startAt must be less than endAt"))); + } + } + $query = parse_url($youtubelink, PHP_URL_QUERY); parse_str($query, $params); @@ -48,7 +57,7 @@ if ($exists) { - //todo this if can probably go when youtube-dl-php supports --force-overwrites options + //todo this can probably go when youtube-dl-php supports --force-overwrites options unlink(env('DOWNLOAD_FOLDER').$id.".".$format); $exists = false; } From 4a0b47d53324e73ff94a6dcac5ba9e03ce7364d7 Mon Sep 17 00:00:00 2001 From: "Michael V." Date: Fri, 4 Jul 2025 21:59:45 +0200 Subject: [PATCH 5/6] noContinue isn't needed --- public/convert.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/public/convert.php b/public/convert.php index 4e8d45c..faefd95 100644 --- a/public/convert.php +++ b/public/convert.php @@ -103,8 +103,6 @@ if (!empty($startAt) || !empty($endAt)) $options = $options->downloadSections('*from-url'); - else - $options = $options->noContinue(true); if($format == 'mp3') { From 40037a6772124b801acfab919f6a465589d508ef Mon Sep 17 00:00:00 2001 From: "Michael V." Date: Fri, 4 Jul 2025 22:06:01 +0200 Subject: [PATCH 6/6] composer: Increase process timeout This google/apiclient package takes way too long to unzip ?? --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f5f05ad..a963433 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "phpstan/phpstan": "^2.0" }, "config": { - "sort-packages": true + "sort-packages": true, + "process-timeout": 600 } }