]> Raphaël G. Git Repositories - youtubedl/blob - test/test_youtube_chapters.py
cb12f83848949524cffb88e53b4f25d0be8eb42e
[youtubedl] / test / test_youtube_chapters.py
1 #!/usr/bin/env python
2 # coding: utf-8
3 from __future__ import unicode_literals
4
5 # Allow direct execution
6 import os
7 import sys
8 import unittest
9 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
11 from test.helper import expect_value
12 from youtube_dl.extractor import YoutubeIE
13
14
15 class TestYoutubeChapters(unittest.TestCase):
16
17 _TEST_CASES = [
18 (
19 # https://www.youtube.com/watch?v=A22oy8dFjqc
20 # pattern: 00:00 - <title>
21 '''This is the absolute ULTIMATE experience of Queen's set at LIVE AID, this is the best video mixed to the absolutely superior stereo radio broadcast. This vastly superior audio mix takes a huge dump on all of the official mixes. Best viewed in 1080p. ENJOY! ***MAKE SURE TO READ THE DESCRIPTION***<br /><a href="#" onclick="yt.www.watch.player.seekTo(00*60+36);return false;">00:36</a> - Bohemian Rhapsody<br /><a href="#" onclick="yt.www.watch.player.seekTo(02*60+42);return false;">02:42</a> - Radio Ga Ga<br /><a href="#" onclick="yt.www.watch.player.seekTo(06*60+53);return false;">06:53</a> - Ay Oh!<br /><a href="#" onclick="yt.www.watch.player.seekTo(07*60+34);return false;">07:34</a> - Hammer To Fall<br /><a href="#" onclick="yt.www.watch.player.seekTo(12*60+08);return false;">12:08</a> - Crazy Little Thing Called Love<br /><a href="#" onclick="yt.www.watch.player.seekTo(16*60+03);return false;">16:03</a> - We Will Rock You<br /><a href="#" onclick="yt.www.watch.player.seekTo(17*60+18);return false;">17:18</a> - We Are The Champions<br /><a href="#" onclick="yt.www.watch.player.seekTo(21*60+12);return false;">21:12</a> - Is This The World We Created...?<br /><br />Short song analysis:<br /><br />- "Bohemian Rhapsody": Although it's a short medley version, it's one of the best performances of the ballad section, with Freddie nailing the Bb4s with the correct studio phrasing (for the first time ever!).<br /><br />- "Radio Ga Ga": Although it's missing one chorus, this is one of - if not the best - the best versions ever, Freddie nails all the Bb4s and sounds very clean! Spike Edney's Roland Jupiter 8 also really shines through on this mix, compared to the DVD releases!<br /><br />- "Audience Improv": A great improv, Freddie sounds strong and confident. You gotta love when he sustains that A4 for 4 seconds!<br /><br />- "Hammer To Fall": Despite missing a verse and a chorus, it's a strong version (possibly the best ever). Freddie sings the song amazingly, and even ad-libs a C#5 and a C5! Also notice how heavy Brian's guitar sounds compared to the thin DVD mixes - it roars!<br /><br />- "Crazy Little Thing Called Love": A great version, the crowd loves the song, the jam is great as well! Only downside to this is the slight feedback issues.<br /><br />- "We Will Rock You": Although cut down to the 1st verse and chorus, Freddie sounds strong. He nails the A4, and the solo from Dr. May is brilliant!<br /><br />- "We Are the Champions": Perhaps the high-light of the performance - Freddie is very daring on this version, he sustains the pre-chorus Bb4s, nails the 1st C5, belts great A4s, but most importantly: He nails the chorus Bb4s, in all 3 choruses! This is the only time he has ever done so! It has to be said though, the last one sounds a bit rough, but that's a side effect of belting high notes for the past 18 minutes, with nodules AND laryngitis!<br /><br />- "Is This The World We Created... ?": Freddie and Brian perform a beautiful version of this, and it is one of the best versions ever. It's both sad and hilarious that a couple of BBC engineers are talking over the song, one of them being completely oblivious of the fact that he is interrupting the performance, on live television... Which was being televised to almost 2 billion homes.<br /><br /><br />All rights go to their respective owners!<br />-----Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use''',
22 1477,
23 [{
24 'start_time': 36,
25 'end_time': 162,
26 'title': 'Bohemian Rhapsody',
27 }, {
28 'start_time': 162,
29 'end_time': 413,
30 'title': 'Radio Ga Ga',
31 }, {
32 'start_time': 413,
33 'end_time': 454,
34 'title': 'Ay Oh!',
35 }, {
36 'start_time': 454,
37 'end_time': 728,
38 'title': 'Hammer To Fall',
39 }, {
40 'start_time': 728,
41 'end_time': 963,
42 'title': 'Crazy Little Thing Called Love',
43 }, {
44 'start_time': 963,
45 'end_time': 1038,
46 'title': 'We Will Rock You',
47 }, {
48 'start_time': 1038,
49 'end_time': 1272,
50 'title': 'We Are The Champions',
51 }, {
52 'start_time': 1272,
53 'end_time': 1477,
54 'title': 'Is This The World We Created...?',
55 }]
56 ),
57 (
58 # https://www.youtube.com/watch?v=ekYlRhALiRQ
59 # pattern: <num>. <title> 0:00
60 '1. Those Beaten Paths of Confusion <a href="#" onclick="yt.www.watch.player.seekTo(0*60+00);return false;">0:00</a><br />2. Beyond the Shadows of Emptiness & Nothingness <a href="#" onclick="yt.www.watch.player.seekTo(11*60+47);return false;">11:47</a><br />3. Poison Yourself...With Thought <a href="#" onclick="yt.www.watch.player.seekTo(26*60+30);return false;">26:30</a><br />4. The Agents of Transformation <a href="#" onclick="yt.www.watch.player.seekTo(35*60+57);return false;">35:57</a><br />5. Drowning in the Pain of Consciousness <a href="#" onclick="yt.www.watch.player.seekTo(44*60+32);return false;">44:32</a><br />6. Deny the Disease of Life <a href="#" onclick="yt.www.watch.player.seekTo(53*60+07);return false;">53:07</a><br /><br />More info/Buy: http://crepusculonegro.storenvy.com/products/257645-cn-03-arizmenda-within-the-vacuum-of-infinity<br /><br />No copyright is intended. The rights to this video are assumed by the owner and its affiliates.',
61 4009,
62 [{
63 'start_time': 0,
64 'end_time': 707,
65 'title': '1. Those Beaten Paths of Confusion',
66 }, {
67 'start_time': 707,
68 'end_time': 1590,
69 'title': '2. Beyond the Shadows of Emptiness & Nothingness',
70 }, {
71 'start_time': 1590,
72 'end_time': 2157,
73 'title': '3. Poison Yourself...With Thought',
74 }, {
75 'start_time': 2157,
76 'end_time': 2672,
77 'title': '4. The Agents of Transformation',
78 }, {
79 'start_time': 2672,
80 'end_time': 3187,
81 'title': '5. Drowning in the Pain of Consciousness',
82 }, {
83 'start_time': 3187,
84 'end_time': 4009,
85 'title': '6. Deny the Disease of Life',
86 }]
87 ),
88 (
89 # https://www.youtube.com/watch?v=WjL4pSzog9w
90 # pattern: 00:00 <title>
91 '<a href="https://arizmenda.bandcamp.com/merch/despairs-depths-descended-cd" class="yt-uix-servicelink " data-target-new-window="True" data-servicelink="CDAQ6TgYACITCNf1raqT2dMCFdRjGAod_o0CBSj4HQ" data-url="https://arizmenda.bandcamp.com/merch/despairs-depths-descended-cd" rel="nofollow noopener" target="_blank">https://arizmenda.bandcamp.com/merch/...</a><br /><br /><a href="#" onclick="yt.www.watch.player.seekTo(00*60+00);return false;">00:00</a> Christening Unborn Deformities <br /><a href="#" onclick="yt.www.watch.player.seekTo(07*60+08);return false;">07:08</a> Taste of Purity<br /><a href="#" onclick="yt.www.watch.player.seekTo(16*60+16);return false;">16:16</a> Sculpting Sins of a Universal Tongue<br /><a href="#" onclick="yt.www.watch.player.seekTo(24*60+45);return false;">24:45</a> Birth<br /><a href="#" onclick="yt.www.watch.player.seekTo(31*60+24);return false;">31:24</a> Neves<br /><a href="#" onclick="yt.www.watch.player.seekTo(37*60+55);return false;">37:55</a> Libations in Limbo',
92 2705,
93 [{
94 'start_time': 0,
95 'end_time': 428,
96 'title': 'Christening Unborn Deformities',
97 }, {
98 'start_time': 428,
99 'end_time': 976,
100 'title': 'Taste of Purity',
101 }, {
102 'start_time': 976,
103 'end_time': 1485,
104 'title': 'Sculpting Sins of a Universal Tongue',
105 }, {
106 'start_time': 1485,
107 'end_time': 1884,
108 'title': 'Birth',
109 }, {
110 'start_time': 1884,
111 'end_time': 2275,
112 'title': 'Neves',
113 }, {
114 'start_time': 2275,
115 'end_time': 2705,
116 'title': 'Libations in Limbo',
117 }]
118 ),
119 (
120 # https://www.youtube.com/watch?v=o3r1sn-t3is
121 # pattern: <title> 00:00 <note>
122 'Download this show in MP3: <a href="http://sh.st/njZKK" class="yt-uix-servicelink " data-url="http://sh.st/njZKK" data-target-new-window="True" data-servicelink="CDAQ6TgYACITCK3j8_6o2dMCFVDCGAoduVAKKij4HQ" rel="nofollow noopener" target="_blank">http://sh.st/njZKK</a><br /><br />Setlist:<br />I-E-A-I-A-I-O <a href="#" onclick="yt.www.watch.player.seekTo(00*60+45);return false;">00:45</a><br />Suite-Pee <a href="#" onclick="yt.www.watch.player.seekTo(4*60+26);return false;">4:26</a> (Incomplete)<br />Attack <a href="#" onclick="yt.www.watch.player.seekTo(5*60+31);return false;">5:31</a> (First live performance since 2011)<br />Prison Song <a href="#" onclick="yt.www.watch.player.seekTo(8*60+42);return false;">8:42</a><br />Know <a href="#" onclick="yt.www.watch.player.seekTo(12*60+32);return false;">12:32</a> (First live performance since 2011)<br />Aerials <a href="#" onclick="yt.www.watch.player.seekTo(15*60+32);return false;">15:32</a><br />Soldier Side - Intro <a href="#" onclick="yt.www.watch.player.seekTo(19*60+13);return false;">19:13</a><br />B.Y.O.B. <a href="#" onclick="yt.www.watch.player.seekTo(20*60+09);return false;">20:09</a><br />Soil <a href="#" onclick="yt.www.watch.player.seekTo(24*60+32);return false;">24:32</a><br />Darts <a href="#" onclick="yt.www.watch.player.seekTo(27*60+48);return false;">27:48</a><br />Radio/Video <a href="#" onclick="yt.www.watch.player.seekTo(30*60+38);return false;">30:38</a><br />Hypnotize <a href="#" onclick="yt.www.watch.player.seekTo(35*60+05);return false;">35:05</a><br />Temper <a href="#" onclick="yt.www.watch.player.seekTo(38*60+08);return false;">38:08</a> (First live performance since 1999)<br />CUBErt <a href="#" onclick="yt.www.watch.player.seekTo(41*60+00);return false;">41:00</a><br />Needles <a href="#" onclick="yt.www.watch.player.seekTo(42*60+57);return false;">42:57</a><br />Deer Dance <a href="#" onclick="yt.www.watch.player.seekTo(46*60+27);return false;">46:27</a><br />Bounce <a href="#" onclick="yt.www.watch.player.seekTo(49*60+38);return false;">49:38</a><br />Suggestions <a href="#" onclick="yt.www.watch.player.seekTo(51*60+25);return false;">51:25</a><br />Psycho <a href="#" onclick="yt.www.watch.player.seekTo(53*60+52);return false;">53:52</a><br />Chop Suey! <a href="#" onclick="yt.www.watch.player.seekTo(58*60+13);return false;">58:13</a><br />Lonely Day <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+01*60+15);return false;">1:01:15</a><br />Question! <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+04*60+14);return false;">1:04:14</a><br />Lost in Hollywood <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+08*60+10);return false;">1:08:10</a><br />Vicinity of Obscenity <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+13*60+40);return false;">1:13:40</a>(First live performance since 2012)<br />Forest <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+16*60+17);return false;">1:16:17</a><br />Cigaro <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+20*60+02);return false;">1:20:02</a><br />Toxicity <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+23*60+57);return false;">1:23:57</a>(with Chino Moreno)<br />Sugar <a href="#" onclick="yt.www.watch.player.seekTo(1*3600+27*60+53);return false;">1:27:53</a>',
123 5640,
124 [{
125 'start_time': 45,
126 'end_time': 266,
127 'title': 'I-E-A-I-A-I-O',
128 }, {
129 'start_time': 266,
130 'end_time': 331,
131 'title': 'Suite-Pee (Incomplete)',
132 }, {
133 'start_time': 331,
134 'end_time': 522,
135 'title': 'Attack (First live performance since 2011)',
136 }, {
137 'start_time': 522,
138 'end_time': 752,
139 'title': 'Prison Song',
140 }, {
141 'start_time': 752,
142 'end_time': 932,
143 'title': 'Know (First live performance since 2011)',
144 }, {
145 'start_time': 932,
146 'end_time': 1153,
147 'title': 'Aerials',
148 }, {
149 'start_time': 1153,
150 'end_time': 1209,
151 'title': 'Soldier Side - Intro',
152 }, {
153 'start_time': 1209,
154 'end_time': 1472,
155 'title': 'B.Y.O.B.',
156 }, {
157 'start_time': 1472,
158 'end_time': 1668,
159 'title': 'Soil',
160 }, {
161 'start_time': 1668,
162 'end_time': 1838,
163 'title': 'Darts',
164 }, {
165 'start_time': 1838,
166 'end_time': 2105,
167 'title': 'Radio/Video',
168 }, {
169 'start_time': 2105,
170 'end_time': 2288,
171 'title': 'Hypnotize',
172 }, {
173 'start_time': 2288,
174 'end_time': 2460,
175 'title': 'Temper (First live performance since 1999)',
176 }, {
177 'start_time': 2460,
178 'end_time': 2577,
179 'title': 'CUBErt',
180 }, {
181 'start_time': 2577,
182 'end_time': 2787,
183 'title': 'Needles',
184 }, {
185 'start_time': 2787,
186 'end_time': 2978,
187 'title': 'Deer Dance',
188 }, {
189 'start_time': 2978,
190 'end_time': 3085,
191 'title': 'Bounce',
192 }, {
193 'start_time': 3085,
194 'end_time': 3232,
195 'title': 'Suggestions',
196 }, {
197 'start_time': 3232,
198 'end_time': 3493,
199 'title': 'Psycho',
200 }, {
201 'start_time': 3493,
202 'end_time': 3675,
203 'title': 'Chop Suey!',
204 }, {
205 'start_time': 3675,
206 'end_time': 3854,
207 'title': 'Lonely Day',
208 }, {
209 'start_time': 3854,
210 'end_time': 4090,
211 'title': 'Question!',
212 }, {
213 'start_time': 4090,
214 'end_time': 4420,
215 'title': 'Lost in Hollywood',
216 }, {
217 'start_time': 4420,
218 'end_time': 4577,
219 'title': 'Vicinity of Obscenity (First live performance since 2012)',
220 }, {
221 'start_time': 4577,
222 'end_time': 4802,
223 'title': 'Forest',
224 }, {
225 'start_time': 4802,
226 'end_time': 5037,
227 'title': 'Cigaro',
228 }, {
229 'start_time': 5037,
230 'end_time': 5273,
231 'title': 'Toxicity (with Chino Moreno)',
232 }, {
233 'start_time': 5273,
234 'end_time': 5640,
235 'title': 'Sugar',
236 }]
237 ),
238 (
239 # https://www.youtube.com/watch?v=PkYLQbsqCE8
240 # pattern: <num> - <title> [<latinized title>] 0:00:00
241 '''Затемно (Zatemno) is an Obscure Black Metal Band from Russia.<br /><br />"Во прах (Vo prakh)'' Into The Ashes", Debut mini-album released may 6, 2016, by Death Knell Productions<br />Released on 6 panel digipak CD, limited to 100 copies only<br />And digital format on Bandcamp<br /><br />Tracklist<br /><br />1 - Во прах [Vo prakh] <a href="#" onclick="yt.www.watch.player.seekTo(0*3600+00*60+00);return false;">0:00:00</a><br />2 - Искупление [Iskupleniye] <a href="#" onclick="yt.www.watch.player.seekTo(0*3600+08*60+10);return false;">0:08:10</a><br />3 - Из серпов луны...[Iz serpov luny] <a href="#" onclick="yt.www.watch.player.seekTo(0*3600+14*60+30);return false;">0:14:30</a><br /><br />Links:<br /><a href="https://deathknellprod.bandcamp.com/album/--2" class="yt-uix-servicelink " data-target-new-window="True" data-url="https://deathknellprod.bandcamp.com/album/--2" data-servicelink="CC8Q6TgYACITCNP234Kr2dMCFcNxGAodQqsIwSj4HQ" target="_blank" rel="nofollow noopener">https://deathknellprod.bandcamp.com/a...</a><br /><a href="https://www.facebook.com/DeathKnellProd/" class="yt-uix-servicelink " data-target-new-window="True" data-url="https://www.facebook.com/DeathKnellProd/" data-servicelink="CC8Q6TgYACITCNP234Kr2dMCFcNxGAodQqsIwSj4HQ" target="_blank" rel="nofollow noopener">https://www.facebook.com/DeathKnellProd/</a><br /><br /><br />I don't have any right about this artifact, my only intention is to spread the music of the band, all rights are reserved to the Затемно (Zatemno) and his producers, Death Knell Productions.<br /><br />------------------------------------------------------------------<br /><br />Subscribe for more videos like this.<br />My link: <a href="https://web.facebook.com/AttackOfTheDragons" class="yt-uix-servicelink " data-target-new-window="True" data-url="https://web.facebook.com/AttackOfTheDragons" data-servicelink="CC8Q6TgYACITCNP234Kr2dMCFcNxGAodQqsIwSj4HQ" target="_blank" rel="nofollow noopener">https://web.facebook.com/AttackOfTheD...</a>''',
242 1138,
243 [{
244 'start_time': 0,
245 'end_time': 490,
246 'title': '1 - Во прах [Vo prakh]',
247 }, {
248 'start_time': 490,
249 'end_time': 870,
250 'title': '2 - Искупление [Iskupleniye]',
251 }, {
252 'start_time': 870,
253 'end_time': 1138,
254 'title': '3 - Из серпов луны...[Iz serpov luny]',
255 }]
256 ),
257 ]
258
259 def test_youtube_chapters(self):
260 for description, duration, expected_chapters in self._TEST_CASES:
261 ie = YoutubeIE()
262 expect_value(
263 self, ie._extract_chapters(description, duration),
264 expected_chapters, None)
265
266
267 if __name__ == '__main__':
268 unittest.main()