]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/crooksandliars.py
[dailymotion] Error spelling
[youtube-dl] / youtube_dl / extractor / crooksandliars.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     int_or_none,
6     qualities,
7 )
8
9
10 class CrooksAndLiarsIE(InfoExtractor):
11     _VALID_URL = r'https?://embed\.crooksandliars\.com/(?:embed|v)/(?P<id>[A-Za-z0-9]+)'
12     _TESTS = [{
13         'url': 'https://embed.crooksandliars.com/embed/8RUoRhRi',
14         'info_dict': {
15             'id': '8RUoRhRi',
16             'ext': 'mp4',
17             'title': 'Fox & Friends Says Protecting Atheists From Discrimination Is Anti-Christian!',
18             'description': 'md5:e1a46ad1650e3a5ec7196d432799127f',
19             'thumbnail': 're:^https?://.*\.jpg',
20             'timestamp': 1428207000,
21             'upload_date': '20150405',
22             'uploader': 'Heather',
23             'duration': 236,
24         }
25     }, {
26         'url': 'http://embed.crooksandliars.com/v/MTE3MjUtMzQ2MzA',
27         'only_matching': True,
28     }]
29
30     def _real_extract(self, url):
31         video_id = self._match_id(url)
32
33         webpage = self._download_webpage(
34             'http://embed.crooksandliars.com/embed/%s' % video_id, video_id)
35
36         manifest = self._parse_json(
37             self._search_regex(
38                 r'var\s+manifest\s*=\s*({.+?})\n', webpage, 'manifest JSON'),
39             video_id)
40
41         quality = qualities(('webm_low', 'mp4_low', 'webm_high', 'mp4_high'))
42
43         formats = [{
44             'url': item['url'],
45             'format_id': item['type'],
46             'quality': quality(item['type']),
47         } for item in manifest['flavors'] if item['mime'].startswith('video/')]
48         self._sort_formats(formats)
49
50         return {
51             'url': url,
52             'id': video_id,
53             'title': manifest['title'],
54             'description': manifest.get('description'),
55             'thumbnail': self._proto_relative_url(manifest.get('poster')),
56             'timestamp': int_or_none(manifest.get('created')),
57             'uploader': manifest.get('author'),
58             'duration': int_or_none(manifest.get('duration')),
59             'formats': formats,
60         }