Exclude 0p from auto webtorrent quality

This commit is contained in:
Chocobozzz 2020-06-24 11:50:26 +02:00
parent 187b2e2346
commit 3cd56a291c
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 22 additions and 18 deletions

View File

@ -362,31 +362,35 @@ class WebTorrentPlugin extends Plugin {
} }
private getAppropriateFile (averageDownloadSpeed?: number): VideoFile { private getAppropriateFile (averageDownloadSpeed?: number): VideoFile {
if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined if (this.videoFiles === undefined) return undefined
if (this.videoFiles.length === 1) return this.videoFiles[0]
const files = this.videoFiles.filter(f => f.resolution.id !== 0)
if (files.length === 0) return undefined
if (files.length === 1) return files[0]
// Don't change the torrent is the play was ended // Don't change the torrent is the play was ended
if (this.torrent && this.torrent.progress === 1 && this.player.ended()) return this.currentVideoFile if (this.torrent && this.torrent.progress === 1 && this.player.ended()) return this.currentVideoFile
if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed() if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
averageDownloadSpeed = 0
// Limit resolution according to player height // Limit resolution according to player height
const playerHeight = this.playerElement.offsetHeight const playerHeight = this.playerElement.offsetHeight
// We take the first resolution just above the player height // We take the first resolution just above the player height
// Example: player height is 530px, we want the 720p file instead of 480p // Example: player height is 530px, we want the 720p file instead of 480p
let maxResolution = this.videoFiles[0].resolution.id let maxResolution = files[0].resolution.id
for (let i = this.videoFiles.length - 1; i >= 0; i--) { for (let i = files.length - 1; i >= 0; i--) {
const resolutionId = this.videoFiles[i].resolution.id const resolutionId = files[i].resolution.id
if (resolutionId >= playerHeight) { if (resolutionId !== 0 && resolutionId >= playerHeight) {
maxResolution = resolutionId maxResolution = resolutionId
break break
} }
} }
// Filter videos we can play according to our screen resolution and bandwidth // Filter videos we can play according to our screen resolution and bandwidth
const filteredFiles = this.videoFiles const filteredFiles = files.filter(f => f.resolution.id <= maxResolution)
.filter(f => f.resolution.id <= maxResolution)
.filter(f => { .filter(f => {
const fileBitrate = (f.size / this.videoDuration) const fileBitrate = (f.size / this.videoDuration)
let threshold = fileBitrate let threshold = fileBitrate
@ -400,7 +404,7 @@ class WebTorrentPlugin extends Plugin {
}) })
// If the download speed is too bad, return the lowest resolution we have // If the download speed is too bad, return the lowest resolution we have
if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles) if (filteredFiles.length === 0) return videoFileMinByResolution(files)
return videoFileMaxByResolution(filteredFiles) return videoFileMaxByResolution(filteredFiles)
} }