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