]>
Commit | Line | Data |
---|---|---|
869baf35 JMF |
1 | from __future__ import unicode_literals |
2 | ||
60cc4dc4 | 3 | import json |
8f0578f0 PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
bebd6f93 | 7 | from ..utils import ExtractorError |
8f0578f0 PH |
8 | |
9 | ||
10 | class FunnyOrDieIE(InfoExtractor): | |
2a834bdb | 11 | _VALID_URL = r'https?://(?:www\.)?funnyordie\.com/(?P<type>embed|articles|videos)/(?P<id>[0-9a-f]+)(?:$|[?#/])' |
aab8874c | 12 | _TESTS = [{ |
869baf35 | 13 | 'url': 'http://www.funnyordie.com/videos/0732f586d7/heart-shaped-box-literal-video-version', |
bebd6f93 | 14 | 'md5': 'bcd81e0c4f26189ee09be362ad6e6ba9', |
869baf35 | 15 | 'info_dict': { |
aab8874c | 16 | 'id': '0732f586d7', |
17 | 'ext': 'mp4', | |
869baf35 | 18 | 'title': 'Heart-Shaped Box: Literal Video Version', |
aab8874c | 19 | 'description': 'md5:ea09a01bc9a1c46d9ab696c01747c338', |
20 | 'thumbnail': 're:^http:.*\.jpg$', | |
869baf35 | 21 | }, |
aab8874c | 22 | }, { |
23 | 'url': 'http://www.funnyordie.com/embed/e402820827', | |
aab8874c | 24 | 'info_dict': { |
25 | 'id': 'e402820827', | |
26 | 'ext': 'mp4', | |
27 | 'title': 'Please Use This Song (Jon Lajoie)', | |
a850fde1 | 28 | 'description': 'Please use this to sell something. www.jonlajoie.com', |
aab8874c | 29 | 'thumbnail': 're:^http:.*\.jpg$', |
30 | }, | |
d319948b S |
31 | }, { |
32 | 'url': 'http://www.funnyordie.com/articles/ebf5e34fc8/10-hours-of-walking-in-nyc-as-a-man', | |
33 | 'only_matching': True, | |
aab8874c | 34 | }] |
8f0578f0 PH |
35 | |
36 | def _real_extract(self, url): | |
37 | mobj = re.match(self._VALID_URL, url) | |
38 | ||
39 | video_id = mobj.group('id') | |
40 | webpage = self._download_webpage(url, video_id) | |
41 | ||
75da98e9 | 42 | links = re.findall(r'<source src="([^"]+/v)[^"]+\.([^"]+)" type=\'video', webpage) |
bebd6f93 S |
43 | if not links: |
44 | raise ExtractorError('No media links available for %s' % video_id) | |
45 | ||
46 | links.sort(key=lambda link: 1 if link[1] == 'mp4' else 0) | |
47 | ||
9b738b2c S |
48 | m3u8_url = self._search_regex( |
49 | r'<source[^>]+src=(["\'])(?P<url>.+?/master\.m3u8)\1', | |
50 | webpage, 'm3u8 url', default=None, group='url') | |
bebd6f93 S |
51 | |
52 | formats = [] | |
9b738b2c S |
53 | |
54 | m3u8_formats = self._extract_m3u8_formats( | |
55 | m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False) | |
56 | if m3u8_formats: | |
57 | formats.extend(m3u8_formats) | |
58 | ||
59 | bitrates = [int(bitrate) for bitrate in re.findall(r'[,/]v(\d+)[,/]', m3u8_url)] | |
60 | bitrates.sort() | |
61 | ||
bebd6f93 S |
62 | for bitrate in bitrates: |
63 | for link in links: | |
64 | formats.append({ | |
1df3186e | 65 | 'url': self._proto_relative_url('%s%d.%s' % (link[0], bitrate, link[1])), |
bebd6f93 S |
66 | 'format_id': '%s-%d' % (link[1], bitrate), |
67 | 'vbr': bitrate, | |
68 | }) | |
8f0578f0 | 69 | |
a3fbd188 S |
70 | subtitles = {} |
71 | for src, src_lang in re.findall(r'<track kind="captions" src="([^"]+)" srclang="([^"]+)"', webpage): | |
72 | subtitles[src_lang] = [{ | |
73 | 'ext': src.split('/')[-1], | |
74 | 'url': 'http://www.funnyordie.com%s' % src, | |
75 | }] | |
614a7e1e | 76 | |
aab8874c | 77 | post_json = self._search_regex( |
78 | r'fb_post\s*=\s*(\{.*?\});', webpage, 'post details') | |
79 | post = json.loads(post_json) | |
60cc4dc4 | 80 | |
869baf35 | 81 | return { |
8f0578f0 | 82 | 'id': video_id, |
d0111a74 | 83 | 'title': post['name'], |
84 | 'description': post.get('description'), | |
85 | 'thumbnail': post.get('picture'), | |
bebd6f93 | 86 | 'formats': formats, |
614a7e1e | 87 | 'subtitles': subtitles, |
8f0578f0 | 88 | } |