]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/freetv.py
[cleanup] Misc fixes
[yt-dlp.git] / yt_dlp / extractor / freetv.py
CommitLineData
e0a4a3d5
E
1import itertools
2import re
3
4from .common import InfoExtractor
56ba69e4 5from ..utils import int_or_none, traverse_obj, urlencode_postdata
e0a4a3d5
E
6
7
8class FreeTvBaseIE(InfoExtractor):
9 def _get_api_response(self, content_id, resource_type, postdata):
10 return self._download_json(
11 'https://www.freetv.com/wordpress/wp-admin/admin-ajax.php',
12 content_id, data=urlencode_postdata(postdata),
13 note=f'Downloading {content_id} {resource_type} JSON')['data']
14
15
16class FreeTvMoviesIE(FreeTvBaseIE):
17 _VALID_URL = r'https?://(?:www\.)?freetv\.com/peliculas/(?P<id>[^/]+)'
18 _TESTS = [{
19 'url': 'https://www.freetv.com/peliculas/atrapame-si-puedes/',
20 'md5': 'dc62d5abf0514726640077cd1591aa92',
21 'info_dict': {
22 'id': '428021',
23 'title': 'AtrĂ¡pame Si Puedes',
24 'description': 'md5:ca63bc00898aeb2f64ec87c6d3a5b982',
25 'ext': 'mp4',
26 }
27 }, {
28 'url': 'https://www.freetv.com/peliculas/monstruoso/',
29 'md5': '509c15c68de41cb708d1f92d071f20aa',
30 'info_dict': {
31 'id': '377652',
32 'title': 'Monstruoso',
33 'description': 'md5:333fc19ee327b457b980e54a911ea4a3',
34 'ext': 'mp4',
35 }
36 }]
37
38 def _extract_video(self, content_id, action='olyott_video_play'):
39 api_response = self._get_api_response(content_id, 'video', {
40 'action': action,
41 'contentID': content_id,
42 })
43
44 video_id, video_url = api_response['displayMeta']['contentID'], api_response['displayMeta']['streamURLVideo']
45 formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_url, video_id, 'mp4')
46 self._sort_formats(formats)
47
48 return {
49 'id': video_id,
50 'title': traverse_obj(api_response, ('displayMeta', 'title')),
51 'description': traverse_obj(api_response, ('displayMeta', 'desc')),
52 'formats': formats,
53 'subtitles': subtitles,
54 }
55
56 def _real_extract(self, url):
57 display_id = self._match_id(url)
58 webpage = self._download_webpage(url, display_id)
59
60 return self._extract_video(
61 self._search_regex((
62 r'class=["\'][^>]+postid-(?P<video_id>\d+)',
63 r'<link[^>]+freetv.com/\?p=(?P<video_id>\d+)',
64 r'<div[^>]+data-params=["\'][^>]+post_id=(?P<video_id>\d+)',
65 ), webpage, 'video id', group='video_id'))
66
67
68class FreeTvIE(FreeTvBaseIE):
69 IE_NAME = 'freetv:series'
70 _VALID_URL = r'https?://(?:www\.)?freetv\.com/series/(?P<id>[^/]+)'
71 _TESTS = [{
72 'url': 'https://www.freetv.com/series/el-detective-l/',
73 'info_dict': {
74 'id': 'el-detective-l',
75 'title': 'El Detective L',
76 'description': 'md5:f9f1143bc33e9856ecbfcbfb97a759be'
77 },
78 'playlist_count': 24,
79 }, {
80 'url': 'https://www.freetv.com/series/esmeraldas/',
81 'info_dict': {
82 'id': 'esmeraldas',
83 'title': 'Esmeraldas',
84 'description': 'md5:43d7ec45bd931d8268a4f5afaf4c77bf'
85 },
86 'playlist_count': 62,
87 }, {
88 'url': 'https://www.freetv.com/series/las-aventuras-de-leonardo/',
89 'info_dict': {
90 'id': 'las-aventuras-de-leonardo',
91 'title': 'Las Aventuras de Leonardo',
92 'description': 'md5:0c47130846c141120a382aca059288f6'
93 },
94 'playlist_count': 13,
95 },
96 ]
97
98 def _extract_series_season(self, season_id, series_title):
99 episodes = self._get_api_response(season_id, 'series', {
100 'contentID': season_id,
101 'action': 'olyott_get_dynamic_series_content',
102 'type': 'list',
103 'perPage': '1000',
104 })['1']
105
106 for episode in episodes:
107 video_id = str(episode['contentID'])
108 formats, subtitles = self._extract_m3u8_formats_and_subtitles(episode['streamURL'], video_id, 'mp4')
109 self._sort_formats(formats)
110
111 yield {
112 'id': video_id,
113 'title': episode.get('fullTitle'),
114 'description': episode.get('description'),
115 'formats': formats,
116 'subtitles': subtitles,
117 'thumbnail': episode.get('thumbnail'),
118 'series': series_title,
119 'series_id': traverse_obj(episode, ('contentMeta', 'displayMeta', 'seriesID')),
120 'season_id': traverse_obj(episode, ('contentMeta', 'displayMeta', 'seasonID')),
121 'season_number': traverse_obj(
122 episode, ('contentMeta', 'displayMeta', 'seasonNum'), expected_type=int_or_none),
123 'episode_number': traverse_obj(
124 episode, ('contentMeta', 'displayMeta', 'episodeNum'), expected_type=int_or_none),
125 }
126
127 def _real_extract(self, url):
128 display_id = self._match_id(url)
129 webpage = self._download_webpage(url, display_id)
130
131 title = self._html_search_regex(
132 r'<h1[^>]+class=["\']synopis[^>]>(?P<title>[^<]+)', webpage, 'title', group='title', fatal=False)
133 description = self._html_search_regex(
134 r'<div[^>]+class=["\']+synopis content[^>]><p>(?P<description>[^<]+)',
135 webpage, 'description', group='description', fatal=False)
136
137 return self.playlist_result(
138 itertools.chain.from_iterable(
139 self._extract_series_season(season_id, title)
140 for season_id in re.findall(r'<option[^>]+value=["\'](\d+)["\']', webpage)),
141 display_id, title, description)