]>
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): | |
e793f767 | 11 | _VALID_URL = r'https?://(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<id>[\w_]+)(?:.*)' |
89acb969 | 12 | _TESTS = [{ |
7eeb5bef | 13 | 'url': 'http://www.liveleak.com/view?i=757_1364311680', |
26e27466 | 14 | 'md5': '50f79e05ba149149c1b4ea961223d5b3', |
7eeb5bef | 15 | 'info_dict': { |
572a89cc | 16 | 'id': '757_1364311680', |
26e27466 | 17 | 'ext': 'flv', |
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', |
26e27466 | 24 | 'md5': 'b13a29626183c9d33944e6a04f41aafc', |
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)', | |
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 | } | |
8f75761f | 43 | }, { |
b95cfa91 | 44 | # Covers https://github.com/rg3/youtube-dl/pull/5983 |
8f75761f | 45 | 'url': 'http://www.liveleak.com/view?i=801_1409392012', |
46 | 'md5': '0b3bec2d888c20728ca2ad3642f0ef15', | |
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 | } | |
89acb969 | 54 | }] |
a37f27ae PH |
55 | |
56 | def _real_extract(self, url): | |
e793f767 | 57 | video_id = self._match_id(url) |
a37f27ae | 58 | webpage = self._download_webpage(url, video_id) |
572a89cc PH |
59 | |
60 | video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip() | |
61 | video_description = self._og_search_description(webpage) | |
62 | video_uploader = self._html_search_regex( | |
63 | r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False) | |
64 | age_limit = int_or_none(self._search_regex( | |
65 | r'you confirm that you are ([0-9]+) years and over.', | |
66 | webpage, 'age limit', default=None)) | |
67 | ||
975fa541 | 68 | sources_raw = self._search_regex( |
89acb969 PH |
69 | r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None) |
70 | if sources_raw is None: | |
572a89cc PH |
71 | alt_source = self._search_regex( |
72 | r'(file: ".*?"),', webpage, 'video URL', default=None) | |
73 | if alt_source: | |
74 | sources_raw = '[{ %s}]' % alt_source | |
75 | else: | |
76 | # Maybe an embed? | |
77 | embed_url = self._search_regex( | |
78 | r'<iframe[^>]+src="(http://www.prochan.com/embed\?[^"]+)"', | |
79 | webpage, 'embed URL') | |
80 | return { | |
81 | '_type': 'url_transparent', | |
82 | 'url': embed_url, | |
83 | 'id': video_id, | |
84 | 'title': video_title, | |
85 | 'description': video_description, | |
86 | 'uploader': video_uploader, | |
87 | 'age_limit': age_limit, | |
88 | } | |
89acb969 | 89 | |
975fa541 PH |
90 | sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw) |
91 | sources = json.loads(sources_json) | |
92 | ||
93 | formats = [{ | |
26e27466 | 94 | 'format_id': '%s' % i, |
975fa541 PH |
95 | 'format_note': s.get('label'), |
96 | 'url': s['file'], | |
26e27466 PH |
97 | } for i, s in enumerate(sources)] |
98 | for i, s in enumerate(sources): | |
afa1ded4 S |
99 | # Removing '.h264_*.mp4' gives the raw video, which is essentially |
100 | # the same video without the LiveLeak logo at the top (see | |
101 | # https://github.com/rg3/youtube-dl/pull/4768) | |
00ac23e6 | 102 | orig_url = re.sub(r'\.h264_.+?\.mp4', '', s['file']) |
26e27466 PH |
103 | if s['file'] != orig_url: |
104 | formats.append({ | |
105 | 'format_id': 'original-%s' % i, | |
106 | 'format_note': s.get('label'), | |
107 | 'url': orig_url, | |
108 | 'preference': 1, | |
109 | }) | |
975fa541 | 110 | self._sort_formats(formats) |
a37f27ae | 111 | |
7eeb5bef PH |
112 | return { |
113 | 'id': video_id, | |
a37f27ae PH |
114 | 'title': video_title, |
115 | 'description': video_description, | |
975fa541 PH |
116 | 'uploader': video_uploader, |
117 | 'formats': formats, | |
572a89cc | 118 | 'age_limit': age_limit, |
a37f27ae | 119 | } |