]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/manoto.py
Fix bug in `--alias`
[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 self._sort_formats(formats)
58 return {
59 'id': video_id,
60 'series': details.get('showTitle'),
61 'season_number': int_or_none(details.get('analyticsSeasonNumber')),
62 'episode_number': int_or_none(details.get('episodeNumber')),
63 'episode_id': details.get('analyticsEpisodeTitle'),
64 'duration': int_or_none(details.get('durationInMinutes'), invscale=60),
65 'view_count': details.get('viewCount'),
66 'categories': [details.get('videoCategory')],
67 'title': details.get('episodeTitle'),
68 'description': clean_html(details.get('episodeDescription')),
69 'thumbnail': details.get('episodelandscapeImgIxUrl'),
70 'formats': formats,
71 }
72
73
74 class ManotoTVShowIE(InfoExtractor):
75 IE_DESC = 'Manoto TV (Show)'
76 _VALID_URL = r'https?://(?:www\.)?manototv\.com/show/(?P<id>[0-9]+)'
77 _TESTS = [{
78 'url': 'https://www.manototv.com/show/2526',
79 'playlist_mincount': 68,
80 'info_dict': {
81 'id': '2526',
82 'title': 'فیلم های ایرانی',
83 'description': 'مجموعه ای از فیلم های سینمای کلاسیک ایران',
84 },
85 }]
86
87 def _real_extract(self, url):
88 show_id = self._match_id(url)
89 show_json = self._download_json(_API_URL.format('showmodule', 'details', show_id), show_id)
90 show_details = show_json.get('details', {})
91 title = show_details.get('showTitle')
92 description = show_details.get('showSynopsis')
93
94 series_json = self._download_json(_API_URL.format('showmodule', 'serieslist', show_id), show_id)
95 playlist_id = str(traverse_obj(series_json, ('details', 'list', 0, 'id')))
96
97 playlist_json = self._download_json(_API_URL.format('showmodule', 'episodelist', playlist_id), playlist_id)
98 playlist = traverse_obj(playlist_json, ('details', 'list')) or []
99
100 entries = [
101 self.url_result(
102 'https://www.manototv.com/episode/%s' % item['slideID'], ie=ManotoTVIE.ie_key(), video_id=item['slideID'])
103 for item in playlist]
104 return self.playlist_result(entries, show_id, title, description)
105
106
107 class ManotoTVLiveIE(InfoExtractor):
108 IE_DESC = 'Manoto TV (Live)'
109 _VALID_URL = r'https?://(?:www\.)?manototv\.com/live/'
110 _TEST = {
111 'url': 'https://www.manototv.com/live/',
112 'info_dict': {
113 'id': 'live',
114 'title': 'Manoto TV Live',
115 'ext': 'mp4',
116 'is_live': True,
117 },
118 'params': {
119 'skip_download': 'm3u8',
120 }
121 }
122
123 def _real_extract(self, url):
124 video_id = 'live'
125 json = self._download_json(_API_URL.format('livemodule', 'details', ''), video_id)
126 details = json.get('details', {})
127 video_url = details.get('liveUrl')
128 formats = self._extract_m3u8_formats(video_url, video_id, 'mp4', live=True)
129 self._sort_formats(formats)
130 return {
131 'id': video_id,
132 'title': 'Manoto TV Live',
133 'is_live': True,
134 'formats': formats,
135 }