2015-09-16 23:51:50 -06:00
|
|
|
import json
|
2015-12-19 06:19:26 -07:00
|
|
|
import re
|
2015-09-16 23:51:50 -06:00
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
2015-12-19 06:04:38 -07:00
|
|
|
determine_ext,
|
2015-12-19 06:23:28 -07:00
|
|
|
float_or_none,
|
2015-09-16 23:51:50 -06:00
|
|
|
int_or_none,
|
|
|
|
parse_iso8601,
|
2021-01-01 05:26:37 -07:00
|
|
|
strip_or_none,
|
2015-09-16 23:51:50 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-12-19 06:59:00 -07:00
|
|
|
class ToggleIE(InfoExtractor):
|
2015-12-19 10:11:23 -07:00
|
|
|
IE_NAME = 'toggle'
|
2021-01-01 05:26:37 -07:00
|
|
|
_VALID_URL = r'(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:en|zh)/(?:[^/]+/){2,}|toggle:)(?P<id>[0-9]+)'
|
2015-09-16 23:51:50 -06:00
|
|
|
_TESTS = [{
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
|
2015-09-16 23:51:50 -06:00
|
|
|
'info_dict': {
|
|
|
|
'id': '343115',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Lion Moms Premiere',
|
|
|
|
'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b',
|
|
|
|
'upload_date': '20150910',
|
|
|
|
'timestamp': 1441858274,
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': 'm3u8 download',
|
2024-06-11 17:09:58 -06:00
|
|
|
},
|
2015-09-16 23:51:50 -06:00
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413',
|
2024-07-07 15:23:40 -06:00
|
|
|
'only_matching': True,
|
2015-09-16 23:51:50 -06:00
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861',
|
2024-07-07 15:23:40 -06:00
|
|
|
'only_matching': True,
|
2015-09-16 23:51:50 -06:00
|
|
|
}, {
|
|
|
|
'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,
|
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
|
2015-09-16 23:51:50 -06:00
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/zh/series/zero-calling-s2-hd/ep13/336367',
|
2015-09-16 23:51:50 -06:00
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302',
|
2015-09-16 23:51:50 -06:00
|
|
|
'only_matching': True,
|
2017-05-20 10:06:30 -06:00
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'http://www.mewatch.sg/en/movies/seven-days/321936',
|
2017-05-20 10:06:30 -06:00
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
2020-02-05 08:41:56 -07:00
|
|
|
'url': 'https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'http://www.mewatch.sg/en/channels/eleven-plus/401585',
|
2017-05-20 10:06:30 -06:00
|
|
|
'only_matching': True,
|
2015-09-16 23:51:50 -06:00
|
|
|
}]
|
|
|
|
|
|
|
|
_API_USER = 'tvpapi_147'
|
|
|
|
_API_PASS = '11111'
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
|
|
params = {
|
|
|
|
'initObj': {
|
|
|
|
'Locale': {
|
2015-12-19 06:06:05 -07:00
|
|
|
'LocaleLanguage': '',
|
|
|
|
'LocaleCountry': '',
|
|
|
|
'LocaleDevice': '',
|
2024-06-11 17:09:58 -06:00
|
|
|
'LocaleUserState': 0,
|
2015-09-16 23:51:50 -06:00
|
|
|
},
|
2015-12-19 06:06:05 -07:00
|
|
|
'Platform': 0,
|
|
|
|
'SiteGuid': 0,
|
|
|
|
'DomainID': '0',
|
|
|
|
'UDID': '',
|
2021-01-01 05:26:37 -07:00
|
|
|
'ApiUser': self._API_USER,
|
2024-06-11 17:09:58 -06:00
|
|
|
'ApiPass': self._API_PASS,
|
2015-09-16 23:51:50 -06:00
|
|
|
},
|
|
|
|
'MediaID': video_id,
|
|
|
|
'mediaType': 0,
|
|
|
|
}
|
|
|
|
|
2021-01-01 05:26:37 -07:00
|
|
|
info = self._download_json(
|
2015-09-16 23:51:50 -06:00
|
|
|
'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
|
2024-06-11 17:09:58 -06:00
|
|
|
video_id, 'Downloading video info json', data=json.dumps(params).encode())
|
2015-09-16 23:51:50 -06:00
|
|
|
|
|
|
|
title = info['MediaName']
|
|
|
|
|
2015-12-19 06:19:26 -07:00
|
|
|
formats = []
|
2015-09-16 23:51:50 -06:00
|
|
|
for video_file in info.get('Files', []):
|
2015-12-19 06:52:37 -07:00
|
|
|
video_url, vid_format = video_file.get('URL'), video_file.get('Format')
|
2018-02-28 08:55:09 -07:00
|
|
|
if not video_url or video_url == 'NA' or not vid_format:
|
2015-12-19 06:52:37 -07:00
|
|
|
continue
|
|
|
|
ext = determine_ext(video_url)
|
|
|
|
vid_format = vid_format.replace(' ', '')
|
2015-09-16 23:51:50 -06:00
|
|
|
# if geo-restricted, m3u8 is inaccessible, but mp4 is okay
|
|
|
|
if ext == 'm3u8':
|
2021-01-01 05:26:37 -07:00
|
|
|
m3u8_formats = self._extract_m3u8_formats(
|
2015-12-19 06:52:37 -07:00
|
|
|
video_url, video_id, ext='mp4', m3u8_id=vid_format,
|
2024-06-11 17:09:58 -06:00
|
|
|
note=f'Downloading {vid_format} m3u8 information',
|
|
|
|
errnote=f'Failed to download {vid_format} m3u8 information',
|
2021-01-01 05:26:37 -07:00
|
|
|
fatal=False)
|
|
|
|
for f in m3u8_formats:
|
|
|
|
# Apple FairPlay Streaming
|
|
|
|
if '/fpshls/' in f['url']:
|
|
|
|
continue
|
|
|
|
formats.append(f)
|
2018-02-28 08:55:09 -07:00
|
|
|
elif ext == 'mpd':
|
|
|
|
formats.extend(self._extract_mpd_formats(
|
|
|
|
video_url, video_id, mpd_id=vid_format,
|
2024-06-11 17:09:58 -06:00
|
|
|
note=f'Downloading {vid_format} MPD manifest',
|
|
|
|
errnote=f'Failed to download {vid_format} MPD manifest',
|
2018-02-28 08:55:09 -07:00
|
|
|
fatal=False))
|
|
|
|
elif ext == 'ism':
|
|
|
|
formats.extend(self._extract_ism_formats(
|
|
|
|
video_url, video_id, ism_id=vid_format,
|
2024-06-11 17:09:58 -06:00
|
|
|
note=f'Downloading {vid_format} ISM manifest',
|
|
|
|
errnote=f'Failed to download {vid_format} ISM manifest',
|
2018-02-28 08:55:09 -07:00
|
|
|
fatal=False))
|
2021-01-01 05:26:37 -07:00
|
|
|
elif ext == 'mp4':
|
2015-09-16 23:51:50 -06:00
|
|
|
formats.append({
|
|
|
|
'ext': ext,
|
2015-12-19 06:52:37 -07:00
|
|
|
'url': video_url,
|
2015-09-16 23:51:50 -06:00
|
|
|
'format_id': vid_format,
|
|
|
|
})
|
|
|
|
if not formats:
|
2021-01-01 05:26:37 -07:00
|
|
|
for meta in (info.get('Metas') or []):
|
2021-05-17 06:23:08 -06:00
|
|
|
if (not self.get_param('allow_unplayable_formats')
|
2021-02-11 21:34:04 -07:00
|
|
|
and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'):
|
2021-08-22 14:08:38 -06:00
|
|
|
self.report_drm(video_id)
|
2021-04-16 18:09:58 -06:00
|
|
|
# Most likely because geo-blocked if no formats and no DRM
|
2015-09-16 23:51:50 -06:00
|
|
|
|
2015-12-19 06:19:26 -07:00
|
|
|
thumbnails = []
|
|
|
|
for picture in info.get('Pictures', []):
|
|
|
|
if not isinstance(picture, dict):
|
|
|
|
continue
|
|
|
|
pic_url = picture.get('URL')
|
|
|
|
if not pic_url:
|
|
|
|
continue
|
|
|
|
thumbnail = {
|
|
|
|
'url': pic_url,
|
|
|
|
}
|
|
|
|
pic_size = picture.get('PicSize', '')
|
|
|
|
m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size)
|
|
|
|
if m:
|
|
|
|
thumbnail.update({
|
|
|
|
'width': int(m.group('width')),
|
|
|
|
'height': int(m.group('height')),
|
|
|
|
})
|
|
|
|
thumbnails.append(thumbnail)
|
|
|
|
|
2021-01-01 05:26:37 -07:00
|
|
|
def counter(prefix):
|
|
|
|
return int_or_none(
|
|
|
|
info.get(prefix + 'Counter') or info.get(prefix.lower() + '_counter'))
|
|
|
|
|
2015-09-16 23:51:50 -06:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
2021-01-01 05:26:37 -07:00
|
|
|
'description': strip_or_none(info.get('Description')),
|
|
|
|
'duration': int_or_none(info.get('Duration')),
|
|
|
|
'timestamp': parse_iso8601(info.get('CreationDate') or None),
|
|
|
|
'average_rating': float_or_none(info.get('Rating')),
|
|
|
|
'view_count': counter('View'),
|
|
|
|
'like_count': counter('Like'),
|
2015-12-19 06:19:26 -07:00
|
|
|
'thumbnails': thumbnails,
|
2015-09-16 23:51:50 -06:00
|
|
|
'formats': formats,
|
|
|
|
}
|
2021-01-01 05:26:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
class MeWatchIE(InfoExtractor):
|
|
|
|
IE_NAME = 'mewatch'
|
|
|
|
_VALID_URL = r'https?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)'
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.mewatch.sg/watch/Recipe-Of-Life-E1-179371',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '1008625',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Recipe Of Life 味之道',
|
|
|
|
'timestamp': 1603306526,
|
|
|
|
'description': 'md5:6e88cde8af2068444fc8e1bc3ebf257c',
|
|
|
|
'upload_date': '20201021',
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': 'm3u8 download',
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-搜密。打卡。小红点-S2-E1-176232',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'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',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://live.mewatch.sg/watch/Recipe-Of-Life-E41-189759',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
item_id = self._match_id(url)
|
|
|
|
custom_id = self._download_json(
|
|
|
|
'https://cdn.mewatch.sg/api/items/' + item_id,
|
|
|
|
item_id, query={'segments': 'all'})['customId']
|
|
|
|
return self.url_result(
|
|
|
|
'toggle:' + custom_id, ToggleIE.ie_key(), custom_id)
|