[Fujitv] Extract metadata and support premium (#2505)

Authored by: YuenSzeHong
This commit is contained in:
YuenSzeHong 2022-01-28 20:58:03 +08:00 committed by GitHub
parent e26f9cc1e5
commit c4da5ff971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,48 +1,52 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from ..utils import HEADRequest
from .common import InfoExtractor from .common import InfoExtractor
class FujiTVFODPlus7IE(InfoExtractor): class FujiTVFODPlus7IE(InfoExtractor):
_VALID_URL = r'https?://fod\.fujitv\.co\.jp/title/[0-9a-z]{4}/(?P<id>[0-9a-z]+)' _VALID_URL = r'https?://fod\.fujitv\.co\.jp/title/(?P<sid>[0-9a-z]{4})/(?P<id>[0-9a-z]+)'
_BASE_URL = 'http://i.fod.fujitv.co.jp/' _BASE_URL = 'https://i.fod.fujitv.co.jp/'
_BITRATE_MAP = {
300: (320, 180),
800: (640, 360),
1200: (1280, 720),
2000: (1280, 720),
4000: (1920, 1080),
}
_TESTS = [{ _TESTS = [{
'url': 'https://fod.fujitv.co.jp/title/5d40/5d40810075', 'url': 'https://fod.fujitv.co.jp/title/5d40/5d40110076',
'info_dict': { 'info_dict': {
'id': '5d40810075', 'id': '5d40110076',
'title': '5d40810075',
'ext': 'mp4', 'ext': 'mp4',
'format_id': '4000', 'title': '#1318 『まる子、まぼろしの洋館を見る』の巻',
'thumbnail': 'http://i.fod.fujitv.co.jp/pc/image/wbtn/wbtn_5d40810075.jpg' 'series': 'ちびまる子ちゃん',
'series_id': '5d40',
'description': 'md5:b3f51dbfdda162ac4f789e0ff4d65750',
'thumbnail': 'https://i.fod.fujitv.co.jp/img/program/5d40/episode/5d40110076_a.jpg',
}, },
'skip': 'Expires after a week'
}] }]
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) series_id, video_id = self._match_valid_url(url).groups()
formats = self._extract_m3u8_formats( self._request_webpage(HEADRequest(url), video_id)
self._BASE_URL + 'abr/tv_android/%s.m3u8' % video_id, video_id, 'mp4') json_info = {}
for f in formats: token = self._get_cookies(url).get('CT')
wh = self._BITRATE_MAP.get(f.get('tbr')) if token:
if wh: json_info = self._download_json('https://fod-sp.fujitv.co.jp/apps/api/episode/detail/?ep_id=%s&is_premium=false' % video_id, video_id, headers={'x-authorization': f'Bearer {token.value}'}, fatal=False)
f.update({ else:
'width': wh[0], self.report_warning(f'The token cookie is needed to extract video metadata. {self._LOGIN_HINTS["cookies"]}')
'height': wh[1], formats, subtitles = [], {}
}) src_json = self._download_json(f'{self._BASE_URL}abrjson_v2/tv_android/{video_id}', video_id)
self._sort_formats(formats) for src in src_json['video_selector']:
if not src.get('url'):
continue
fmt, subs = self._extract_m3u8_formats_and_subtitles(src['url'], video_id, 'mp4')
formats.extend(fmt)
subtitles = self._merge_subtitles(subtitles, subs)
self._sort_formats(formats, ['tbr'])
return { return {
'id': video_id, 'id': video_id,
'title': video_id, 'title': json_info.get('ep_title'),
'series': json_info.get('lu_title'),
'series_id': series_id,
'description': json_info.get('ep_description'),
'formats': formats, 'formats': formats,
'thumbnail': self._BASE_URL + 'pc/image/wbtn/wbtn_%s.jpg' % video_id, 'subtitles': subtitles,
'thumbnail': f'{self._BASE_URL}img/program/{series_id}/episode/{video_id}_a.jpg',
} }