aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-08-29 13:00:39 -0700
committerJesús <heckyel@hyperbola.info>2021-08-29 23:17:32 -0500
commit2ae81f2a78fcf71ac14099cf6642cc6181299d27 (patch)
tree7e88b97b7299862752dfe8dd9f04a5a0f64f0e67
parent99cb1c48eac0a8553945e308d22fc7fa7da83825 (diff)
downloadyt-local-2ae81f2a78fcf71ac14099cf6642cc6181299d27.tar.lz
yt-local-2ae81f2a78fcf71ac14099cf6642cc6181299d27.tar.xz
yt-local-2ae81f2a78fcf71ac14099cf6642cc6181299d27.zip
Add setting to prefer uni or pair sources and fix selection b/w them
pair_quality != uni_quality was the wrong condition to check, since there are cases where the target_resolution is 360, and there are no pair sources at 360, but there are some at other resolutions, which would falsely select the pair sources. Signed-off-by: Jesús <heckyel@hyperbola.info>
-rw-r--r--settings.py9
-rw-r--r--youtube/watch.py17
2 files changed, 22 insertions, 4 deletions
diff --git a/settings.py b/settings.py
index 9c64c3a..c97e3d8 100644
--- a/settings.py
+++ b/settings.py
@@ -168,6 +168,15 @@ For security reasons, enabling this is not recommended.''',
'category': 'playback',
}),
+ ('prefer_uni_sources', {
+ 'label': 'Prefer integrated sources',
+ 'type': bool,
+ 'default': True,
+ 'comment': '',
+ 'category': 'playback',
+ 'description': 'If enabled and the default resolution is set to 360p or 720p, uses the unified (integrated) video files which contain audio and video, with buffering managed by the browser. If disabled, always uses the separate audio and video files through custom buffer management in av-merge via MediaSource.',
+ }),
+
('use_video_player', {
'type': int,
'default': 1,
diff --git a/youtube/watch.py b/youtube/watch.py
index 32b6eef..7494b95 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -23,7 +23,7 @@ except FileNotFoundError:
decrypt_cache = {}
-def get_video_sources(info):
+def get_video_sources(info, target_resolution):
'''return dict with organized sources: {
'uni_sources': [{}, ...], # video and audio in one file
'uni_idx': int, # default unified source index
@@ -35,7 +35,6 @@ def get_video_sources(info):
video_only_sources = []
uni_sources = []
pair_sources = []
- target_resolution = settings.default_resolution
for fmt in info['formats']:
if not all(fmt[attr] for attr in ('ext', 'url')):
continue
@@ -563,7 +562,8 @@ def get_watch_page(video_id=None):
'codecs': codecs_string,
})
- source_info = get_video_sources(info)
+ target_resolution = settings.default_resolution
+ source_info = get_video_sources(info, target_resolution)
uni_sources = source_info['uni_sources']
pair_sources = source_info['pair_sources']
uni_idx, pair_idx = source_info['uni_idx'], source_info['pair_idx']
@@ -577,8 +577,17 @@ def get_watch_page(video_id=None):
pair_quality = yt_data_extract.deep_get(pair_sources, pair_idx, 0,
'quality')
uni_quality = yt_data_extract.deep_get(uni_sources, uni_idx, 'quality')
+ pair_error = abs((pair_quality or 360) - target_resolution)
+ uni_error = abs((uni_quality or 360) - target_resolution)
+ if uni_error == pair_error:
+ # use settings.prefer_uni_sources as a tiebreaker
+ closer_to_target = 'uni' if settings.prefer_uni_sources else 'pair'
+ elif uni_error < pair_error:
+ closer_to_target = 'uni'
+ else:
+ closer_to_target = 'pair'
using_pair_sources = (
- bool(pair_sources) and (not uni_sources or pair_quality != uni_quality)
+ bool(pair_sources) and (not uni_sources or closer_to_target == 'pair')
)
# 1 second per pixel, or the actual video width