1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-28 21:22:13 +00:00

adapt to work for mewatch.sg

This commit is contained in:
shouldsee 2023-05-07 20:54:40 +08:00
parent 211cbfd5d4
commit 1ebcbb7812

View file

@ -17,9 +17,11 @@ from ..utils import (
class ToggleIE(InfoExtractor): class ToggleIE(InfoExtractor):
IE_NAME = 'toggle' IE_NAME = 'toggle'
_VALID_URL = r'(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:en|zh)/(?:[^/]+/){2,}|toggle:)(?P<id>[0-9]+)' _VALID_URL = r'(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:[^/]+/){1,}|toggle:)[^/]+-(?P<id>[0-9]+)'
_TESTS = [{ _TESTS = [{
'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115', ### to be updated
### deprecated
# 'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
'info_dict': { 'info_dict': {
'id': '343115', 'id': '343115',
'ext': 'mp4', 'ext': 'mp4',
@ -33,7 +35,8 @@ class ToggleIE(InfoExtractor):
} }
}, { }, {
'note': 'DRM-protected video', 'note': 'DRM-protected video',
'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413', ### url deprecated
# 'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413',
'info_dict': { 'info_dict': {
'id': '341413', 'id': '341413',
'ext': 'wvm', 'ext': 'wvm',
@ -45,10 +48,13 @@ class ToggleIE(InfoExtractor):
'params': { 'params': {
'skip_download': 'DRM-protected wvm download', 'skip_download': 'DRM-protected wvm download',
} }
}, { },
{
# this also tests correct video id extraction # this also tests correct video id extraction
'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay', 'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay',
'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861',
### url deprecated
# 'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861',
'info_dict': { 'info_dict': {
'id': '332861', 'id': '332861',
'ext': 'mp4', 'ext': 'mp4',
@ -61,26 +67,39 @@ class ToggleIE(InfoExtractor):
'skip_download': 'DRM-protected wvm download', 'skip_download': 'DRM-protected wvm download',
}, },
'skip': 'm3u8 links are geo-restricted' 'skip': 'm3u8 links are geo-restricted'
}, { },
'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
{
### video.toggle.sg seems deprecated
# 'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'http://www.mewatch.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331', 'url':'https://www.mewatch.sg/clips/Seraph-Sun-Aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set-84901',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'http://www.mewatch.sg/zh/series/zero-calling-s2-hd/ep13/336367', 'url':'https://www.mewatch.sg/episode/Zero-Calling-S2-E13-The-End-of-The-Beginning-55137',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302', ### webisodes no longer used
'url':'https://www.mewatch.sg/clips/Jeeva-is-an-orphan-Vetri-S2-Webisode-7-84944',
# 'url': 'http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'http://www.mewatch.sg/en/movies/seven-days/321936', ### only available in Singapore 403 forbidden
'url': 'https://www.mewatch.sg/movie/Seven-Days-79641',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456', ### not working for this list, but not a big issue since old path deprecated
'url':'https://www.mewatch.sg/list/CNA-Singapore-Tonight-154904',
# 'url': 'https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'http://www.mewatch.sg/en/channels/eleven-plus/401585', ### not working. seems deprecated
# 'url': 'http://www.mewatch.sg/en/channels/eleven-plus/401585',
'only_matching': True,
}, {
### [20230507:shouldsee] working
'url' :'https://www.mewatch.sg/watch/Seraph-Sun-Aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set-84901',
'only_matching': True, 'only_matching': True,
}] }]
@ -90,34 +109,38 @@ class ToggleIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
lang='en'
params = { params = {
'initObj': { 'delivery':'stream,progressive',
'Locale': { 'resolution':'External',
'LocaleLanguage': '', 'segments':'all',
'LocaleCountry': '', 'lang':lang,
'LocaleDevice': '', 'ff':'idp,ldp,rpt,cd',
'LocaleUserState': 0 }
}, video_info = self._download_json(
'Platform': 0, 'https://cdn.mewatch.sg/api/items/'+ video_id +'/videos',
'SiteGuid': 0, video_id, 'Downloading video info json', query=params)
'DomainID': '0',
'UDID': '',
'ApiUser': self._API_USER,
'ApiPass': self._API_PASS
},
'MediaID': video_id,
'mediaType': 0,
}
info = self._download_json( params = {
'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo', # 'delivery':'stream,progressive',
video_id, 'Downloading video info json', data=json.dumps(params).encode('utf-8')) # 'resolution':'External',
'segments': 'all',
'lang':lang,
'ff':'idp,ldp,rpt,cd',
}
meta_info = self._download_json(
'https://cdn.mewatch.sg/api/items/'+ video_id ,
video_id, 'Downloading video info json', query=params)
title = info['MediaName'] # urls = info
info = {'Files':video_info}
info.update(meta_info)
title = info['path'].rsplit('/',1)[-1]
formats = [] formats = []
for video_file in info.get('Files', []): for video_file in info.get('Files', []):
video_url, vid_format = video_file.get('URL'), video_file.get('Format') video_url, vid_format = video_file.get('url'), video_file.get('format')
if not video_url or video_url == 'NA' or not vid_format: if not video_url or video_url == 'NA' or not vid_format:
continue continue
ext = determine_ext(video_url) ext = determine_ext(video_url)
@ -154,18 +177,16 @@ class ToggleIE(InfoExtractor):
}) })
if not formats: if not formats:
for meta in (info.get('Metas') or []): for meta in (info.get('Metas') or []):
if meta.get('Key') == 'Encryption' and meta.get('Value') == '1': if (not self.get_param('allow_unplayable_formats')
raise ExtractorError( and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'):
'This video is DRM protected.', expected=True) self.report_drm(video_id)
# Most likely because geo-blocked # Most likely because geo-blocked if no formats and no DRM
raise ExtractorError('No downloadable videos found', expected=True)
self._sort_formats(formats)
thumbnails = [] thumbnails = []
for picture in info.get('Pictures', []): for picture in info.get('images', []):
if not isinstance(picture, dict): if not isinstance(picture, dict):
continue continue
pic_url = picture.get('URL') pic_url = picture.get('tile')
if not pic_url: if not pic_url:
continue continue
thumbnail = { thumbnail = {
@ -227,8 +248,16 @@ class MeWatchIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
item_id = self._match_id(url) item_id = self._match_id(url)
custom_id = self._download_json( return self.url_result(
'toggle:' + item_id, ToggleIE.ie_key(), item_id)
print(f'[debug]{item_id}')
xdata = self._download_json(
'https://cdn.mewatch.sg/api/items/' + item_id, 'https://cdn.mewatch.sg/api/items/' + item_id,
item_id, query={'segments': 'all'})['customId'] item_id, query={'segments': 'all','lang':'en','ff':'idp,ldp,rpt,cd'})
from pprint import pprint
pprint(xdata)
custom_id = xdata['customId']
print(f'[debug]{custom_id}')
return self.url_result( return self.url_result(
'toggle:' + custom_id, ToggleIE.ie_key(), custom_id) 'toggle:' + custom_id, ToggleIE.ie_key(), custom_id)