diff options
author | James Taylor <user234683@users.noreply.github.com> | 2021-08-23 19:50:57 -0700 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-08-29 20:52:57 -0500 |
commit | a7da23c6da411442dc4ef6af91447820d0b0e517 (patch) | |
tree | 811186bcf0bfbc7a175af6efbaaf955413a5f522 /youtube/templates/watch.html | |
parent | c9a75042d24ed969e0cf5ae0d7b76ccb3c41a93b (diff) | |
download | yt-local-a7da23c6da411442dc4ef6af91447820d0b0e517.tar.lz yt-local-a7da23c6da411442dc4ef6af91447820d0b0e517.tar.xz yt-local-a7da23c6da411442dc4ef6af91447820d0b0e517.zip |
Add video quality selector
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/templates/watch.html')
-rw-r--r-- | youtube/templates/watch.html | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html index 9d7a36c..2c85e16 100644 --- a/youtube/templates/watch.html +++ b/youtube/templates/watch.html @@ -55,8 +55,17 @@ </video> </figure> - {% if pair_sources and (not uni_sources or pair_sources[pair_idx][0]['quality'] != uni_sources[uni_idx]['quality']) %} - <script src="/youtube.com/static/js/av-merge.js"></script> + <script src="/youtube.com/static/js/av-merge.js"></script> + {% if using_pair_sources %} + <!-- Initialize av-merge --> + <script> + var srcPair = data['pair_sources'][data['pair_idx']]; + var video = document.getElementById('js-video-player'); + var videoSource = srcPair[0]; + // Do it dynamically rather than as the default in jinja + // in case javascript is disabled + avInitialize(video, srcPair, 0); + </script> {% endif %} {% if time_start != 0 %} @@ -93,8 +102,41 @@ <div class="external-player-controls"> <input class="speed" id="speed-control" type="text" title="Video speed"> <script src="/youtube.com/static/js/speedyplay.js"></script> + <select id="quality-select"> + {% for src in uni_sources %} + <option value='{"type": "uni", "index": {{ loop.index0 }}}' {{ 'selected' if loop.index0 == uni_idx and not using_pair_sources else '' }} >{{ src['quality_string'] }} (integrated)</option> + {% endfor %} + {% for src_pair in pair_sources %} + <option value='{"type": "pair", "index": {{ loop.index0}}}' {{ 'selected' if loop.index0 == pair_idx and using_pair_sources else '' }} >{{ src_pair[0]['quality_string'] }}, {{ src_pair[1]['quality_string'] }}</option> + {% endfor %} + </select> + <script> + document.getElementById('quality-select').addEventListener( + 'change', function(e) { + var video = document.getElementById('js-video-player'); + var selection = JSON.parse(this.value); + var currentVideoTime = video.currentTime; + var videoPaused = video.paused; + var videoSpeed = video.playbackRate; + var videoSource; + if (selection.type == 'uni'){ + videoSource = data['uni_sources'][selection.index]; + video.src = videoSource.url; + } else { + let srcPair = data['pair_sources'][selection.index]; + videoSource = srcPair[0]; + avInitialize(video, srcPair, currentVideoTime); + } + setVideoDimensions(videoSource.height, videoSource.width); + video.currentTime = currentVideoTime; + if (!videoPaused){ + video.play(); + } + video.playbackRate = videoSpeed; + } + ); + </script> </div> - <input class="v-checkbox" name="video_info_list" value="{{ video_info }}" form="playlist-edit" type="checkbox"> <span class="v-direct-link"><a href="https://youtu.be/{{ video_id }}" rel="noopener noreferrer" target="_blank">Direct Link</a></span> |