]> git.gir.st - subscriptionfeed.git/blob - app/youtube/templates/watch.html.j2
don't load livestreams through proxy for osx(?) devices
[subscriptionfeed.git] / app / youtube / templates / watch.html.j2
1 {% extends "base.html.j2" %}
2 {% import 'macros.imp.j2' as macros %}
3
4 {% block title %}{{ title | e }} — {{ author | e }}{% endblock %}
5
6 {% block content %}
7 {% if video_url %}
8 <div class="aspect-ratio main-video" style="--aspect-ratio:{{ aspectr }}">
9 <video controls poster="{{ poster }}">
10 {% set offset = "#t="~request.args.t|timeoffset if request.args.t else "" %}
11 {% for v in stream_map.muxed|sort(attribute='height', reverse=True) %}
12 <source src="{{v.url}}{{offset}}">
13 {% endfor %}
14 {% set cc_default = False %}
15 {% for cc in subtitles %}
16 <track label="{{ cc.name }}" kind="subtitles" srclang="{{ cc.code }}" src="{{ url_for('youtube.timedtext') }}?{{ cc.query }}" {{ 'default' if cc_default and not loop.counter }}>
17 {% endfor %}
18 {% if '/api/manifest/hls_variant/' in video_url %}{#todo: this is ugly!#}
19 <source src="{{ video_url }}">
20 {% endif %}
21 </video>
22
23 <script>
24 "use strict";
25 var sha256=function a(b){function c(a,b){return a>>>b|a<<32-b}for(var d,e,f=Math.pow,g=f(2,32),h="length",i="",j=[],k=8*b[h],l=a.h=a.h||[],m=a.k=a.k||[],n=m[h],o={},p=2;64>n;p++)if(!o[p]){for(d=0;313>d;d+=p)o[d]=p;l[n]=f(p,.5)*g|0,m[n++]=f(p,1/3)*g|0}for(b+="\x80";b[h]%64-56;)b+="\x00";for(d=0;d<b[h];d++){if(e=b.charCodeAt(d),e>>8)return;j[d>>2]|=e<<(3-d)%4*8}for(j[j[h]]=k/g|0,j[j[h]]=k,e=0;e<j[h];){var q=j.slice(e,e+=16),r=l;for(l=l.slice(0,8),d=0;64>d;d++){var s=q[d-15],t=q[d-2],u=l[0],v=l[4],w=l[7]+(c(v,6)^c(v,11)^c(v,25))+(v&l[5]^~v&l[6])+m[d]+(q[d]=16>d?q[d]:q[d-16]+(c(s,7)^c(s,18)^s>>>3)+q[d-7]+(c(t,17)^c(t,19)^t>>>10)|0),x=(c(u,2)^c(u,13)^c(u,22))+(u&l[1]^u&l[2]^l[1]&l[2]);l=[w+x|0].concat(l),l[4]=l[4]+w|0}for(d=0;8>d;d++)l[d]=l[d]+r[d]|0}for(d=0;8>d;d++)for(e=3;e+1;e--){var y=l[d]>>8*e&255;i+=(16>y?0:"")+y.toString(16)}return i}; /*https://geraintluff.github.io/sha256/sha256.min.js (public domain)*/
26 document.addEventListener('DOMContentLoaded', load_sponsorblock);
27 document.addEventListener('DOMContentLoaded', ()=>{
28 const check = document.querySelector("#skip_sponsors");
29 check.addEventListener("change", () => {if (check.checked) load_sponsorblock()});
30 });
31 function load_sponsorblock(){
32 const video_id = (new URLSearchParams(document.location.search)).get('v');
33 const hash = sha256(video_id).substr(0,4);
34 fetch(`https://sponsor.ajay.app/api/skipSegments/${hash}`)
35 .then(response => response.json())
36 .then(data => {
37 const segments = ((data.find(e => e.videoID == video_id)||{}).segments||[])
38 .filter(e => e.category == "sponsor").map(e => e.segment);
39 document.querySelector('#skip_n').innerText = `; ${segments.length} segments`;
40 for (const [start, end] of segments) {
41 document.querySelector('.main-video video')
42 .addEventListener("timeupdate", function() {
43 if (document.querySelector("#skip_sponsors").checked &&
44 this.currentTime >= start &&
45 this.currentTime < end-1) {
46 this.currentTime = end;
47 }
48 });
49 }
50 });
51 }
52 </script>
53 {% if '/api/manifest/hls_variant/' in video_url %}{#todo: this is ugly!#}
54 <script src="/static/3rd-party/hls.js/hls.min.js"></script>
55 <script>
56 let vid = document.querySelector('video');
57 if (!vid.canPlayType('application/vnd.apple.mpegurl') && Hls.isSupported()) {
58 var hls = new Hls();
59 let source = new URL(document.querySelector("source").src).pathname;
60 hls.loadSource(source);
61 hls.attachMedia(vid);
62 }
63 </script>
64 {% endif %}
65
66 </div>
67 {% else %}{#TODO: this'll break livestreams #}
68 <img src="{{ poster }}" style="width:100%;object-fit:cover;height:calc(100% / {{ aspectr }});">
69 {% endif %}
70
71 {% if video_error %}
72 <div class="video_error">
73 {{ errdetails }} Watch on <a href="{{ invidious_url }}">Invidious</a> or <a href="https://www.youtube.com/watch?v={{ video_id }}">Youtube</a>
74 </div>
75 {% endif %}
76
77 <h1>{{ title | e }}<br>
78 <small><a href="/channel/{{ channel_id }}/">{{ author | e }}</a></small></h1>
79
80 <details><summary>Description</summary>
81 <p style="white-space:pre-wrap">{{ description | e }}</p>
82 </details>
83
84 <details><summary>Metadata</summary>
85 <dl>
86 <dt>Duration
87 <dd>{{ length | format_time }}
88 <dt>Views
89 <dd>{{ '{0:,}'.format(views | int)|replace(",","&thinsp;") }}
90 <dt>Published
91 <dd>{{ published.split('T')[0] }}
92 <dt>Rating
93 <dd>{{ rating | round(1) }}/5
94 <dt>Visibility
95 <dd>{{ 'unlisted' if unlisted else 'public' }}
96 {% if blacklisted|length == 0 %}
97 <dt>Available in
98 <dd>all regions
99 {% elif whitelisted|length == 0 %}
100 <dt>Blacklisted in
101 <dd>all regions
102 {% elif blacklisted|length > whitelisted|length %}
103 <dt>Available in
104 <dd>{{ whitelisted | join(', ') }}
105 {% else %}
106 <dt>Blacklisted in
107 <dd>{{ blacklisted | join(', ') }}
108 {% endif %}
109 </dl>
110 </details>
111
112 <details><summary>More Actions</summary>
113 <ul class="more-actions">
114 <li><label><input type=checkbox id=skip_sponsors checked>skip sponsors</label> (with <a href="https://sponsor.ajay.app">SponsorBlock</a><span id=skip_n></span>)
115 <noscript><br>Note: requires javascript</noscript>
116 {# TODO: don't redirect away (204 response?) #}
117 <li>{{ macros.emoji_link("audio", video_id, True) }}
118 <li>{{ macros.emoji_button("pin", video_id, is_pinned, True) }}
119 <li>{{ macros.emoji_button("subscribe", channel_id, is_subscribed, True) }}
120 <li>{{ macros.emoji_link("raw", video_id, True) }}
121 <li>{{ macros.emoji_link("json", video_id, True) }}
122 <li><a href="https://invidious.snopyta.org/watch?v={{ video_id }}">watch on invidious</a>
123 <li><a href="https://youtu.be/{{ video_id }}">youtu.be</a>
124 | <a href="https://www.youtube-nocookie.com/embed/{{ video_id }}">embed</a>
125 </ul>
126 </details>
127
128 <details><summary>Info- and Endcards</summary>
129 <div class="cards">
130 {% for card in all_cards %} {# Note: no point in displaying the current channels's channel card #}
131 {{ macros.typed_card(card) if not (card.type == 'CHANNEL' and card.content.channel_id == channel_id) }}
132 {% endfor %}
133 {{ macros.dummycard() }}
134 </div>
135 </details>
136 {% endblock %}
Imprint / Impressum