[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / tweakers.py
blob77a4136cc17fcd44af0e5196594045f9fcf89291
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 mimetype2ext,
9 class TweakersIE(InfoExtractor):
10 _VALID_URL = r'https?://tweakers\.net/video/(?P<id>\d+)'
11 _TEST = {
12 'url': 'https://tweakers.net/video/9926/new-nintendo-3ds-xl-op-alle-fronten-beter.html',
13 'md5': 'fe73e417c093a788e0160c4025f88b15',
14 'info_dict': {
15 'id': '9926',
16 'ext': 'mp4',
17 'title': 'New Nintendo 3DS XL - Op alle fronten beter',
18 'description': 'md5:3789b21fed9c0219e9bcaacd43fab280',
19 'thumbnail': r're:^https?://.*\.jpe?g$',
20 'duration': 386,
21 'uploader_id': 's7JeEm',
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27 video_data = self._download_json(
28 f'https://tweakers.net/video/s1playlist/{video_id}/1920/1080/playlist.json',
29 video_id)['items'][0]
31 title = video_data['title']
33 formats = []
34 for location in video_data.get('locations', {}).get('progressive', []):
35 format_id = location.get('label')
36 width = int_or_none(location.get('width'))
37 height = int_or_none(location.get('height'))
38 for source in location.get('sources', []):
39 source_url = source.get('src')
40 if not source_url:
41 continue
42 ext = mimetype2ext(source.get('type')) or determine_ext(source_url)
43 formats.append({
44 'format_id': format_id,
45 'url': source_url,
46 'width': width,
47 'height': height,
48 'ext': ext,
51 return {
52 'id': video_id,
53 'title': title,
54 'description': video_data.get('description'),
55 'thumbnail': video_data.get('poster'),
56 'duration': int_or_none(video_data.get('duration')),
57 'uploader_id': video_data.get('account'),
58 'formats': formats,