1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-22 16:44:32 +01:00

download subtitles for mewatch.sg

This commit is contained in:
Huey 2020-07-05 12:51:24 +08:00
parent 07af16b92e
commit cfe81de220
No known key found for this signature in database
GPG Key ID: 54C82E718C137231

View File

@ -4,15 +4,10 @@ from __future__ import unicode_literals
import json
import re
from ..utils import (ExtractorError, determine_ext, error_to_compat_str,
float_or_none, int_or_none, parse_iso8601,
sanitized_Request)
from .common import InfoExtractor
from ..utils import (
determine_ext,
ExtractorError,
float_or_none,
int_or_none,
parse_iso8601,
sanitized_Request,
)
class ToggleIE(InfoExtractor):
@ -93,7 +88,29 @@ class ToggleIE(InfoExtractor):
_API_USER = 'tvpapi_147'
_API_PASS = '11111'
def _real_extract(self, url):
def _get_subtitles(self, video_id):
req = sanitized_Request(
'https://sub.toggle.sg/toggle_api/v1.0/apiService/getSubtitleFilesForMedia?mediaId={0}'.format(video_id),
)
subFiles = self._download_json(req, video_id, 'Downloading subtitles json').get('subtitleFiles', [])
subtitles = dict()
if len(subFiles) == 0:
return {}
for sub in subFiles:
url = sub.get('subtitleFileUrl')
if url is not None:
subtitles.setdefault(sub.get('subtitleFileLanguage'), []).append(dict(
url=url,
ext=re.search(
r'\.(\w{3,4})$',
url
).group(1)
))
return subtitles
def _real_extract(self, url, api_url='https://tvpapi-as.ott.kaltura.com/v3_9/gateways/jsonpostgw.aspx?m=GetMediaInfo'):
video_id = self._match_id(url)
webpage = self._download_webpage(
@ -125,9 +142,11 @@ class ToggleIE(InfoExtractor):
'mediaType': 0,
}
try:
req = sanitized_Request(
'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
json.dumps(params).encode('utf-8'))
api_url,
json.dumps(params).encode('utf-8')
)
info = self._download_json(req, video_id, 'Downloading video info json')
title = info['MediaName']
@ -199,6 +218,8 @@ class ToggleIE(InfoExtractor):
})
thumbnails.append(thumbnail)
subtitles = self._get_subtitles(video_id)
return {
'id': video_id,
'title': title,
@ -210,4 +231,14 @@ class ToggleIE(InfoExtractor):
'like_count': like_count,
'thumbnails': thumbnails,
'formats': formats,
'subtitles': subtitles
}
except ExtractorError as err:
self._downloader.report_warning(
'Could not get metadata from tvpapi-as.ott.kaltura.com: %s \nTrying tvpapi.as.tvinci.com instead'
% error_to_compat_str(err)
)
self._real_extract(
video_id,
api_url='http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo'
)