[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / tv2hu.py
blob9c0a111c0514faa6536804f79edeadd84edf592f
1 # encoding: utf-8
2 from .common import InfoExtractor
3 from ..utils import (
4 traverse_obj,
5 UnsupportedError,
9 class TV2HuIE(InfoExtractor):
10 IE_NAME = 'tv2play.hu'
11 _VALID_URL = r'https?://(?:www\.)?tv2play\.hu/(?!szalag/)(?P<id>[^#&?]+)'
12 _TESTS = [{
13 'url': 'https://tv2play.hu/mintaapak/mintaapak_213_epizod_resz',
14 'info_dict': {
15 'id': '249240',
16 'ext': 'mp4',
17 'title': 'Mintaapák - 213. epizód',
18 'series': 'Mintaapák',
19 'duration': 2164,
20 'description': 'md5:7350147e75485a59598e806c47967b07',
21 'thumbnail': r're:^https?://.*\.jpg$',
22 'release_date': '20210825',
23 'episode_number': 213,
25 'params': {
26 'skip_download': True,
28 }, {
29 'url': 'https://tv2play.hu/taxi_2',
30 'md5': '585e58e2e090f34603804bb2c48e98d8',
31 'info_dict': {
32 'id': '199363',
33 'ext': 'mp4',
34 'title': 'Taxi 2',
35 'series': 'Taxi 2',
36 'duration': 5087,
37 'description': 'md5:47762155dc9a50241797ded101b1b08c',
38 'thumbnail': r're:^https?://.*\.jpg$',
39 'release_date': '20210118',
41 'params': {
42 'skip_download': True,
46 def _real_extract(self, url):
47 id = self._match_id(url)
48 json_data = self._download_json(f'https://tv2play.hu/api/search/{id}', id)
50 if json_data['contentType'] == 'showpage':
51 ribbon_ids = traverse_obj(json_data, ('pages', ..., 'tabs', ..., 'ribbonIds'), get_all=False, expected_type=list)
52 entries = [self.url_result(f'https://tv2play.hu/szalag/{ribbon_id}',
53 ie=TV2HuSeriesIE.ie_key(), video_id=ribbon_id) for ribbon_id in ribbon_ids]
54 return self.playlist_result(entries, playlist_id=id)
55 elif json_data['contentType'] != 'video':
56 raise UnsupportedError(url)
58 video_id = str(json_data['id'])
59 player_id = json_data.get('playerId')
60 series_json = json_data.get('seriesInfo', {})
62 video_json_url = self._download_json(f'https://tv2play.hu/api/streaming-url?playerId={player_id}', video_id)['url']
63 video_json = self._download_json(video_json_url, video_id)
64 m3u8_url = self._proto_relative_url(traverse_obj(video_json, ('bitrates', 'hls')))
65 formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
67 return {
68 'id': video_id,
69 'title': json_data['title'],
70 'series': json_data.get('seriesTitle'),
71 'duration': json_data.get('length'),
72 'description': json_data.get('description'),
73 'thumbnail': 'https://tv2play.hu' + json_data.get('thumbnailUrl'),
74 'release_date': json_data.get('uploadedAt').replace('.', ''),
75 'season_number': series_json.get('seasonNr'),
76 'episode_number': series_json.get('episodeNr'),
77 'formats': formats,
78 'subtitles': subtitles,
82 class TV2HuSeriesIE(InfoExtractor):
83 IE_NAME = 'tv2playseries.hu'
84 _VALID_URL = r'https?://(?:www\.)?tv2play\.hu/szalag/(?P<id>[^#&?]+)'
86 _TESTS = [{
87 'url': 'https://tv2play.hu/szalag/59?rendezes=nepszeruseg',
88 'playlist_mincount': 284,
89 'info_dict': {
90 'id': '59',
94 def _real_extract(self, url):
95 id = self._match_id(url)
96 json_data = self._download_json(f'https://tv2play.hu/api/ribbons/{id}/0?size=100000', id)
97 entries = []
98 for card in json_data.get('cards', []):
99 video_id = card.get('slug')
100 if video_id:
101 entries.append(self.url_result(f'https://tv2play.hu/{video_id}',
102 ie=TV2HuIE.ie_key(), video_id=video_id))
104 return self.playlist_result(entries, playlist_id=id)