commit 689f9dee3a583d1f845c9596879aa03874b6fad8 parent 1ff826a1c3edb5f12015ea906519d6e73ff6f170 Author: JayVii <jayvii[AT]posteo[DOT]de> Date: Wed, 20 Nov 2024 18:34:48 +0100 fix: return 404 while video is still downloading Diffstat:
M | index.php | | | 27 | +++++++++++++++++++-------- |
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/index.php b/index.php @@ -164,13 +164,19 @@ if (!is_null($_GET["channel"]) && $auth) { $download_retry <= 3 ) { $download_retry++; - passthru( - "yt-dlp " . - "-x " . - "--audio-format opus " . - "-o '%(id)s.%(ext)s' " . - "https://www.youtube.com/watch?v=" . basename($_GET["video"]) - ); + if ( + strlen( + system("ps ax | grep -v grep | grep " . basename($_GET["video"])) + ) < 1 + ) { + passthru( + "yt-dlp " . + "-x " . + "--audio-format opus " . + "-o '%(id)s.%(ext)s' " . + "https://www.youtube.com/watch?v=" . basename($_GET["video"]) + ); + } } // If file has been downloaded properly, check whether the file is valid if (!(analyze_video(basename($_GET["video"]) . ".opus")["playtime_seconds"] > 0)) { @@ -178,7 +184,12 @@ if (!is_null($_GET["channel"]) && $auth) { unlink(basename($_GET["video"]) . ".opus"); } // If file still exists, return to user - if (file_exists(basename($_GET["video"]) . ".opus")) { + if ( + file_exists(basename($_GET["video"]) . ".opus") && + strlen( + system("ps ax | grep -v grep | grep " . basename($_GET["video"])) + ) < 1 + ) { header("content-type: audio/ogg; codec=opus"); header( "content-length: " . filesize(basename($_GET["video"]) . ".opus")