comediansincarsgettingcoffee.com support
[youtube-dl] / youtube_dl / extractor / ccc.py
1 # encoding: utf-8
2 import re
3 import json
4
5 from .common import InfoExtractor
6 from ..utils import (
7     unified_strdate,
8 )
9
10 class ComCarCoffIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?comediansincarsgettingcoffee\.com/(?P<id>[a-z0-9\-]+)/?'
12     _TESTS = [
13         {
14             'url': 'http://comediansincarsgettingcoffee.com/miranda-sings-happy-thanksgiving-miranda/',
15             'info_dict': {
16                 'id': 'miranda-sings-happy-thanksgiving-miranda',
17                 'upload_date': '20141127',
18                 'title': 'Happy Thanksgiving Miranda',
19                 'description': 'Jerry Seinfeld and his special guest Miranda Sings cruise around town in search of coffee, complaining and apologizing along the way.',
20                 'thumbnail': 'http://ccc.crackle.com/images/s5e4_thumb.jpg',
21             },
22         }
23     ]
24
25     def _real_extract(self, url):
26         display_id = self._match_id(url)
27         webpage = self._download_webpage(url, display_id)
28
29         full_data = json.loads(self._search_regex(
30             r'<script type="application/json" id="videoData">(?P<json>.+?)</script>',
31             webpage, 'json'))
32
33         video_id = full_data['activeVideo']['video']
34         video_data = full_data['videos'][video_id]
35
36         return {
37             'id': video_id,
38             'display_id': display_id,
39             'title': video_data['title'],
40             'description': video_data['description'],
41             # XXX: the original datum is a full ISO timestamp... why convert it to a worse format?
42             'upload_date': unified_strdate(video_data['pubDate']),
43             'thumbnail': video_data['images']['thumb'],
44             # XXX: what do we do with video_data['images']['poster']?
45             'formats': self._extract_m3u8_formats(video_data['mediaUrl'], video_id),
46         }