test_youtube_chapters.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from __future__ import unicode_literals
  4. # Allow direct execution
  5. import os
  6. import sys
  7. import unittest
  8. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  9. from test.helper import expect_value
  10. from youtube_dl.extractor import YoutubeIE
  11. class TestYoutubeChapters(unittest.TestCase):
  12. _TEST_CASES = [
  13. (
  14. # https://www.youtube.com/watch?v=A22oy8dFjqc
  15. # pattern: 00:00 - <title>
  16. '''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''',
  17. 1477,
  18. [{
  19. 'start_time': 36,
  20. 'end_time': 162,
  21. 'title': 'Bohemian Rhapsody',
  22. }, {
  23. 'start_time': 162,
  24. 'end_time': 413,
  25. 'title': 'Radio Ga Ga',
  26. }, {
  27. 'start_time': 413,
  28. 'end_time': 454,
  29. 'title': 'Ay Oh!',
  30. }, {
  31. 'start_time': 454,
  32. 'end_time': 728,
  33. 'title': 'Hammer To Fall',
  34. }, {
  35. 'start_time': 728,
  36. 'end_time': 963,
  37. 'title': 'Crazy Little Thing Called Love',
  38. }, {
  39. 'start_time': 963,
  40. 'end_time': 1038,
  41. 'title': 'We Will Rock You',
  42. }, {
  43. 'start_time': 1038,
  44. 'end_time': 1272,
  45. 'title': 'We Are The Champions',
  46. }, {
  47. 'start_time': 1272,
  48. 'end_time': 1477,
  49. 'title': 'Is This The World We Created...?',
  50. }]
  51. ),
  52. (
  53. # https://www.youtube.com/watch?v=ekYlRhALiRQ
  54. # pattern: <num>. <title> 0:00
  55. '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.',
  56. 4009,
  57. [{
  58. 'start_time': 0,
  59. 'end_time': 707,
  60. 'title': '1. Those Beaten Paths of Confusion',
  61. }, {
  62. 'start_time': 707,
  63. 'end_time': 1590,
  64. 'title': '2. Beyond the Shadows of Emptiness & Nothingness',
  65. }, {
  66. 'start_time': 1590,
  67. 'end_time': 2157,
  68. 'title': '3. Poison Yourself...With Thought',
  69. }, {
  70. 'start_time': 2157,
  71. 'end_time': 2672,
  72. 'title': '4. The Agents of Transformation',
  73. }, {
  74. 'start_time': 2672,
  75. 'end_time': 3187,
  76. 'title': '5. Drowning in the Pain of Consciousness',
  77. }, {
  78. 'start_time': 3187,
  79. 'end_time': 4009,
  80. 'title': '6. Deny the Disease of Life',
  81. }]
  82. ),
  83. (
  84. # https://www.youtube.com/watch?v=WjL4pSzog9w
  85. # pattern: 00:00 <title>
  86. '<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',
  87. 2705,
  88. [{
  89. 'start_time': 0,
  90. 'end_time': 428,
  91. 'title': 'Christening Unborn Deformities',
  92. }, {
  93. 'start_time': 428,
  94. 'end_time': 976,
  95. 'title': 'Taste of Purity',
  96. }, {
  97. 'start_time': 976,
  98. 'end_time': 1485,
  99. 'title': 'Sculpting Sins of a Universal Tongue',
  100. }, {
  101. 'start_time': 1485,
  102. 'end_time': 1884,
  103. 'title': 'Birth',
  104. }, {
  105. 'start_time': 1884,
  106. 'end_time': 2275,
  107. 'title': 'Neves',
  108. }, {
  109. 'start_time': 2275,
  110. 'end_time': 2705,
  111. 'title': 'Libations in Limbo',
  112. }]
  113. ),
  114. (
  115. # https://www.youtube.com/watch?v=o3r1sn-t3is
  116. # pattern: <title> 00:00 <note>
  117. '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>',
  118. 5640,
  119. [{
  120. 'start_time': 45,
  121. 'end_time': 266,
  122. 'title': 'I-E-A-I-A-I-O',
  123. }, {
  124. 'start_time': 266,
  125. 'end_time': 331,
  126. 'title': 'Suite-Pee (Incomplete)',
  127. }, {
  128. 'start_time': 331,
  129. 'end_time': 522,
  130. 'title': 'Attack (First live performance since 2011)',
  131. }, {
  132. 'start_time': 522,
  133. 'end_time': 752,
  134. 'title': 'Prison Song',
  135. }, {
  136. 'start_time': 752,
  137. 'end_time': 932,
  138. 'title': 'Know (First live performance since 2011)',
  139. }, {
  140. 'start_time': 932,
  141. 'end_time': 1153,
  142. 'title': 'Aerials',
  143. }, {
  144. 'start_time': 1153,
  145. 'end_time': 1209,
  146. 'title': 'Soldier Side - Intro',
  147. }, {
  148. 'start_time': 1209,
  149. 'end_time': 1472,
  150. 'title': 'B.Y.O.B.',
  151. }, {
  152. 'start_time': 1472,
  153. 'end_time': 1668,
  154. 'title': 'Soil',
  155. }, {
  156. 'start_time': 1668,
  157. 'end_time': 1838,
  158. 'title': 'Darts',
  159. }, {
  160. 'start_time': 1838,
  161. 'end_time': 2105,
  162. 'title': 'Radio/Video',
  163. }, {
  164. 'start_time': 2105,
  165. 'end_time': 2288,
  166. 'title': 'Hypnotize',
  167. }, {
  168. 'start_time': 2288,
  169. 'end_time': 2460,
  170. 'title': 'Temper (First live performance since 1999)',
  171. }, {
  172. 'start_time': 2460,
  173. 'end_time': 2577,
  174. 'title': 'CUBErt',
  175. }, {
  176. 'start_time': 2577,
  177. 'end_time': 2787,
  178. 'title': 'Needles',
  179. }, {
  180. 'start_time': 2787,
  181. 'end_time': 2978,
  182. 'title': 'Deer Dance',
  183. }, {
  184. 'start_time': 2978,
  185. 'end_time': 3085,
  186. 'title': 'Bounce',
  187. }, {
  188. 'start_time': 3085,
  189. 'end_time': 3232,
  190. 'title': 'Suggestions',
  191. }, {
  192. 'start_time': 3232,
  193. 'end_time': 3493,
  194. 'title': 'Psycho',
  195. }, {
  196. 'start_time': 3493,
  197. 'end_time': 3675,
  198. 'title': 'Chop Suey!',
  199. }, {
  200. 'start_time': 3675,
  201. 'end_time': 3854,
  202. 'title': 'Lonely Day',
  203. }, {
  204. 'start_time': 3854,
  205. 'end_time': 4090,
  206. 'title': 'Question!',
  207. }, {
  208. 'start_time': 4090,
  209. 'end_time': 4420,
  210. 'title': 'Lost in Hollywood',
  211. }, {
  212. 'start_time': 4420,
  213. 'end_time': 4577,
  214. 'title': 'Vicinity of Obscenity (First live performance since 2012)',
  215. }, {
  216. 'start_time': 4577,
  217. 'end_time': 4802,
  218. 'title': 'Forest',
  219. }, {
  220. 'start_time': 4802,
  221. 'end_time': 5037,
  222. 'title': 'Cigaro',
  223. }, {
  224. 'start_time': 5037,
  225. 'end_time': 5273,
  226. 'title': 'Toxicity (with Chino Moreno)',
  227. }, {
  228. 'start_time': 5273,
  229. 'end_time': 5640,
  230. 'title': 'Sugar',
  231. }]
  232. ),
  233. (
  234. # https://www.youtube.com/watch?v=PkYLQbsqCE8
  235. # pattern: <num> - <title> [<latinized title>] 0:00:00
  236. '''Затемно (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>''',
  237. 1138,
  238. [{
  239. 'start_time': 0,
  240. 'end_time': 490,
  241. 'title': '1 - Во прах [Vo prakh]',
  242. }, {
  243. 'start_time': 490,
  244. 'end_time': 870,
  245. 'title': '2 - Искупление [Iskupleniye]',
  246. }, {
  247. 'start_time': 870,
  248. 'end_time': 1138,
  249. 'title': '3 - Из серпов луны...[Iz serpov luny]',
  250. }]
  251. ),
  252. (
  253. # https://www.youtube.com/watch?v=xZW70zEasOk
  254. # time point more than duration
  255. '''● LCS Spring finals: Saturday and Sunday from <a href="#" onclick="yt.www.watch.player.seekTo(13*60+30);return false;">13:30</a> outside the venue! <br />● PAX East: Fri, Sat & Sun - more info in tomorrows video on the main channel!''',
  256. 283,
  257. []
  258. ),
  259. ]
  260. def test_youtube_chapters(self):
  261. for description, duration, expected_chapters in self._TEST_CASES:
  262. ie = YoutubeIE()
  263. expect_value(
  264. self, ie._extract_chapters(description, duration),
  265. expected_chapters, None)
  266. if __name__ == '__main__':
  267. unittest.main()