mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-07 06:17:24 +08:00
download subtitles for mewatch.sg
This commit is contained in:
parent
07af16b92e
commit
cfe81de220
@ -4,15 +4,10 @@ from __future__ import unicode_literals
|
|||||||
import json
|
import json
|
||||||
import re
|
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 .common import InfoExtractor
|
||||||
from ..utils import (
|
|
||||||
determine_ext,
|
|
||||||
ExtractorError,
|
|
||||||
float_or_none,
|
|
||||||
int_or_none,
|
|
||||||
parse_iso8601,
|
|
||||||
sanitized_Request,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ToggleIE(InfoExtractor):
|
class ToggleIE(InfoExtractor):
|
||||||
@ -93,7 +88,29 @@ class ToggleIE(InfoExtractor):
|
|||||||
_API_USER = 'tvpapi_147'
|
_API_USER = 'tvpapi_147'
|
||||||
_API_PASS = '11111'
|
_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)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
webpage = self._download_webpage(
|
webpage = self._download_webpage(
|
||||||
@ -125,9 +142,11 @@ class ToggleIE(InfoExtractor):
|
|||||||
'mediaType': 0,
|
'mediaType': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
req = sanitized_Request(
|
req = sanitized_Request(
|
||||||
'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
|
api_url,
|
||||||
json.dumps(params).encode('utf-8'))
|
json.dumps(params).encode('utf-8')
|
||||||
|
)
|
||||||
info = self._download_json(req, video_id, 'Downloading video info json')
|
info = self._download_json(req, video_id, 'Downloading video info json')
|
||||||
|
|
||||||
title = info['MediaName']
|
title = info['MediaName']
|
||||||
@ -199,6 +218,8 @@ class ToggleIE(InfoExtractor):
|
|||||||
})
|
})
|
||||||
thumbnails.append(thumbnail)
|
thumbnails.append(thumbnail)
|
||||||
|
|
||||||
|
subtitles = self._get_subtitles(video_id)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
@ -210,4 +231,14 @@ class ToggleIE(InfoExtractor):
|
|||||||
'like_count': like_count,
|
'like_count': like_count,
|
||||||
'thumbnails': thumbnails,
|
'thumbnails': thumbnails,
|
||||||
'formats': formats,
|
'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'
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user