]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/liveleak.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / liveleak.py
CommitLineData
7eeb5bef
PH
1from __future__ import unicode_literals
2
975fa541 3import json
a37f27ae
PH
4import re
5
6from .common import InfoExtractor
572a89cc 7from ..utils import int_or_none
a37f27ae
PH
8
9
10class 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',
e2ee97dc 20 'title': 'Most unlucky car accident',
ec85ded8 21 'thumbnail': r're:^https?://.*\.jpg$'
6f5ac90c 22 }
8bcc8756 23 }, {
89acb969 24 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
26e27466 25 'md5': 'b13a29626183c9d33944e6a04f41aafc',
89acb969 26 'info_dict': {
572a89cc
PH
27 'id': 'f93_1390833151',
28 'ext': 'mp4',
89acb969
PH
29 '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.',
30 'uploader': 'ARD_Stinkt',
31 'title': 'German Television does first Edward Snowden Interview (ENGLISH)',
ec85ded8 32 'thumbnail': r're:^https?://.*\.jpg$'
89acb969 33 }
8bcc8756 34 }, {
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,
44 }
8f75761f 45 }, {
b95cfa91 46 # Covers https://github.com/rg3/youtube-dl/pull/5983
8f75761f 47 'url': 'http://www.liveleak.com/view?i=801_1409392012',
48 'md5': '0b3bec2d888c20728ca2ad3642f0ef15',
49 'info_dict': {
50 'id': '801_1409392012',
51 'ext': 'mp4',
611c1dd9 52 'description': 'Happened on 27.7.2014. \r\nAt 0:53 you can see people still swimming at near beach.',
8f75761f 53 'uploader': 'bony333',
e2ee97dc 54 'title': 'Crazy Hungarian tourist films close call waterspout in Croatia',
ec85ded8 55 'thumbnail': r're:^https?://.*\.jpg$'
8f75761f 56 }
3779d524
V
57 }, {
58 # Covers https://github.com/rg3/youtube-dl/pull/10664#issuecomment-247439521
8b0d3ee6 59 'url': 'http://m.liveleak.com/view?i=763_1473349649',
3779d524
V
60 'add_ie': ['Youtube'],
61 'info_dict': {
62 'id': '763_1473349649',
63 'ext': 'mp4',
64 'title': 'Reporters and public officials ignore epidemic of black on asian violence in Sacramento | Colin Flaherty',
65 'description': 'Colin being the warrior he is and showing the injustice Asians in Sacramento are being subjected to.',
66 'uploader': 'Ziz',
67 'upload_date': '20160908',
68 'uploader_id': 'UCEbta5E_jqlZmEJsriTEtnw'
8b0d3ee6
S
69 },
70 'params': {
71 'skip_download': True,
72 },
89acb969 73 }]
a37f27ae 74
b8f67449
KM
75 @staticmethod
76 def _extract_url(webpage):
77 mobj = re.search(
78 r'<iframe[^>]+src="https?://(?:\w+\.)?liveleak\.com/ll_embed\?(?:.*?)i=(?P<id>[\w_]+)(?:.*)',
79 webpage)
80 if mobj:
81 return 'http://www.liveleak.com/view?i=%s' % mobj.group('id')
82
a37f27ae 83 def _real_extract(self, url):
e793f767 84 video_id = self._match_id(url)
a37f27ae 85 webpage = self._download_webpage(url, video_id)
572a89cc
PH
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))
e2ee97dc 94 video_thumbnail = self._og_search_thumbnail(webpage)
572a89cc 95
975fa541 96 sources_raw = self._search_regex(
89acb969
PH
97 r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None)
98 if sources_raw is None:
572a89cc
PH
99 alt_source = self._search_regex(
100 r'(file: ".*?"),', webpage, 'video URL', default=None)
101 if alt_source:
102 sources_raw = '[{ %s}]' % alt_source
103 else:
104 # Maybe an embed?
105 embed_url = self._search_regex(
8b0d3ee6 106 r'<iframe[^>]+src="(https?://(?:www\.)?(?:prochan|youtube)\.com/embed[^"]+)"',
572a89cc
PH
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 }
89acb969 117
975fa541
PH
118 sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw)
119 sources = json.loads(sources_json)
120
121 formats = [{
26e27466 122 'format_id': '%s' % i,
975fa541
PH
123 'format_note': s.get('label'),
124 'url': s['file'],
26e27466 125 } for i, s in enumerate(sources)]
3779d524 126
26e27466 127 for i, s in enumerate(sources):
afa1ded4
S
128 # Removing '.h264_*.mp4' gives the raw video, which is essentially
129 # the same video without the LiveLeak logo at the top (see
130 # https://github.com/rg3/youtube-dl/pull/4768)
00ac23e6 131 orig_url = re.sub(r'\.h264_.+?\.mp4', '', s['file'])
26e27466
PH
132 if s['file'] != orig_url:
133 formats.append({
134 'format_id': 'original-%s' % i,
135 'format_note': s.get('label'),
136 'url': orig_url,
137 'preference': 1,
138 })
975fa541 139 self._sort_formats(formats)
a37f27ae 140
7eeb5bef
PH
141 return {
142 'id': video_id,
a37f27ae
PH
143 'title': video_title,
144 'description': video_description,
975fa541
PH
145 'uploader': video_uploader,
146 'formats': formats,
572a89cc 147 'age_limit': age_limit,
e2ee97dc 148 'thumbnail': video_thumbnail,
a37f27ae 149 }