1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-28 21:22:13 +00:00
This commit is contained in:
shouldsee 2023-05-10 02:21:27 +08:00
parent 1ebcbb7812
commit d5de6295cf

View file

@ -1,13 +1,9 @@
# coding: utf-8
from __future__ import unicode_literals
import json import json
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
ExtractorError,
float_or_none, float_or_none,
int_or_none, int_or_none,
parse_iso8601, parse_iso8601,
@ -16,248 +12,292 @@ from ..utils import (
class ToggleIE(InfoExtractor): class ToggleIE(InfoExtractor):
IE_NAME = 'toggle' IE_NAME = "toggle"
_VALID_URL = r'(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:[^/]+/){1,}|toggle:)[^/]+-(?P<id>[0-9]+)' _VALID_URL = r"(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:[^/]+/){1,}|toggle:)[^/]+-(?P<id>[0-9]+)"
_TESTS = [{ _TESTS = [
### to be updated {
### deprecated ### to be updated
# 'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115', ### deprecated
'info_dict': { # 'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
'id': '343115', "info_dict": {
'ext': 'mp4', "id": "343115",
'title': 'Lion Moms Premiere', "ext": "mp4",
'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b', "title": "Lion Moms Premiere",
'upload_date': '20150910', "description": "md5:aea1149404bff4d7f7b6da11fafd8e6b",
'timestamp': 1441858274, "upload_date": "20150910",
"timestamp": 1441858274,
},
"params": {
"skip_download": "m3u8 download",
},
}, },
'params': { {
'skip_download': 'm3u8 download', "note": "DRM-protected video",
} ### url deprecated
}, { # 'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413',
'note': 'DRM-protected video', "info_dict": {
### url deprecated "id": "341413",
# 'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413', "ext": "wvm",
'info_dict': { "title": "Dug's Special Mission",
'id': '341413', "description": "md5:e86c6f4458214905c1772398fabc93e0",
'ext': 'wvm', "upload_date": "20150827",
'title': 'Dug\'s Special Mission', "timestamp": 1440644006,
'description': 'md5:e86c6f4458214905c1772398fabc93e0', },
'upload_date': '20150827', "params": {
'timestamp': 1440644006, "skip_download": "DRM-protected wvm download",
},
}, },
'params': { {
'skip_download': 'DRM-protected wvm download', # this also tests correct video id extraction
} "note": "m3u8 links are geo-restricted, but Android/mp4 is okay",
}, ### url deprecated
{ # 'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861',
# this also tests correct video id extraction "info_dict": {
'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay', "id": "332861",
"ext": "mp4",
"title": "28th SEA Games (5 Show) - Episode 11",
"description": "md5:3cd4f5f56c7c3b1340c50a863f896faa",
"upload_date": "20150605",
"timestamp": 1433480166,
},
"params": {
"skip_download": "DRM-protected wvm download",
},
"skip": "m3u8 links are geo-restricted",
},
{
### 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,
},
{
"url": "https://www.mewatch.sg/clips/Seraph-Sun-Aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set-84901",
"only_matching": True,
},
{
"url": "https://www.mewatch.sg/episode/Zero-Calling-S2-E13-The-End-of-The-Beginning-55137",
"only_matching": True,
},
{
### 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 available in Singapore 403 forbidden
"url": "https://www.mewatch.sg/movie/Seven-Days-79641",
"only_matching": True,
},
{
### 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,
},
{
### 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,
},
]
### url deprecated _API_USER = "tvpapi_147"
# 'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861', _API_PASS = "11111"
'info_dict': {
'id': '332861',
'ext': 'mp4',
'title': '28th SEA Games (5 Show) - Episode 11',
'description': 'md5:3cd4f5f56c7c3b1340c50a863f896faa',
'upload_date': '20150605',
'timestamp': 1433480166,
},
'params': {
'skip_download': 'DRM-protected wvm download',
},
'skip': 'm3u8 links are geo-restricted'
},
{
### 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,
}, {
'url':'https://www.mewatch.sg/clips/Seraph-Sun-Aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set-84901',
'only_matching': True,
}, {
'url':'https://www.mewatch.sg/episode/Zero-Calling-S2-E13-The-End-of-The-Beginning-55137',
'only_matching': True,
}, {
### 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 available in Singapore 403 forbidden
'url': 'https://www.mewatch.sg/movie/Seven-Days-79641',
'only_matching': True,
}, {
### 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,
}, {
### 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,
}]
_API_USER = 'tvpapi_147'
_API_PASS = '11111'
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
lang='en' lang = "en"
params = { params = {
'delivery':'stream,progressive', "delivery": "stream,progressive",
'resolution':'External', "resolution": "External",
'segments':'all', "segments": "all",
'lang':lang, "lang": lang,
'ff':'idp,ldp,rpt,cd', "ff": "idp,ldp,rpt,cd",
} }
video_info = self._download_json( video_info = self._download_json(
'https://cdn.mewatch.sg/api/items/'+ video_id +'/videos', "https://cdn.mewatch.sg/api/items/" + video_id + "/videos",
video_id, 'Downloading video info json', query=params) video_id,
"Downloading video info json",
query=params,
)
params = { params = {
# 'delivery':'stream,progressive', # 'delivery':'stream,progressive',
# 'resolution':'External', # 'resolution':'External',
'segments': 'all', "segments": "all",
'lang':lang, "lang": lang,
'ff':'idp,ldp,rpt,cd', "ff": "idp,ldp,rpt,cd",
} }
meta_info = self._download_json( meta_info = self._download_json(
'https://cdn.mewatch.sg/api/items/'+ video_id , "https://cdn.mewatch.sg/api/items/" + video_id,
video_id, 'Downloading video info json', query=params) video_id,
"Downloading video info json",
query=params,
)
# urls = info # urls = info
info = {'Files':video_info} info = {"Files": video_info}
info.update(meta_info) info.update(meta_info)
title = info['path'].rsplit('/',1)[-1] 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)
vid_format = vid_format.replace(' ', '') vid_format = vid_format.replace(" ", "")
# if geo-restricted, m3u8 is inaccessible, but mp4 is okay # if geo-restricted, m3u8 is inaccessible, but mp4 is okay
if ext == 'm3u8': if ext == "m3u8":
m3u8_formats = self._extract_m3u8_formats( m3u8_formats = self._extract_m3u8_formats(
video_url, video_id, ext='mp4', m3u8_id=vid_format, video_url,
note='Downloading %s m3u8 information' % vid_format, video_id,
errnote='Failed to download %s m3u8 information' % vid_format, ext="mp4",
fatal=False) m3u8_id=vid_format,
note="Downloading %s m3u8 information" % vid_format,
errnote="Failed to download %s m3u8 information" % vid_format,
fatal=False,
)
for f in m3u8_formats: for f in m3u8_formats:
# Apple FairPlay Streaming # Apple FairPlay Streaming
if '/fpshls/' in f['url']: if "/fpshls/" in f["url"]:
continue continue
formats.append(f) formats.append(f)
elif ext == 'mpd': elif ext == "mpd":
formats.extend(self._extract_mpd_formats( formats.extend(
video_url, video_id, mpd_id=vid_format, self._extract_mpd_formats(
note='Downloading %s MPD manifest' % vid_format, video_url,
errnote='Failed to download %s MPD manifest' % vid_format, video_id,
fatal=False)) mpd_id=vid_format,
elif ext == 'ism': note="Downloading %s MPD manifest" % vid_format,
formats.extend(self._extract_ism_formats( errnote="Failed to download %s MPD manifest" % vid_format,
video_url, video_id, ism_id=vid_format, fatal=False,
note='Downloading %s ISM manifest' % vid_format, )
errnote='Failed to download %s ISM manifest' % vid_format, )
fatal=False)) elif ext == "ism":
elif ext == 'mp4': formats.extend(
formats.append({ self._extract_ism_formats(
'ext': ext, video_url,
'url': video_url, video_id,
'format_id': vid_format, ism_id=vid_format,
}) note="Downloading %s ISM manifest" % vid_format,
errnote="Failed to download %s ISM manifest" % vid_format,
fatal=False,
)
)
elif ext == "mp4":
formats.append(
{
"ext": ext,
"url": video_url,
"format_id": vid_format,
}
)
if not formats: if not formats:
for meta in (info.get('Metas') or []): for meta in info.get("Metas") or []:
if (not self.get_param('allow_unplayable_formats') if (
and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'): not self.get_param("allow_unplayable_formats")
and meta.get("Key") == "Encryption"
and meta.get("Value") == "1"
):
self.report_drm(video_id) self.report_drm(video_id)
# Most likely because geo-blocked if no formats and no DRM # Most likely because geo-blocked if no formats and no DRM
thumbnails = [] thumbnails = []
for picture in info.get('images', []): for picture in info.get("images", []):
if not isinstance(picture, dict): if not isinstance(picture, dict):
continue continue
pic_url = picture.get('tile') pic_url = picture.get("tile")
if not pic_url: if not pic_url:
continue continue
thumbnail = { thumbnail = {
'url': pic_url, "url": pic_url,
} }
pic_size = picture.get('PicSize', '') pic_size = picture.get("PicSize", "")
m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size) m = re.search(r"(?P<width>\d+)[xX](?P<height>\d+)", pic_size)
if m: if m:
thumbnail.update({ thumbnail.update(
'width': int(m.group('width')), {
'height': int(m.group('height')), "width": int(m.group("width")),
}) "height": int(m.group("height")),
}
)
thumbnails.append(thumbnail) thumbnails.append(thumbnail)
def counter(prefix): def counter(prefix):
return int_or_none( return int_or_none(
info.get(prefix + 'Counter') or info.get(prefix.lower() + '_counter')) info.get(prefix + "Counter") or info.get(prefix.lower() + "_counter")
)
return { return {
'id': video_id, "id": video_id,
'title': title, "title": title,
'description': strip_or_none(info.get('Description')), "description": strip_or_none(info.get("Description")),
'duration': int_or_none(info.get('Duration')), "duration": int_or_none(info.get("Duration")),
'timestamp': parse_iso8601(info.get('CreationDate') or None), "timestamp": parse_iso8601(info.get("CreationDate") or None),
'average_rating': float_or_none(info.get('Rating')), "average_rating": float_or_none(info.get("Rating")),
'view_count': counter('View'), "view_count": counter("View"),
'like_count': counter('Like'), "like_count": counter("Like"),
'thumbnails': thumbnails, "thumbnails": thumbnails,
'formats': formats, "formats": formats,
} }
class MeWatchIE(InfoExtractor): class MeWatchIE(InfoExtractor):
IE_NAME = 'mewatch' IE_NAME = "mewatch"
_VALID_URL = r'https?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)' _VALID_URL = (
_TESTS = [{ r"https?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)"
'url': 'https://www.mewatch.sg/watch/Recipe-Of-Life-E1-179371', )
'info_dict': { _TESTS = [
'id': '1008625', {
'ext': 'mp4', "url": "https://www.mewatch.sg/watch/Recipe-Of-Life-E1-179371",
'title': 'Recipe Of Life 味之道', "info_dict": {
'timestamp': 1603306526, "id": "1008625",
'description': 'md5:6e88cde8af2068444fc8e1bc3ebf257c', "ext": "mp4",
'upload_date': '20201021', "title": "Recipe Of Life 味之道",
"timestamp": 1603306526,
"description": "md5:6e88cde8af2068444fc8e1bc3ebf257c",
"upload_date": "20201021",
},
"params": {
"skip_download": "m3u8 download",
},
}, },
'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-搜密。打卡。小红点-S2-E1-176232', "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, "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,
'url': 'https://live.mewatch.sg/watch/Recipe-Of-Life-E41-189759', },
'only_matching': True, ]
}]
def _real_extract(self, url): def _real_extract(self, url):
item_id = self._match_id(url) item_id = self._match_id(url)
return self.url_result( return self.url_result("toggle:" + item_id, ToggleIE.ie_key(), item_id)
'toggle:' + item_id, ToggleIE.ie_key(), item_id)
print(f'[debug]{item_id}') print(f"[debug]{item_id}")
xdata = self._download_json( 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','lang':'en','ff':'idp,ldp,rpt,cd'}) item_id,
query={"segments": "all", "lang": "en", "ff": "idp,ldp,rpt,cd"},
)
from pprint import pprint from pprint import pprint
pprint(xdata) pprint(xdata)
custom_id = xdata['customId'] custom_id = xdata["customId"]
print(f'[debug]{custom_id}') 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)