You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
7.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class LiveLeakIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:\w+\.)?liveleak\.com/view\?.*?\b[it]=(?P<id>[\w_]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.liveleak.com/view?i=757_1364311680',
  9. 'md5': '0813c2430bea7a46bf13acf3406992f4',
  10. 'info_dict': {
  11. 'id': '757_1364311680',
  12. 'ext': 'mp4',
  13. 'description': 'extremely bad day for this guy..!',
  14. 'uploader': 'ljfriel2',
  15. 'title': 'Most unlucky car accident',
  16. 'thumbnail': r're:^https?://.*\.jpg$'
  17. }
  18. }, {
  19. 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
  20. 'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf',
  21. 'info_dict': {
  22. 'id': 'f93_1390833151',
  23. 'ext': 'mp4',
  24. 'description': 'German Television Channel NDR does an exclusive interview with Edward Snowden.\r\nUploaded on LiveLeak cause German Television thinks the rest of the world isn\'t intereseted in Edward Snowden.',
  25. 'uploader': 'ARD_Stinkt',
  26. 'title': 'German Television does first Edward Snowden Interview (ENGLISH)',
  27. 'thumbnail': r're:^https?://.*\.jpg$'
  28. }
  29. }, {
  30. # Prochan embed
  31. 'url': 'http://www.liveleak.com/view?i=4f7_1392687779',
  32. 'md5': '42c6d97d54f1db107958760788c5f48f',
  33. 'info_dict': {
  34. 'id': '4f7_1392687779',
  35. 'ext': 'mp4',
  36. 'description': "The guy with the cigarette seems amazingly nonchalant about the whole thing... I really hope my friends' reactions would be a bit stronger.\r\n\r\nAction-go to 0:55.",
  37. 'uploader': 'CapObveus',
  38. 'title': 'Man is Fatally Struck by Reckless Car While Packing up a Moving Truck',
  39. 'age_limit': 18,
  40. },
  41. 'skip': 'Video is dead',
  42. }, {
  43. # Covers https://github.com/ytdl-org/youtube-dl/pull/5983
  44. # Multiple resolutions
  45. 'url': 'http://www.liveleak.com/view?i=801_1409392012',
  46. 'md5': 'c3a449dbaca5c0d1825caecd52a57d7b',
  47. 'info_dict': {
  48. 'id': '801_1409392012',
  49. 'ext': 'mp4',
  50. 'description': 'Happened on 27.7.2014. \r\nAt 0:53 you can see people still swimming at near beach.',
  51. 'uploader': 'bony333',
  52. 'title': 'Crazy Hungarian tourist films close call waterspout in Croatia',
  53. 'thumbnail': r're:^https?://.*\.jpg$'
  54. }
  55. }, {
  56. # Covers https://github.com/ytdl-org/youtube-dl/pull/10664#issuecomment-247439521
  57. 'url': 'http://m.liveleak.com/view?i=763_1473349649',
  58. 'add_ie': ['Youtube'],
  59. 'info_dict': {
  60. 'id': '763_1473349649',
  61. 'ext': 'mp4',
  62. 'title': 'Reporters and public officials ignore epidemic of black on asian violence in Sacramento | Colin Flaherty',
  63. 'description': 'Colin being the warrior he is and showing the injustice Asians in Sacramento are being subjected to.',
  64. 'uploader': 'Ziz',
  65. 'upload_date': '20160908',
  66. 'uploader_id': 'UCEbta5E_jqlZmEJsriTEtnw'
  67. },
  68. 'params': {
  69. 'skip_download': True,
  70. },
  71. }, {
  72. 'url': 'https://www.liveleak.com/view?i=677_1439397581',
  73. 'info_dict': {
  74. 'id': '677_1439397581',
  75. 'title': 'Fuel Depot in China Explosion caught on video',
  76. },
  77. 'playlist_count': 3,
  78. }, {
  79. 'url': 'https://www.liveleak.com/view?t=HvHi_1523016227',
  80. 'only_matching': True,
  81. }, {
  82. # No original video
  83. 'url': 'https://www.liveleak.com/view?t=C26ZZ_1558612804',
  84. 'only_matching': True,
  85. }]
  86. @staticmethod
  87. def _extract_urls(webpage):
  88. return re.findall(
  89. r'<iframe[^>]+src="(https?://(?:\w+\.)?liveleak\.com/ll_embed\?[^"]*[ift]=[\w_]+[^"]+)"',
  90. webpage)
  91. def _real_extract(self, url):
  92. video_id = self._match_id(url)
  93. webpage = self._download_webpage(url, video_id)
  94. video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip()
  95. video_description = self._og_search_description(webpage)
  96. video_uploader = self._html_search_regex(
  97. r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False)
  98. age_limit = int_or_none(self._search_regex(
  99. r'you confirm that you are ([0-9]+) years and over.',
  100. webpage, 'age limit', default=None))
  101. video_thumbnail = self._og_search_thumbnail(webpage)
  102. entries = self._parse_html5_media_entries(url, webpage, video_id)
  103. if not entries:
  104. # Maybe an embed?
  105. embed_url = self._search_regex(
  106. r'<iframe[^>]+src="((?:https?:)?//(?:www\.)?(?:prochan|youtube)\.com/embed[^"]+)"',
  107. webpage, 'embed URL')
  108. return {
  109. '_type': 'url_transparent',
  110. 'url': embed_url,
  111. 'id': video_id,
  112. 'title': video_title,
  113. 'description': video_description,
  114. 'uploader': video_uploader,
  115. 'age_limit': age_limit,
  116. }
  117. for idx, info_dict in enumerate(entries):
  118. formats = []
  119. for a_format in info_dict['formats']:
  120. if not a_format.get('height'):
  121. a_format['height'] = int_or_none(self._search_regex(
  122. r'([0-9]+)p\.mp4', a_format['url'], 'height label',
  123. default=None))
  124. formats.append(a_format)
  125. # Removing '.*.mp4' gives the raw video, which is essentially
  126. # the same video without the LiveLeak logo at the top (see
  127. # https://github.com/ytdl-org/youtube-dl/pull/4768)
  128. orig_url = re.sub(r'\.mp4\.[^.]+', '', a_format['url'])
  129. if a_format['url'] != orig_url:
  130. format_id = a_format.get('format_id')
  131. format_id = 'original' + ('-' + format_id if format_id else '')
  132. if self._is_valid_url(orig_url, video_id, format_id):
  133. formats.append({
  134. 'format_id': format_id,
  135. 'url': orig_url,
  136. 'preference': 1,
  137. })
  138. self._sort_formats(formats)
  139. info_dict['formats'] = formats
  140. # Don't append entry ID for one-video pages to keep backward compatibility
  141. if len(entries) > 1:
  142. info_dict['id'] = '%s_%s' % (video_id, idx + 1)
  143. else:
  144. info_dict['id'] = video_id
  145. info_dict.update({
  146. 'title': video_title,
  147. 'description': video_description,
  148. 'uploader': video_uploader,
  149. 'age_limit': age_limit,
  150. 'thumbnail': video_thumbnail,
  151. })
  152. return self.playlist_result(entries, video_id, video_title)
  153. class LiveLeakEmbedIE(InfoExtractor):
  154. _VALID_URL = r'https?://(?:www\.)?liveleak\.com/ll_embed\?.*?\b(?P<kind>[ift])=(?P<id>[\w_]+)'
  155. # See generic.py for actual test cases
  156. _TESTS = [{
  157. 'url': 'https://www.liveleak.com/ll_embed?i=874_1459135191',
  158. 'only_matching': True,
  159. }, {
  160. 'url': 'https://www.liveleak.com/ll_embed?f=ab065df993c1',
  161. 'only_matching': True,
  162. }]
  163. def _real_extract(self, url):
  164. kind, video_id = re.match(self._VALID_URL, url).groups()
  165. if kind == 'f':
  166. webpage = self._download_webpage(url, video_id)
  167. liveleak_url = self._search_regex(
  168. r'(?:logourl\s*:\s*|window\.open\()(?P<q1>[\'"])(?P<url>%s)(?P=q1)' % LiveLeakIE._VALID_URL,
  169. webpage, 'LiveLeak URL', group='url')
  170. else:
  171. liveleak_url = 'http://www.liveleak.com/view?%s=%s' % (kind, video_id)
  172. return self.url_result(liveleak_url, ie=LiveLeakIE.ie_key())