aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/static/js
diff options
context:
space:
mode:
authorAstound <kirito@disroot.org>2025-03-07 01:28:34 +0800
committerAstound <kirito@disroot.org>2025-03-07 01:28:34 +0800
commitdecbb8e0b2ce1a4b379cbd463ea836436eb11c63 (patch)
tree9b1c6efc1e041c6681cbf88c2d7833a74c8b97e3 /youtube/static/js
parent35daa8879f7e0741d7723d93dca681c061658c68 (diff)
downloadyt-local-decbb8e0b2ce1a4b379cbd463ea836436eb11c63.tar.lz
yt-local-decbb8e0b2ce1a4b379cbd463ea836436eb11c63.tar.xz
yt-local-decbb8e0b2ce1a4b379cbd463ea836436eb11c63.zip
Improve buffer management for different platforms
- Introduced `BUFFER_CONFIG` to define buffer sizes for various systems (webOS, Samsung Tizen, Android TV, desktop). - Added `detectSystem()` function to determine the platform based on `navigator.userAgent`. - Updated `Stream` constructor to use platform-specific buffer sizes dynamically. - Added console log for debugging detected system and applied buffer size.
Diffstat (limited to 'youtube/static/js')
-rw-r--r--youtube/static/js/av-merge.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/youtube/static/js/av-merge.js b/youtube/static/js/av-merge.js
index e00f440..cfe9574 100644
--- a/youtube/static/js/av-merge.js
+++ b/youtube/static/js/av-merge.js
@@ -20,6 +20,29 @@
// TODO: Call abort to cancel in-progress appends?
+// Buffer sizes for different systems
+const BUFFER_CONFIG = {
+ default: 50 * 10**6, // 50 megabytes
+ webOS: 20 * 10**6, // 20 megabytes WebOS (LG)
+ samsungTizen: 20 * 10**6, // 20 megabytes Samsung Tizen OS
+ androidTV: 30 * 10**6, // 30 megabytes Android TV
+ desktop: 50 * 10**6, // 50 megabytes PC/Mac
+};
+
+function detectSystem() {
+ const userAgent = navigator.userAgent.toLowerCase();
+ if (/webos|lg browser/i.test(userAgent)) {
+ return "webOS";
+ } else if (/tizen/i.test(userAgent)) {
+ return "samsungTizen";
+ } else if (/android tv|smart-tv/i.test(userAgent)) {
+ return "androidTV";
+ } else if (/firefox|chrome|safari|edge/i.test(userAgent)) {
+ return "desktop";
+ } else {
+ return "default";
+ }
+}
function AVMerge(video, srcInfo, startTime){
this.audioSource = null;
@@ -164,6 +187,8 @@ AVMerge.prototype.printDebuggingInfo = function() {
}
function Stream(avMerge, source, startTime, avRatio) {
+ const selectedSystem = detectSystem();
+ let baseBufferTarget = BUFFER_CONFIG[selectedSystem] || BUFFER_CONFIG.default;
this.avMerge = avMerge;
this.video = avMerge.video;
this.url = source['url'];
@@ -173,10 +198,11 @@ function Stream(avMerge, source, startTime, avRatio) {
this.mimeCodec = source['mime_codec']
this.streamType = source['acodec'] ? 'audio' : 'video';
if (this.streamType == 'audio') {
- this.bufferTarget = avRatio*50*10**6;
+ this.bufferTarget = avRatio * baseBufferTarget;
} else {
- this.bufferTarget = 50*10**6; // 50 megabytes
+ this.bufferTarget = baseBufferTarget;
}
+ console.info(`Detected system: ${selectedSystem}. Applying bufferTarget of ${this.bufferTarget} bytes to ${this.streamType}.`);
this.initRange = source['init_range'];
this.indexRange = source['index_range'];