logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

toggle.py (7892B)


  1. import json
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. float_or_none,
  7. int_or_none,
  8. parse_iso8601,
  9. strip_or_none,
  10. )
  11. class ToggleIE(InfoExtractor):
  12. IE_NAME = 'toggle'
  13. _VALID_URL = r'(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:en|zh)/(?:[^/]+/){2,}|toggle:)(?P<id>[0-9]+)'
  14. _TESTS = [{
  15. 'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
  16. 'info_dict': {
  17. 'id': '343115',
  18. 'ext': 'mp4',
  19. 'title': 'Lion Moms Premiere',
  20. 'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b',
  21. 'upload_date': '20150910',
  22. 'timestamp': 1441858274,
  23. },
  24. 'params': {
  25. 'skip_download': 'm3u8 download',
  26. },
  27. }, {
  28. 'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://www.mewatch.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://www.mewatch.sg/zh/series/zero-calling-s2-hd/ep13/336367',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.mewatch.sg/en/movies/seven-days/321936',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'http://www.mewatch.sg/en/channels/eleven-plus/401585',
  53. 'only_matching': True,
  54. }]
  55. _API_USER = 'tvpapi_147'
  56. _API_PASS = '11111'
  57. def _real_extract(self, url):
  58. video_id = self._match_id(url)
  59. params = {
  60. 'initObj': {
  61. 'Locale': {
  62. 'LocaleLanguage': '',
  63. 'LocaleCountry': '',
  64. 'LocaleDevice': '',
  65. 'LocaleUserState': 0,
  66. },
  67. 'Platform': 0,
  68. 'SiteGuid': 0,
  69. 'DomainID': '0',
  70. 'UDID': '',
  71. 'ApiUser': self._API_USER,
  72. 'ApiPass': self._API_PASS,
  73. },
  74. 'MediaID': video_id,
  75. 'mediaType': 0,
  76. }
  77. info = self._download_json(
  78. 'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
  79. video_id, 'Downloading video info json', data=json.dumps(params).encode())
  80. title = info['MediaName']
  81. formats = []
  82. for video_file in info.get('Files', []):
  83. video_url, vid_format = video_file.get('URL'), video_file.get('Format')
  84. if not video_url or video_url == 'NA' or not vid_format:
  85. continue
  86. ext = determine_ext(video_url)
  87. vid_format = vid_format.replace(' ', '')
  88. # if geo-restricted, m3u8 is inaccessible, but mp4 is okay
  89. if ext == 'm3u8':
  90. m3u8_formats = self._extract_m3u8_formats(
  91. video_url, video_id, ext='mp4', m3u8_id=vid_format,
  92. note=f'Downloading {vid_format} m3u8 information',
  93. errnote=f'Failed to download {vid_format} m3u8 information',
  94. fatal=False)
  95. for f in m3u8_formats:
  96. # Apple FairPlay Streaming
  97. if '/fpshls/' in f['url']:
  98. continue
  99. formats.append(f)
  100. elif ext == 'mpd':
  101. formats.extend(self._extract_mpd_formats(
  102. video_url, video_id, mpd_id=vid_format,
  103. note=f'Downloading {vid_format} MPD manifest',
  104. errnote=f'Failed to download {vid_format} MPD manifest',
  105. fatal=False))
  106. elif ext == 'ism':
  107. formats.extend(self._extract_ism_formats(
  108. video_url, video_id, ism_id=vid_format,
  109. note=f'Downloading {vid_format} ISM manifest',
  110. errnote=f'Failed to download {vid_format} ISM manifest',
  111. fatal=False))
  112. elif ext == 'mp4':
  113. formats.append({
  114. 'ext': ext,
  115. 'url': video_url,
  116. 'format_id': vid_format,
  117. })
  118. if not formats:
  119. for meta in (info.get('Metas') or []):
  120. if (not self.get_param('allow_unplayable_formats')
  121. and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'):
  122. self.report_drm(video_id)
  123. # Most likely because geo-blocked if no formats and no DRM
  124. thumbnails = []
  125. for picture in info.get('Pictures', []):
  126. if not isinstance(picture, dict):
  127. continue
  128. pic_url = picture.get('URL')
  129. if not pic_url:
  130. continue
  131. thumbnail = {
  132. 'url': pic_url,
  133. }
  134. pic_size = picture.get('PicSize', '')
  135. m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size)
  136. if m:
  137. thumbnail.update({
  138. 'width': int(m.group('width')),
  139. 'height': int(m.group('height')),
  140. })
  141. thumbnails.append(thumbnail)
  142. def counter(prefix):
  143. return int_or_none(
  144. info.get(prefix + 'Counter') or info.get(prefix.lower() + '_counter'))
  145. return {
  146. 'id': video_id,
  147. 'title': title,
  148. 'description': strip_or_none(info.get('Description')),
  149. 'duration': int_or_none(info.get('Duration')),
  150. 'timestamp': parse_iso8601(info.get('CreationDate') or None),
  151. 'average_rating': float_or_none(info.get('Rating')),
  152. 'view_count': counter('View'),
  153. 'like_count': counter('Like'),
  154. 'thumbnails': thumbnails,
  155. 'formats': formats,
  156. }
  157. class MeWatchIE(InfoExtractor):
  158. IE_NAME = 'mewatch'
  159. _VALID_URL = r'https?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)'
  160. _TESTS = [{
  161. 'url': 'https://www.mewatch.sg/watch/Recipe-Of-Life-E1-179371',
  162. 'info_dict': {
  163. 'id': '1008625',
  164. 'ext': 'mp4',
  165. 'title': 'Recipe Of Life 味之道',
  166. 'timestamp': 1603306526,
  167. 'description': 'md5:6e88cde8af2068444fc8e1bc3ebf257c',
  168. 'upload_date': '20201021',
  169. },
  170. 'params': {
  171. 'skip_download': 'm3u8 download',
  172. },
  173. }, {
  174. 'url': 'https://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-搜密。打卡。小红点-S2-E1-176232',
  175. 'only_matching': True,
  176. }, {
  177. 'url': 'https://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-%E6%90%9C%E5%AF%86%E3%80%82%E6%89%93%E5%8D%A1%E3%80%82%E5%B0%8F%E7%BA%A2%E7%82%B9-S2-E1-176232',
  178. 'only_matching': True,
  179. }, {
  180. 'url': 'https://live.mewatch.sg/watch/Recipe-Of-Life-E41-189759',
  181. 'only_matching': True,
  182. }]
  183. def _real_extract(self, url):
  184. item_id = self._match_id(url)
  185. custom_id = self._download_json(
  186. 'https://cdn.mewatch.sg/api/items/' + item_id,
  187. item_id, query={'segments': 'all'})['customId']
  188. return self.url_result(
  189. 'toggle:' + custom_id, ToggleIE.ie_key(), custom_id)