mirror of https://github.com/yt-dlp/yt-dlp.git
[tvbanywherena] Use API
This commit is contained in:
parent
25776dd0d7
commit
b04c017886
|
@ -6,13 +6,21 @@ from ..utils import (
|
||||||
get_elements_by_class,
|
get_elements_by_class,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
traverse_obj,
|
|
||||||
urljoin,
|
urljoin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_program_url(lang, pid):
|
||||||
|
if lang == 'english':
|
||||||
|
return f'https://api.tvbaw.com/EN/getProgramByPid?value={pid}'
|
||||||
|
if lang == 'viet':
|
||||||
|
return f'https://api.tvbaw.com/VN/getProgramByPid?value={pid}'
|
||||||
|
|
||||||
|
return f'https://api.tvbaw.com/getProgramByPid?value={pid}'
|
||||||
|
|
||||||
|
|
||||||
class TvbAnywhereNaIE(InfoExtractor):
|
class TvbAnywhereNaIE(InfoExtractor):
|
||||||
_VALID_URL = r'https://(?:www\.)?tvbanywherena\.com/(?P<lang>[^/]+)/videos/[^/]+/(?P<id>\d+)'
|
_VALID_URL = r'https://(?:www\.)?tvbanywherena\.com/(?P<lang>cantonese|english|viet)/videos/[^/]+/(?P<id>\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.tvbanywherena.com/cantonese/videos/437-SuperTrioShow/6007674088001',
|
'url': 'https://www.tvbanywherena.com/cantonese/videos/437-SuperTrioShow/6007674088001',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
|
@ -59,8 +67,9 @@ class TvbAnywhereNaIE(InfoExtractor):
|
||||||
brightcove = self.BRIGHTCOVE_URL_TEMPLATE % (
|
brightcove = self.BRIGHTCOVE_URL_TEMPLATE % (
|
||||||
attrs.get('data-account'), attrs.get('data-player'), attrs.get('data-video-id'))
|
attrs.get('data-account'), attrs.get('data-player'), attrs.get('data-video-id'))
|
||||||
|
|
||||||
metainfo = self._search_json(r'<script[^>]+type="application/ld\+json"[^>]*>', webpage, 'info', content_id)
|
pid = self._search_regex(r'\'pid\':\s*\'(\d+)\'', webpage, 'pid')
|
||||||
seriesname = metainfo.get('alternateName' if lang == 'cantonese' else 'name')
|
program = self._download_json(_get_program_url(lang, pid), content_id)
|
||||||
|
seriesname = program.get('title' if lang == 'cantonese' else 'subtitle')
|
||||||
episodeinfo = get_element_html_by_id(content_id, webpage)
|
episodeinfo = get_element_html_by_id(content_id, webpage)
|
||||||
episodename = get_element_by_class('episodeName', episodeinfo)
|
episodename = get_element_by_class('episodeName', episodeinfo)
|
||||||
|
|
||||||
|
@ -75,18 +84,18 @@ class TvbAnywhereNaIE(InfoExtractor):
|
||||||
'title': f'{seriesname} {episodename}',
|
'title': f'{seriesname} {episodename}',
|
||||||
'description': get_element_by_class(episodeinfo, 'episodeDescription'),
|
'description': get_element_by_class(episodeinfo, 'episodeDescription'),
|
||||||
'series': seriesname,
|
'series': seriesname,
|
||||||
'genres': metainfo.get('genre', []),
|
'genres': program.get('genres', []),
|
||||||
'cast': traverse_obj(metainfo, ('actor', ..., 'name')),
|
'cast': program.get('char', []),
|
||||||
'release_year': int_or_none(metainfo.get('datePublished')),
|
'release_year': int_or_none(program.get('year')),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TvbAnywhereNaSeriesIE(InfoExtractor):
|
class TvbAnywhereNaSeriesIE(InfoExtractor):
|
||||||
_VALID_URL = r'https://(?:www\.)?tvbanywherena\.com/(?P<lang>[^/]+)/series/(?P<id>[^/]+)'
|
_VALID_URL = r'https://(?:www\.)?tvbanywherena\.com/(?P<lang>cantonese|english|viet)/series/(?P<id>\d+)-'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://tvbanywherena.com/cantonese/series/2594-ForensicHeroesV',
|
'url': 'https://tvbanywherena.com/cantonese/series/2594-ForensicHeroesV',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '2594-ForensicHeroesV',
|
'id': '2594',
|
||||||
'title': '法證先鋒V',
|
'title': '法證先鋒V',
|
||||||
'description': 'md5:ada77595c0b4bfe9fbc859087fc659b6',
|
'description': 'md5:ada77595c0b4bfe9fbc859087fc659b6',
|
||||||
'genres': ['警匪', '動作', '劇情'],
|
'genres': ['警匪', '動作', '劇情'],
|
||||||
|
@ -98,7 +107,7 @@ class TvbAnywhereNaSeriesIE(InfoExtractor):
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.tvbanywherena.com/viet/series/1034-Ngh%E1%BB%8BchThi%C3%AAnK%E1%BB%B3%C3%81n2',
|
'url': 'https://www.tvbanywherena.com/viet/series/1034-Ngh%E1%BB%8BchThi%C3%AAnK%E1%BB%B3%C3%81n2',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1034-Ngh%E1%BB%8BchThi%C3%AAnK%E1%BB%B3%C3%81n2',
|
'id': '1034',
|
||||||
'title': 'Nghịch Thiên Kỳ Án 2',
|
'title': 'Nghịch Thiên Kỳ Án 2',
|
||||||
'description': 'md5:9cb8cc2aa86e97b040e805c3b1eff1be',
|
'description': 'md5:9cb8cc2aa86e97b040e805c3b1eff1be',
|
||||||
'genres': ['Phim Hình Sự'],
|
'genres': ['Phim Hình Sự'],
|
||||||
|
@ -112,7 +121,8 @@ class TvbAnywhereNaSeriesIE(InfoExtractor):
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
lang, content_id = self._match_valid_url(url).group('lang', 'id')
|
lang, content_id = self._match_valid_url(url).group('lang', 'id')
|
||||||
webpage = self._download_webpage(url, content_id)
|
webpage = self._download_webpage(url, content_id)
|
||||||
metainfo = self._search_json(r'<script[^>]+type="application/ld\+json"[^>]*>', webpage, 'info', content_id)
|
program = self._download_json(_get_program_url(lang, content_id), content_id)
|
||||||
|
# brightcove_playlist_id = program.get('bcov')
|
||||||
|
|
||||||
def get_entries(page_data):
|
def get_entries(page_data):
|
||||||
for episode in get_elements_by_class('item', page_data):
|
for episode in get_elements_by_class('item', page_data):
|
||||||
|
@ -121,11 +131,11 @@ class TvbAnywhereNaSeriesIE(InfoExtractor):
|
||||||
return {
|
return {
|
||||||
'_type': 'playlist',
|
'_type': 'playlist',
|
||||||
'id': content_id,
|
'id': content_id,
|
||||||
'title': metainfo.get('alternateName' if lang == 'cantonese' else 'name'),
|
'title': program.get('title' if lang == 'cantonese' else 'subtitle'),
|
||||||
'description': metainfo.get('description'),
|
'description': program.get('synopsis'),
|
||||||
'genres': metainfo.get('genre', []),
|
'genres': program.get('genres', []),
|
||||||
'cast': traverse_obj(metainfo, ('actor', ..., 'name')),
|
'cast': program.get('char', []),
|
||||||
'release_year': int_or_none(metainfo.get('datePublished')),
|
'release_year': int_or_none(program.get('year')),
|
||||||
'thumbnail': metainfo.get('image'),
|
'thumbnail': program.get('large'),
|
||||||
'entries': get_entries(webpage),
|
'entries': get_entries(webpage),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue