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