]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/manoto.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / manoto.py
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 int_or_none,
5 traverse_obj
6 )
7
8
9 _API_URL = 'https://dak1vd5vmi7x6.cloudfront.net/api/v1/publicrole/{}/{}?id={}'
10
11
12 class ManotoTVIE(InfoExtractor):
13 IE_DESC = 'Manoto TV (Episode)'
14 _VALID_URL = r'https?://(?:www\.)?manototv\.com/episode/(?P<id>[0-9]+)'
15 _TESTS = [{
16 'url': 'https://www.manototv.com/episode/8475',
17 'info_dict': {
18 'id': '8475',
19 'series': 'خانه های رویایی با برادران اسکات',
20 'season_number': 7,
21 'episode_number': 25,
22 'episode_id': 'My Dream Home S7: Carol & John',
23 'duration': 3600,
24 'categories': ['سرگرمی'],
25 'title': 'کارول و جان',
26 'description': 'md5:d0fff1f8ba5c6775d312a00165d1a97e',
27 'thumbnail': r're:^https?://.*\.(jpeg|png|jpg)$',
28 'ext': 'mp4'
29 },
30 'params': {
31 'skip_download': 'm3u8',
32 }
33 }, {
34 'url': 'https://www.manototv.com/episode/12576',
35 'info_dict': {
36 'id': '12576',
37 'series': 'فیلم های ایرانی',
38 'episode_id': 'Seh Mah Taatili',
39 'duration': 5400,
40 'view_count': int,
41 'categories': ['سرگرمی'],
42 'title': 'سه ماه تعطیلی',
43 'description': 'سه ماه تعطیلی فیلمی به کارگردانی و نویسندگی شاپور قریب ساختهٔ سال ۱۳۵۶ است.',
44 'thumbnail': r're:^https?://.*\.(jpeg|png|jpg)$',
45 'ext': 'mp4'
46 },
47 'params': {
48 'skip_download': 'm3u8',
49 }
50 }]
51
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54 episode_json = self._download_json(_API_URL.format('showmodule', 'episodedetails', video_id), video_id)
55 details = episode_json.get('details', {})
56 formats = self._extract_m3u8_formats(details.get('videoM3u8Url'), video_id, 'mp4')
57 return {
58 'id': video_id,
59 'series': details.get('showTitle'),
60 'season_number': int_or_none(details.get('analyticsSeasonNumber')),
61 'episode_number': int_or_none(details.get('episodeNumber')),
62 'episode_id': details.get('analyticsEpisodeTitle'),
63 'duration': int_or_none(details.get('durationInMinutes'), invscale=60),
64 'view_count': details.get('viewCount'),
65 'categories': [details.get('videoCategory')],
66 'title': details.get('episodeTitle'),
67 'description': clean_html(details.get('episodeDescription')),
68 'thumbnail': details.get('episodelandscapeImgIxUrl'),
69 'formats': formats,
70 }
71
72
73 class ManotoTVShowIE(InfoExtractor):
74 IE_DESC = 'Manoto TV (Show)'
75 _VALID_URL = r'https?://(?:www\.)?manototv\.com/show/(?P<id>[0-9]+)'
76 _TESTS = [{
77 'url': 'https://www.manototv.com/show/2526',
78 'playlist_mincount': 68,
79 'info_dict': {
80 'id': '2526',
81 'title': 'فیلم های ایرانی',
82 'description': 'مجموعه ای از فیلم های سینمای کلاسیک ایران',
83 },
84 }]
85
86 def _real_extract(self, url):
87 show_id = self._match_id(url)
88 show_json = self._download_json(_API_URL.format('showmodule', 'details', show_id), show_id)
89 show_details = show_json.get('details', {})
90 title = show_details.get('showTitle')
91 description = show_details.get('showSynopsis')
92
93 series_json = self._download_json(_API_URL.format('showmodule', 'serieslist', show_id), show_id)
94 playlist_id = str(traverse_obj(series_json, ('details', 'list', 0, 'id')))
95
96 playlist_json = self._download_json(_API_URL.format('showmodule', 'episodelist', playlist_id), playlist_id)
97 playlist = traverse_obj(playlist_json, ('details', 'list')) or []
98
99 entries = [
100 self.url_result(
101 'https://www.manototv.com/episode/%s' % item['slideID'], ie=ManotoTVIE.ie_key(), video_id=item['slideID'])
102 for item in playlist]
103 return self.playlist_result(entries, show_id, title, description)
104
105
106 class ManotoTVLiveIE(InfoExtractor):
107 IE_DESC = 'Manoto TV (Live)'
108 _VALID_URL = r'https?://(?:www\.)?manototv\.com/live/'
109 _TEST = {
110 'url': 'https://www.manototv.com/live/',
111 'info_dict': {
112 'id': 'live',
113 'title': 'Manoto TV Live',
114 'ext': 'mp4',
115 'is_live': True,
116 },
117 'params': {
118 'skip_download': 'm3u8',
119 }
120 }
121
122 def _real_extract(self, url):
123 video_id = 'live'
124 json = self._download_json(_API_URL.format('livemodule', 'details', ''), video_id)
125 details = json.get('details', {})
126 video_url = details.get('liveUrl')
127 formats = self._extract_m3u8_formats(video_url, video_id, 'mp4', live=True)
128 return {
129 'id': video_id,
130 'title': 'Manoto TV Live',
131 'is_live': True,
132 'formats': formats,
133 }