]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/liveleak.py
[liveleak] Support another liveleak embedding pattern (closes #13336)
[yt-dlp.git] / youtube_dl / extractor / liveleak.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import int_or_none
7
8
9 class LiveLeakIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<id>[\w_]+)(?:.*)'
11 _TESTS = [{
12 'url': 'http://www.liveleak.com/view?i=757_1364311680',
13 'md5': '0813c2430bea7a46bf13acf3406992f4',
14 'info_dict': {
15 'id': '757_1364311680',
16 'ext': 'mp4',
17 'description': 'extremely bad day for this guy..!',
18 'uploader': 'ljfriel2',
19 'title': 'Most unlucky car accident',
20 'thumbnail': r're:^https?://.*\.jpg$'
21 }
22 }, {
23 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
24 'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf',
25 'info_dict': {
26 'id': 'f93_1390833151',
27 'ext': 'mp4',
28 '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.',
29 'uploader': 'ARD_Stinkt',
30 'title': 'German Television does first Edward Snowden Interview (ENGLISH)',
31 'thumbnail': r're:^https?://.*\.jpg$'
32 }
33 }, {
34 # Prochan embed
35 'url': 'http://www.liveleak.com/view?i=4f7_1392687779',
36 'md5': '42c6d97d54f1db107958760788c5f48f',
37 'info_dict': {
38 'id': '4f7_1392687779',
39 'ext': 'mp4',
40 '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.",
41 'uploader': 'CapObveus',
42 'title': 'Man is Fatally Struck by Reckless Car While Packing up a Moving Truck',
43 'age_limit': 18,
44 },
45 'skip': 'Video is dead',
46 }, {
47 # Covers https://github.com/rg3/youtube-dl/pull/5983
48 # Multiple resolutions
49 'url': 'http://www.liveleak.com/view?i=801_1409392012',
50 'md5': 'c3a449dbaca5c0d1825caecd52a57d7b',
51 'info_dict': {
52 'id': '801_1409392012',
53 'ext': 'mp4',
54 'description': 'Happened on 27.7.2014. \r\nAt 0:53 you can see people still swimming at near beach.',
55 'uploader': 'bony333',
56 'title': 'Crazy Hungarian tourist films close call waterspout in Croatia',
57 'thumbnail': r're:^https?://.*\.jpg$'
58 }
59 }, {
60 # Covers https://github.com/rg3/youtube-dl/pull/10664#issuecomment-247439521
61 'url': 'http://m.liveleak.com/view?i=763_1473349649',
62 'add_ie': ['Youtube'],
63 'info_dict': {
64 'id': '763_1473349649',
65 'ext': 'mp4',
66 'title': 'Reporters and public officials ignore epidemic of black on asian violence in Sacramento | Colin Flaherty',
67 'description': 'Colin being the warrior he is and showing the injustice Asians in Sacramento are being subjected to.',
68 'uploader': 'Ziz',
69 'upload_date': '20160908',
70 'uploader_id': 'UCEbta5E_jqlZmEJsriTEtnw'
71 },
72 'params': {
73 'skip_download': True,
74 },
75 }]
76
77 @staticmethod
78 def _extract_urls(webpage):
79 return re.findall(
80 r'<iframe[^>]+src="(https?://(?:\w+\.)?liveleak\.com/ll_embed\?[^"]*[if]=[\w_]+[^"]+)"',
81 webpage)
82
83 def _real_extract(self, url):
84 video_id = self._match_id(url)
85 webpage = self._download_webpage(url, video_id)
86
87 video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip()
88 video_description = self._og_search_description(webpage)
89 video_uploader = self._html_search_regex(
90 r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False)
91 age_limit = int_or_none(self._search_regex(
92 r'you confirm that you are ([0-9]+) years and over.',
93 webpage, 'age limit', default=None))
94 video_thumbnail = self._og_search_thumbnail(webpage)
95
96 entries = self._parse_html5_media_entries(url, webpage, video_id)
97 if not entries:
98 # Maybe an embed?
99 embed_url = self._search_regex(
100 r'<iframe[^>]+src="((?:https?:)?//(?:www\.)?(?:prochan|youtube)\.com/embed[^"]+)"',
101 webpage, 'embed URL')
102 return {
103 '_type': 'url_transparent',
104 'url': embed_url,
105 'id': video_id,
106 'title': video_title,
107 'description': video_description,
108 'uploader': video_uploader,
109 'age_limit': age_limit,
110 }
111
112 info_dict = entries[0]
113
114 for a_format in info_dict['formats']:
115 if not a_format.get('height'):
116 a_format['height'] = int_or_none(self._search_regex(
117 r'([0-9]+)p\.mp4', a_format['url'], 'height label',
118 default=None))
119
120 self._sort_formats(info_dict['formats'])
121
122 info_dict.update({
123 'id': video_id,
124 'title': video_title,
125 'description': video_description,
126 'uploader': video_uploader,
127 'age_limit': age_limit,
128 'thumbnail': video_thumbnail,
129 })
130
131 return info_dict
132
133
134 class LiveLeakEmbedIE(InfoExtractor):
135 _VALID_URL = r'https?://(?:www\.)?liveleak\.com/ll_embed\?.*?\b(?P<kind>[if])=(?P<id>[\w_]+)'
136
137 # See generic.py for actual test cases
138 _TESTS = [{
139 'url': 'https://www.liveleak.com/ll_embed?i=874_1459135191',
140 'only_matching': True,
141 }, {
142 'url': 'https://www.liveleak.com/ll_embed?f=ab065df993c1',
143 'only_matching': True,
144 }]
145
146 def _real_extract(self, url):
147 mobj = re.match(self._VALID_URL, url)
148 kind, video_id = mobj.group('kind', 'id')
149
150 if kind == 'f':
151 webpage = self._download_webpage(url, video_id)
152 liveleak_url = self._search_regex(
153 r'logourl\s*:\s*(?P<q1>[\'"])(?P<url>%s)(?P=q1)' % LiveLeakIE._VALID_URL,
154 webpage, 'LiveLeak URL', group='url')
155 elif kind == 'i':
156 liveleak_url = 'http://www.liveleak.com/view?i=%s' % video_id
157
158 return self.url_result(liveleak_url, ie=LiveLeakIE.ie_key())