]>
Commit | Line | Data |
---|---|---|
7eeb5bef PH |
1 | from __future__ import unicode_literals |
2 | ||
975fa541 | 3 | import json |
a37f27ae PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
572a89cc | 7 | from ..utils import int_or_none |
a37f27ae PH |
8 | |
9 | ||
10 | class LiveLeakIE(InfoExtractor): | |
c0ade33e | 11 | _VALID_URL = r'^(?:http://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)' |
89acb969 | 12 | _TESTS = [{ |
7eeb5bef | 13 | 'url': 'http://www.liveleak.com/view?i=757_1364311680', |
7eeb5bef PH |
14 | 'md5': '0813c2430bea7a46bf13acf3406992f4', |
15 | 'info_dict': { | |
572a89cc PH |
16 | 'id': '757_1364311680', |
17 | 'ext': 'mp4', | |
7eeb5bef PH |
18 | 'description': 'extremely bad day for this guy..!', |
19 | 'uploader': 'ljfriel2', | |
20 | 'title': 'Most unlucky car accident' | |
6f5ac90c | 21 | } |
8bcc8756 | 22 | }, { |
89acb969 | 23 | 'url': 'http://www.liveleak.com/view?i=f93_1390833151', |
89acb969 PH |
24 | 'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf', |
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)', | |
31 | } | |
8bcc8756 | 32 | }, { |
572a89cc PH |
33 | 'url': 'http://www.liveleak.com/view?i=4f7_1392687779', |
34 | 'md5': '42c6d97d54f1db107958760788c5f48f', | |
35 | 'info_dict': { | |
36 | 'id': '4f7_1392687779', | |
37 | 'ext': 'mp4', | |
38 | '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.", | |
39 | 'uploader': 'CapObveus', | |
40 | 'title': 'Man is Fatally Struck by Reckless Car While Packing up a Moving Truck', | |
41 | 'age_limit': 18, | |
42 | } | |
89acb969 | 43 | }] |
a37f27ae PH |
44 | |
45 | def _real_extract(self, url): | |
46 | mobj = re.match(self._VALID_URL, url) | |
a37f27ae | 47 | video_id = mobj.group('video_id') |
a37f27ae | 48 | webpage = self._download_webpage(url, video_id) |
572a89cc PH |
49 | |
50 | video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip() | |
51 | video_description = self._og_search_description(webpage) | |
52 | video_uploader = self._html_search_regex( | |
53 | r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False) | |
54 | age_limit = int_or_none(self._search_regex( | |
55 | r'you confirm that you are ([0-9]+) years and over.', | |
56 | webpage, 'age limit', default=None)) | |
57 | ||
975fa541 | 58 | sources_raw = self._search_regex( |
89acb969 PH |
59 | r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None) |
60 | if sources_raw is None: | |
572a89cc PH |
61 | alt_source = self._search_regex( |
62 | r'(file: ".*?"),', webpage, 'video URL', default=None) | |
63 | if alt_source: | |
64 | sources_raw = '[{ %s}]' % alt_source | |
65 | else: | |
66 | # Maybe an embed? | |
67 | embed_url = self._search_regex( | |
68 | r'<iframe[^>]+src="(http://www.prochan.com/embed\?[^"]+)"', | |
69 | webpage, 'embed URL') | |
70 | return { | |
71 | '_type': 'url_transparent', | |
72 | 'url': embed_url, | |
73 | 'id': video_id, | |
74 | 'title': video_title, | |
75 | 'description': video_description, | |
76 | 'uploader': video_uploader, | |
77 | 'age_limit': age_limit, | |
78 | } | |
89acb969 | 79 | |
975fa541 PH |
80 | sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw) |
81 | sources = json.loads(sources_json) | |
82 | ||
83 | formats = [{ | |
84 | 'format_note': s.get('label'), | |
85 | 'url': s['file'], | |
86 | } for s in sources] | |
87 | self._sort_formats(formats) | |
a37f27ae | 88 | |
7eeb5bef PH |
89 | return { |
90 | 'id': video_id, | |
a37f27ae PH |
91 | 'title': video_title, |
92 | 'description': video_description, | |
975fa541 PH |
93 | 'uploader': video_uploader, |
94 | 'formats': formats, | |
572a89cc | 95 | 'age_limit': age_limit, |
a37f27ae | 96 | } |