diff options
author | Astound <kirito@disroot.org> | 2025-03-05 12:12:22 +0800 |
---|---|---|
committer | Astound <kirito@disroot.org> | 2025-03-05 12:12:22 +0800 |
commit | e8b14ac52846d3c7d0b2842c3248ad475249ada4 (patch) | |
tree | 473f5fa962c3ff8c23f01a620e1b2d98b3eab439 /youtube | |
parent | 35daa8879f7e0741d7723d93dca681c061658c68 (diff) | |
download | yt-local-e8b14ac52846d3c7d0b2842c3248ad475249ada4.tar.lz yt-local-e8b14ac52846d3c7d0b2842c3248ad475249ada4.tar.xz yt-local-e8b14ac52846d3c7d0b2842c3248ad475249ada4.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')
-rw-r--r-- | youtube/static/js/av-merge.js | 30 |
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..ba496e6 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: 15 * 10**6, // 15 megabytes WebOS (LG) + samsungTizen: 15 * 10**6, // 15 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']; |