]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/liveleak.py
Merge branch 'master' of https://github.com/ssaqua/youtube-dl into ssaqua-master
[yt-dlp.git] / youtube_dlc / extractor / liveleak.py
CommitLineData
7eeb5bef
PH
1from __future__ import unicode_literals
2
a37f27ae
PH
3import re
4
5from .common import InfoExtractor
572a89cc 6from ..utils import int_or_none
a37f27ae
PH
7
8
9class LiveLeakIE(InfoExtractor):
e2750e14 10 _VALID_URL = r'https?://(?:\w+\.)?liveleak\.com/view\?.*?\b[it]=(?P<id>[\w_]+)'
89acb969 11 _TESTS = [{
7eeb5bef 12 'url': 'http://www.liveleak.com/view?i=757_1364311680',
116283ff 13 'md5': '0813c2430bea7a46bf13acf3406992f4',
7eeb5bef 14 'info_dict': {
572a89cc 15 'id': '757_1364311680',
116283ff 16 'ext': 'mp4',
7eeb5bef
PH
17 'description': 'extremely bad day for this guy..!',
18 'uploader': 'ljfriel2',
e2ee97dc 19 'title': 'Most unlucky car accident',
ec85ded8 20 'thumbnail': r're:^https?://.*\.jpg$'
6f5ac90c 21 }
8bcc8756 22 }, {
89acb969 23 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
116283ff 24 'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf',
89acb969 25 'info_dict': {
572a89cc
PH
26 'id': 'f93_1390833151',
27 'ext': 'mp4',
89acb969
PH
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)',
ec85ded8 31 'thumbnail': r're:^https?://.*\.jpg$'
89acb969 32 }
8bcc8756 33 }, {
116283ff 34 # Prochan embed
572a89cc
PH
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,
116283ff
YCH
44 },
45 'skip': 'Video is dead',
8f75761f 46 }, {
067aa17e 47 # Covers https://github.com/ytdl-org/youtube-dl/pull/5983
116283ff 48 # Multiple resolutions
8f75761f 49 'url': 'http://www.liveleak.com/view?i=801_1409392012',
116283ff 50 'md5': 'c3a449dbaca5c0d1825caecd52a57d7b',
8f75761f 51 'info_dict': {
52 'id': '801_1409392012',
53 'ext': 'mp4',
611c1dd9 54 'description': 'Happened on 27.7.2014. \r\nAt 0:53 you can see people still swimming at near beach.',
8f75761f 55 'uploader': 'bony333',
e2ee97dc 56 'title': 'Crazy Hungarian tourist films close call waterspout in Croatia',
ec85ded8 57 'thumbnail': r're:^https?://.*\.jpg$'
8f75761f 58 }
3779d524 59 }, {
067aa17e 60 # Covers https://github.com/ytdl-org/youtube-dl/pull/10664#issuecomment-247439521
8b0d3ee6 61 'url': 'http://m.liveleak.com/view?i=763_1473349649',
3779d524
V
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'
8b0d3ee6
S
71 },
72 'params': {
73 'skip_download': True,
74 },
381ad4f3
YCH
75 }, {
76 'url': 'https://www.liveleak.com/view?i=677_1439397581',
77 'info_dict': {
78 'id': '677_1439397581',
79 'title': 'Fuel Depot in China Explosion caught on video',
80 },
81 'playlist_count': 3,
e2750e14
S
82 }, {
83 'url': 'https://www.liveleak.com/view?t=HvHi_1523016227',
84 'only_matching': True,
33b2218b 85 }, {
86 # No original video
87 'url': 'https://www.liveleak.com/view?t=C26ZZ_1558612804',
88 'only_matching': True,
89acb969 89 }]
a37f27ae 90
b8f67449 91 @staticmethod
09747ba7
YCH
92 def _extract_urls(webpage):
93 return re.findall(
e1a06287 94 r'<iframe[^>]+src="(https?://(?:\w+\.)?liveleak\.com/ll_embed\?[^"]*[ift]=[\w_]+[^"]+)"',
b8f67449 95 webpage)
b8f67449 96
a37f27ae 97 def _real_extract(self, url):
e793f767 98 video_id = self._match_id(url)
a37f27ae 99 webpage = self._download_webpage(url, video_id)
572a89cc
PH
100
101 video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip()
102 video_description = self._og_search_description(webpage)
103 video_uploader = self._html_search_regex(
104 r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False)
105 age_limit = int_or_none(self._search_regex(
106 r'you confirm that you are ([0-9]+) years and over.',
107 webpage, 'age limit', default=None))
e2ee97dc 108 video_thumbnail = self._og_search_thumbnail(webpage)
572a89cc 109
116283ff
YCH
110 entries = self._parse_html5_media_entries(url, webpage, video_id)
111 if not entries:
112 # Maybe an embed?
113 embed_url = self._search_regex(
114 r'<iframe[^>]+src="((?:https?:)?//(?:www\.)?(?:prochan|youtube)\.com/embed[^"]+)"',
115 webpage, 'embed URL')
116 return {
117 '_type': 'url_transparent',
118 'url': embed_url,
119 'id': video_id,
120 'title': video_title,
121 'description': video_description,
122 'uploader': video_uploader,
123 'age_limit': age_limit,
124 }
89acb969 125
381ad4f3 126 for idx, info_dict in enumerate(entries):
e1a06287 127 formats = []
381ad4f3
YCH
128 for a_format in info_dict['formats']:
129 if not a_format.get('height'):
130 a_format['height'] = int_or_none(self._search_regex(
131 r'([0-9]+)p\.mp4', a_format['url'], 'height label',
132 default=None))
e1a06287
RA
133 formats.append(a_format)
134
135 # Removing '.*.mp4' gives the raw video, which is essentially
136 # the same video without the LiveLeak logo at the top (see
067aa17e 137 # https://github.com/ytdl-org/youtube-dl/pull/4768)
e1a06287
RA
138 orig_url = re.sub(r'\.mp4\.[^.]+', '', a_format['url'])
139 if a_format['url'] != orig_url:
140 format_id = a_format.get('format_id')
33b2218b 141 format_id = 'original' + ('-' + format_id if format_id else '')
142 if self._is_valid_url(orig_url, video_id, format_id):
143 formats.append({
144 'format_id': format_id,
145 'url': orig_url,
146 'preference': 1,
147 })
e1a06287
RA
148 self._sort_formats(formats)
149 info_dict['formats'] = formats
3779d524 150
381ad4f3
YCH
151 # Don't append entry ID for one-video pages to keep backward compatibility
152 if len(entries) > 1:
153 info_dict['id'] = '%s_%s' % (video_id, idx + 1)
154 else:
155 info_dict['id'] = video_id
a37f27ae 156
381ad4f3
YCH
157 info_dict.update({
158 'title': video_title,
159 'description': video_description,
160 'uploader': video_uploader,
161 'age_limit': age_limit,
162 'thumbnail': video_thumbnail,
163 })
116283ff 164
381ad4f3 165 return self.playlist_result(entries, video_id, video_title)
09747ba7
YCH
166
167
168class LiveLeakEmbedIE(InfoExtractor):
e1a06287 169 _VALID_URL = r'https?://(?:www\.)?liveleak\.com/ll_embed\?.*?\b(?P<kind>[ift])=(?P<id>[\w_]+)'
09747ba7
YCH
170
171 # See generic.py for actual test cases
172 _TESTS = [{
173 'url': 'https://www.liveleak.com/ll_embed?i=874_1459135191',
174 'only_matching': True,
175 }, {
176 'url': 'https://www.liveleak.com/ll_embed?f=ab065df993c1',
177 'only_matching': True,
178 }]
179
180 def _real_extract(self, url):
e1a06287 181 kind, video_id = re.match(self._VALID_URL, url).groups()
09747ba7
YCH
182
183 if kind == 'f':
184 webpage = self._download_webpage(url, video_id)
185 liveleak_url = self._search_regex(
e1a06287 186 r'(?:logourl\s*:\s*|window\.open\()(?P<q1>[\'"])(?P<url>%s)(?P=q1)' % LiveLeakIE._VALID_URL,
09747ba7 187 webpage, 'LiveLeak URL', group='url')
e1a06287
RA
188 else:
189 liveleak_url = 'http://www.liveleak.com/view?%s=%s' % (kind, video_id)
09747ba7
YCH
190
191 return self.url_result(liveleak_url, ie=LiveLeakIE.ie_key())