manoto.py 5.0 KB

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