]>
Commit | Line | Data |
---|---|---|
e0a4a3d5 E |
1 | import itertools |
2 | import re | |
3 | ||
4 | from .common import InfoExtractor | |
56ba69e4 | 5 | from ..utils import int_or_none, traverse_obj, urlencode_postdata |
e0a4a3d5 E |
6 | |
7 | ||
8 | class 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 | ||
16 | class 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') | |
e0a4a3d5 E |
46 | |
47 | return { | |
48 | 'id': video_id, | |
49 | 'title': traverse_obj(api_response, ('displayMeta', 'title')), | |
50 | 'description': traverse_obj(api_response, ('displayMeta', 'desc')), | |
51 | 'formats': formats, | |
52 | 'subtitles': subtitles, | |
53 | } | |
54 | ||
55 | def _real_extract(self, url): | |
56 | display_id = self._match_id(url) | |
57 | webpage = self._download_webpage(url, display_id) | |
58 | ||
59 | return self._extract_video( | |
60 | self._search_regex(( | |
61 | r'class=["\'][^>]+postid-(?P<video_id>\d+)', | |
62 | r'<link[^>]+freetv.com/\?p=(?P<video_id>\d+)', | |
63 | r'<div[^>]+data-params=["\'][^>]+post_id=(?P<video_id>\d+)', | |
64 | ), webpage, 'video id', group='video_id')) | |
65 | ||
66 | ||
67 | class FreeTvIE(FreeTvBaseIE): | |
68 | IE_NAME = 'freetv:series' | |
69 | _VALID_URL = r'https?://(?:www\.)?freetv\.com/series/(?P<id>[^/]+)' | |
70 | _TESTS = [{ | |
71 | 'url': 'https://www.freetv.com/series/el-detective-l/', | |
72 | 'info_dict': { | |
73 | 'id': 'el-detective-l', | |
74 | 'title': 'El Detective L', | |
75 | 'description': 'md5:f9f1143bc33e9856ecbfcbfb97a759be' | |
76 | }, | |
77 | 'playlist_count': 24, | |
78 | }, { | |
79 | 'url': 'https://www.freetv.com/series/esmeraldas/', | |
80 | 'info_dict': { | |
81 | 'id': 'esmeraldas', | |
82 | 'title': 'Esmeraldas', | |
83 | 'description': 'md5:43d7ec45bd931d8268a4f5afaf4c77bf' | |
84 | }, | |
85 | 'playlist_count': 62, | |
86 | }, { | |
87 | 'url': 'https://www.freetv.com/series/las-aventuras-de-leonardo/', | |
88 | 'info_dict': { | |
89 | 'id': 'las-aventuras-de-leonardo', | |
90 | 'title': 'Las Aventuras de Leonardo', | |
91 | 'description': 'md5:0c47130846c141120a382aca059288f6' | |
92 | }, | |
93 | 'playlist_count': 13, | |
94 | }, | |
95 | ] | |
96 | ||
97 | def _extract_series_season(self, season_id, series_title): | |
98 | episodes = self._get_api_response(season_id, 'series', { | |
99 | 'contentID': season_id, | |
100 | 'action': 'olyott_get_dynamic_series_content', | |
101 | 'type': 'list', | |
102 | 'perPage': '1000', | |
103 | })['1'] | |
104 | ||
105 | for episode in episodes: | |
106 | video_id = str(episode['contentID']) | |
107 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(episode['streamURL'], video_id, 'mp4') | |
e0a4a3d5 E |
108 | |
109 | yield { | |
110 | 'id': video_id, | |
111 | 'title': episode.get('fullTitle'), | |
112 | 'description': episode.get('description'), | |
113 | 'formats': formats, | |
114 | 'subtitles': subtitles, | |
115 | 'thumbnail': episode.get('thumbnail'), | |
116 | 'series': series_title, | |
117 | 'series_id': traverse_obj(episode, ('contentMeta', 'displayMeta', 'seriesID')), | |
118 | 'season_id': traverse_obj(episode, ('contentMeta', 'displayMeta', 'seasonID')), | |
119 | 'season_number': traverse_obj( | |
120 | episode, ('contentMeta', 'displayMeta', 'seasonNum'), expected_type=int_or_none), | |
121 | 'episode_number': traverse_obj( | |
122 | episode, ('contentMeta', 'displayMeta', 'episodeNum'), expected_type=int_or_none), | |
123 | } | |
124 | ||
125 | def _real_extract(self, url): | |
126 | display_id = self._match_id(url) | |
127 | webpage = self._download_webpage(url, display_id) | |
128 | ||
129 | title = self._html_search_regex( | |
130 | r'<h1[^>]+class=["\']synopis[^>]>(?P<title>[^<]+)', webpage, 'title', group='title', fatal=False) | |
131 | description = self._html_search_regex( | |
132 | r'<div[^>]+class=["\']+synopis content[^>]><p>(?P<description>[^<]+)', | |
133 | webpage, 'description', group='description', fatal=False) | |
134 | ||
135 | return self.playlist_result( | |
136 | itertools.chain.from_iterable( | |
137 | self._extract_series_season(season_id, title) | |
138 | for season_id in re.findall(r'<option[^>]+value=["\'](\d+)["\']', webpage)), | |
139 | display_id, title, description) |