From 46190a372bf5d957284753e7488d965c301b32be Mon Sep 17 00:00:00 2001 From: Eir Sunny Date: Thu, 19 Dec 2024 21:27:26 -0600 Subject: [PATCH] Play YT stream first if downloading --- api/downloadApi.js | 4 ++-- api/video.js | 2 +- html/static/js/player-new.js | 6 ++++-- html/static/js/player/quality.js | 5 +++-- pug/video.pug | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/api/downloadApi.js b/api/downloadApi.js index 553101a..d315b0e 100755 --- a/api/downloadApi.js +++ b/api/downloadApi.js @@ -281,9 +281,9 @@ module.exports = [ let dlData = cacheManager.read("download")[videoName] let status = "not found" - if (videoName && videoName != "" && downloader.videoExists(videoName)) { + if (videoName) { // Case 1: not in memory but exists as a file. probably downloaded on a previous server run - if (dlData == undefined) + if (dlData == undefined && downloader.videoExists(videoName)) status = "found" // Case 2: in memory else if (dlData) diff --git a/api/video.js b/api/video.js index 7611b9d..0fe6861 100755 --- a/api/video.js +++ b/api/video.js @@ -255,7 +255,7 @@ module.exports = [ if (!qSet && willDownload && !largestSavedFormat) { dlQueue.enqueue(id, startingFormat.qualityLabel) // Wait for a second to give the default noscript player at least a small portion of bytes to play - await new Promise(resolve => setTimeout(resolve, 1000)) + // await new Promise(resolve => setTimeout(resolve, 1000)) } // Only preload if new quality is better than what we already have, unless using &quality diff --git a/html/static/js/player-new.js b/html/static/js/player-new.js index b6277a6..5ae656f 100755 --- a/html/static/js/player-new.js +++ b/html/static/js/player-new.js @@ -11,8 +11,10 @@ Promise.all(modulePaths.map(m => import(`/static/js/player/${m}.js`))).then(modu modules[modulePaths[i]] = modules[modulePaths[i]].default(modules, q, qa) // Page + all modules loaded - - modules.quality.videoDownloaded(modules.globals.videoPath, modules.globals.startingFormat.qualityLabel) + if (modules.globals.awaitingNewFormat && !modules.globals.startingFormat.cloudtube__label.endsWith(" *")) + modules.quality.setVideoSource(modules.globals.videoPath, true) + else + modules.quality.videoDownloaded(modules.globals.videoPath, modules.globals.startingFormat.qualityLabel, true) }) // Hide default controls diff --git a/html/static/js/player/quality.js b/html/static/js/player/quality.js index d1c150f..a525ce0 100755 --- a/html/static/js/player/quality.js +++ b/html/static/js/player/quality.js @@ -96,9 +96,10 @@ export default (modules, q, qa) => { waitForNewVideoLoad: (videoName, quality) => { modules.cacheInfo.pingCache(`${videoName}-${quality}`, () => self.videoDownloaded(`/getVideo?v=${videoName}&q=${quality}`, quality), 1000 * 3) }, - setVideoSource: newSource => { + setVideoSource: (newSource, dontReload) => { videoSource = newSource - self.reloadSource() + if (!dontReload) + self.reloadSource() }, videoDownloaded: (videoName, quality) => { self.setVideoSource(videoName) diff --git a/pug/video.pug b/pug/video.pug index 99eebf5..71af71d 100755 --- a/pug/video.pug +++ b/pug/video.pug @@ -60,7 +60,7 @@ block content if targetFormat .video-container-inner video(controls playsinline preload="auto" width=targetFormat.second__width height=targetFormat.second__height data-itag=targetFormat.itag autoplay=continuous||autoplay).video - source(type=targetFormat.type src=`${videoPath}${mediaFragment}`) + source(type=targetFormat.type src=(dlStatus < 2 ? startingFormat.url : `${videoPath}${mediaFragment}`)) //- source(type=targetFormat.type) each t in video.captions track(label=t.label kind="subtitles" srclang=t.languageCode src=t.url)