]> git.gir.st - subscriptionfeed.git/blob - app/youtube/templates/watch.html.j2
add youtube-nocookie link
[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 </video>
19
20 <script>
21 "use strict";
22 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)*/
23 document.addEventListener('DOMContentLoaded', load_sponsorblock);
24 document.addEventListener('DOMContentLoaded', ()=>{
25 const check = document.querySelector("#skip_sponsors");
26 check.addEventListener("change", () => {if (check.checked) load_sponsorblock()});
27 });
28 function load_sponsorblock(){
29 const video_id = (new URLSearchParams(document.location.search)).get('v');
30 const hash = sha256(video_id).substr(0,4);
31 fetch(`https://sponsor.ajay.app/api/skipSegments/${hash}`)
32 .then(response => response.json())
33 .then(data => {
34 const segments = ((data.find(e => e.videoID == video_id)||{}).segments||[])
35 .filter(e => e.category == "sponsor").map(e => e.segment);
36 document.querySelector('#skip_n').innerText = `; ${segments.length} segments`;
37 for (const [start, end] of segments) {
38 document.querySelector('.main-video video')
39 .addEventListener("timeupdate", function() {
40 if (document.querySelector("#skip_sponsors").checked &&
41 this.currentTime >= start &&
42 this.currentTime < end-1) {
43 this.currentTime = end;
44 }
45 });
46 }
47 });
48 }
49 </script>
50
51 </div>
52 {% else %}{#TODO: this'll break livestreams #}
53 <img src="{{ poster }}" style="width:100%;object-fit:cover;height:calc(100% / {{ aspectr }});">
54 {% endif %}
55
56 {% if video_error %}
57 <div class="video_error">
58 {{ errdetails }} Watch on <a href="{{ invidious_url }}">Invidious</a> or <a href="https://www.youtube.com/watch?v={{ video_id }}">Youtube</a>
59 </div>
60 {% endif %}
61
62 <h1>{{ title | e }}<br>
63 <small><a href="/channel/{{ channel_id }}/">{{ author | e }}</a></small></h1>
64
65 <details><summary>Description</summary>
66 <p style="white-space:pre-wrap">{{ description | e }}</p>
67 </details>
68
69 <details><summary>Metadata</summary>
70 <dl>
71 <dt>Duration
72 <dd>{{ length | format_time }}
73 <dt>Views
74 <dd>{{ '{0:,}'.format(views | int)|replace(",","&thinsp;") }}
75 <dt>Published
76 <dd>{{ published.split('T')[0] }}
77 <dt>Rating
78 <dd>{{ rating | round(1) }}/5
79 <dt>Visibility
80 <dd>{{ 'unlisted' if unlisted else 'public' }}
81 {% if blacklisted|length == 0 %}
82 <dt>Available in
83 <dd>all regions
84 {% elif whitelisted|length == 0 %}
85 <dt>Blacklisted in
86 <dd>all regions
87 {% elif blacklisted|length > whitelisted|length %}
88 <dt>Available in
89 <dd>{{ whitelisted | join(', ') }}
90 {% else %}
91 <dt>Blacklisted in
92 <dd>{{ blacklisted | join(', ') }}
93 {% endif %}
94 </dl>
95 </details>
96
97 <details><summary>More Actions</summary>
98 <ul class="more-actions">
99 <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>)
100 <noscript><br>Note: requires javascript</noscript>
101 {# TODO: don't redirect away (204 response?) #}
102 <li>{{ macros.emoji_link("audio", video_id, True) }}
103 <li>{{ macros.emoji_button("pin", video_id, is_pinned, True) }}
104 <li>{{ macros.emoji_button("subscribe", channel_id, is_subscribed, True) }}
105 <li>{{ macros.emoji_link("raw", video_id, True) }}
106 <li>{{ macros.emoji_link("json", video_id, True) }}
107 <li><a href="https://invidious.snopyta.org/watch?v={{ video_id }}">watch on invidious</a>
108 <li><a href="https://youtu.be/{{ video_id }}">youtu.be</a>
109 | <a href="https://www.youtube-nocookie.com/embed/{{ video_id }}">embed</a>
110 </ul>
111 </details>
112
113 <details><summary>Info- and Endcards</summary>
114 <div class="cards">
115 {% for card in all_cards %} {# Note: no point in displaying the current channels's channel card #}
116 {{ macros.typed_card(card) if not (card.type == 'CHANNEL' and card.content.channel_id == channel_id) }}
117 {% endfor %}
118 {{ macros.dummycard() }}
119 </div>
120 </details>
121 {% endblock %}
Imprint / Impressum