]>
Commit | Line | Data |
---|---|---|
e3aaace4 | 1 | from __future__ import unicode_literals |
2 | ||
e3aaace4 | 3 | from .common import InfoExtractor |
5f87d845 RA |
4 | from ..utils import ( |
5 | int_or_none, | |
6 | determine_ext, | |
7 | mimetype2ext, | |
8 | ) | |
e3aaace4 | 9 | |
10 | ||
11 | class TweakersIE(InfoExtractor): | |
9c91a8fa | 12 | _VALID_URL = r'https?://tweakers\.net/video/(?P<id>\d+)' |
e3aaace4 | 13 | _TEST = { |
14 | 'url': 'https://tweakers.net/video/9926/new-nintendo-3ds-xl-op-alle-fronten-beter.html', | |
5f87d845 | 15 | 'md5': 'fe73e417c093a788e0160c4025f88b15', |
e3aaace4 | 16 | 'info_dict': { |
17 | 'id': '9926', | |
18 | 'ext': 'mp4', | |
9c91a8fa | 19 | 'title': 'New Nintendo 3DS XL - Op alle fronten beter', |
5f87d845 | 20 | 'description': 'md5:3789b21fed9c0219e9bcaacd43fab280', |
ec85ded8 | 21 | 'thumbnail': r're:^https?://.*\.jpe?g$', |
9c91a8fa | 22 | 'duration': 386, |
5f87d845 | 23 | 'uploader_id': 's7JeEm', |
e3aaace4 | 24 | } |
25 | } | |
26 | ||
27 | def _real_extract(self, url): | |
5f87d845 RA |
28 | video_id = self._match_id(url) |
29 | video_data = self._download_json( | |
30 | 'https://tweakers.net/video/s1playlist/%s/1920/1080/playlist.json' % video_id, | |
31 | video_id)['items'][0] | |
32 | ||
33 | title = video_data['title'] | |
34 | ||
35 | formats = [] | |
36 | for location in video_data.get('locations', {}).get('progressive', []): | |
37 | format_id = location.get('label') | |
38 | width = int_or_none(location.get('width')) | |
39 | height = int_or_none(location.get('height')) | |
40 | for source in location.get('sources', []): | |
41 | source_url = source.get('src') | |
42 | if not source_url: | |
43 | continue | |
44 | ext = mimetype2ext(source.get('type')) or determine_ext(source_url) | |
45 | formats.append({ | |
46 | 'format_id': format_id, | |
47 | 'url': source_url, | |
48 | 'width': width, | |
49 | 'height': height, | |
50 | 'ext': ext, | |
51 | }) | |
52 | self._sort_formats(formats) | |
53 | ||
54 | return { | |
55 | 'id': video_id, | |
56 | 'title': title, | |
57 | 'description': video_data.get('description'), | |
58 | 'thumbnail': video_data.get('poster'), | |
59 | 'duration': int_or_none(video_data.get('duration')), | |
60 | 'uploader_id': video_data.get('account'), | |
61 | 'formats': formats, | |
62 | } |