Merge branch 'baidu' of https://github.com/remitamine/youtube-dl into remitamine...
[youtube-dl] / youtube_dl / extractor / comcarcoff.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     parse_duration,
8     parse_iso8601,
9 )
10
11
12 class ComCarCoffIE(InfoExtractor):
13     _VALID_URL = r'http://(?:www\.)?comediansincarsgettingcoffee\.com/(?P<id>[a-z0-9\-]*)'
14     _TESTS = [{
15         'url': 'http://comediansincarsgettingcoffee.com/miranda-sings-happy-thanksgiving-miranda/',
16         'info_dict': {
17             'id': 'miranda-sings-happy-thanksgiving-miranda',
18             'ext': 'mp4',
19             'upload_date': '20141127',
20             'timestamp': 1417107600,
21             'duration': 1232,
22             'title': 'Happy Thanksgiving Miranda',
23             'description': 'Jerry Seinfeld and his special guest Miranda Sings cruise around town in search of coffee, complaining and apologizing along the way.',
24             'thumbnail': 'http://ccc.crackle.com/images/s5e4_thumb.jpg',
25         },
26         'params': {
27             'skip_download': 'requires ffmpeg',
28         }
29     }]
30
31     def _real_extract(self, url):
32         display_id = self._match_id(url)
33         if not display_id:
34             display_id = 'comediansincarsgettingcoffee.com'
35         webpage = self._download_webpage(url, display_id)
36
37         full_data = self._parse_json(
38             self._search_regex(
39                 r'window\.app\s*=\s*({.+?});\n', webpage, 'full data json'),
40             display_id)['videoData']
41
42         video_id = full_data['activeVideo']['video']
43         video_data = full_data.get('videos', {}).get(video_id) or full_data['singleshots'][video_id]
44         thumbnails = [{
45             'url': video_data['images']['thumb'],
46         }, {
47             'url': video_data['images']['poster'],
48         }]
49         formats = self._extract_m3u8_formats(
50             video_data['mediaUrl'], video_id, ext='mp4')
51
52         timestamp = int_or_none(video_data.get('pubDateTime')) or parse_iso8601(
53             video_data.get('pubDate'))
54         duration = int_or_none(video_data.get('durationSeconds')) or parse_duration(
55             video_data.get('duration'))
56
57         return {
58             'id': video_id,
59             'display_id': display_id,
60             'title': video_data['title'],
61             'description': video_data.get('description'),
62             'timestamp': timestamp,
63             'duration': duration,
64             'thumbnails': thumbnails,
65             'formats': formats,
66             'webpage_url': 'http://comediansincarsgettingcoffee.com/%s' % (video_data.get('urlSlug', video_data.get('slug'))),
67         }