1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2025-01-08 14:17:54 +01:00

[tver] fix the code pointed out in flake8

This commit is contained in:
tsukumijima 2020-09-22 04:17:54 +09:00
parent 9f45837753
commit e57602b380

View File

@ -1,30 +1,20 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import csv
import re import re
from .common import InfoExtractor
from .brightcove import BrightcoveNewIE from .brightcove import BrightcoveNewIE
from ..compat import (
compat_HTTPError,
)
from ..utils import (
ExtractorError,
js_to_json,
unsmuggle_url,
)
class TVerIE(BrightcoveNewIE): class TVerIE(BrightcoveNewIE):
_TESTS = [ _TESTS = [
{ {
'url': 'https://tver.jp/feature/f0057485', # 'feature' 'url': 'https://tver.jp/feature/f0057485', # 'feature'
'md5': '1c1c09662252571992dee0441028b4ec', # MD5 hash of a short video downloaded by running youtube-dl with the --test option 'md5': '1c1c09662252571992dee0441028b4ec', # MD5 hash of a short video downloaded by running youtube-dl with the --test option
'info_dict': { 'info_dict': {
'id': 'f0057485', # TVer ID 'id': 'f0057485', # TVer ID
'display_id': 'ref:hanzawa_naoki---s2----323-001', # Brightcove ID 'display_id': 'ref:hanzawa_naoki---s2----323-001', # Brightcove ID
'ext': 'mp4', 'ext': 'mp4',
'title': '半沢直樹(新シリーズ) 第1話 子会社VS銀行!飛ばされた半沢の新たな下剋上が始まる', 'title': '半沢直樹(新シリーズ) 第1話 子会社VS銀行!飛ばされた半沢の新たな下剋上が始まる',
'description': '大和田(香川照之)の不正を糾弾し、子会社へ出向を命じられた半沢直樹(堺雅人)は、東京セントラル証券営業企画部長に。ある日1500億円超の買収案件が舞い込むが…。', 'description': '大和田(香川照之)の不正を糾弾し、子会社へ出向を命じられた半沢直樹(堺雅人)は、東京セントラル証券営業企画部長に。ある日1500億円超の買収案件が舞い込むが…。',
@ -37,11 +27,11 @@ class TVerIE(BrightcoveNewIE):
'skip': 'Running from test_download.py doesn\'t seem to be able to handle encrypted HLS videos', 'skip': 'Running from test_download.py doesn\'t seem to be able to handle encrypted HLS videos',
}, },
{ {
'url': 'https://tver.jp/corner/f0056997', # 'corner' 'url': 'https://tver.jp/corner/f0056997', # 'corner'
'md5': 'aac4e681dcdb775fc44497da4f7bdd05', # MD5 hash of a short video downloaded by running youtube-dl with the --test option 'md5': 'aac4e681dcdb775fc44497da4f7bdd05', # MD5 hash of a short video downloaded by running youtube-dl with the --test option
'info_dict': { 'info_dict': {
'id': 'f0056997', # TVer ID 'id': 'f0056997', # TVer ID
'display_id': 'ref:kanokari_10', # Brightcove ID 'display_id': 'ref:kanokari_10', # Brightcove ID
'ext': 'mp4', 'ext': 'mp4',
'title': '彼女、お借りします 第10話「友達の彼女」-トモカノ-', 'title': '彼女、お借りします 第10話「友達の彼女」-トモカノ-',
'description': 'バイトの初任給を何に使おうか考える和也だったが、ふと栗林のことが脳裏をよぎる。最近栗林の様子がおかしいと、木部から話を聞いていたのだ。ボーッとしていたり、女性不信のつぶやきをしているという。和也は意を決して、栗林を呼び出すことに。翌日、栗林が和也を待っていると──「駿君、だよね?」。待ち合わせ場所にやって来たのは、千鶴だった……!', 'description': 'バイトの初任給を何に使おうか考える和也だったが、ふと栗林のことが脳裏をよぎる。最近栗林の様子がおかしいと、木部から話を聞いていたのだ。ボーッとしていたり、女性不信のつぶやきをしているという。和也は意を決して、栗林を呼び出すことに。翌日、栗林が和也を待っていると──「駿君、だよね?」。待ち合わせ場所にやって来たのは、千鶴だった……!',
@ -54,11 +44,11 @@ class TVerIE(BrightcoveNewIE):
'skip': 'Running from test_download.py doesn\'t seem to be able to handle encrypted HLS videos', 'skip': 'Running from test_download.py doesn\'t seem to be able to handle encrypted HLS videos',
}, },
{ {
'url': 'https://tver.jp/episode/76799350', # 'episode' 'url': 'https://tver.jp/episode/76799350', # 'episode'
'md5': 'ad893db02b8a3e949216c463af7ce51e', # MD5 hash of a short video downloaded by running youtube-dl with the --test option 'md5': 'ad893db02b8a3e949216c463af7ce51e', # MD5 hash of a short video downloaded by running youtube-dl with the --test option
'info_dict': { 'info_dict': {
'id': '76799350', # TVer ID 'id': '76799350', # TVer ID
'display_id': '2366_2365_4533', # Brightcove ID 'display_id': '2366_2365_4533', # Brightcove ID
'ext': 'mp4', 'ext': 'mp4',
'title': '港時間 #49 神奈川県リビエラシーボニアマリーナ 9月18日(金)放送分', 'title': '港時間 #49 神奈川県リビエラシーボニアマリーナ 9月18日(金)放送分',
'description': '【毎週金曜 よる12時15分から放送】\n\n日本のヨット文化 を育んできた三浦半島の西海岸、小網代湾にあるリビエラシーボニアマリーナ。昨年から始まったSailGPの日本チームを率いるヨット界のレジェンドに会いました。', 'description': '【毎週金曜 よる12時15分から放送】\n\n日本のヨット文化 を育んできた三浦半島の西海岸、小網代湾にあるリビエラシーボニアマリーナ。昨年から始まったSailGPの日本チームを率いるヨット界のレジェンドに会いました。',
@ -71,13 +61,13 @@ class TVerIE(BrightcoveNewIE):
'skip': 'Running from test_download.py doesn\'t seem to be able to handle encrypted HLS videos', 'skip': 'Running from test_download.py doesn\'t seem to be able to handle encrypted HLS videos',
}, },
] ]
IE_NAME = 'TVer' IE_NAME = 'TVer'
IE_DESC = 'TVer' IE_DESC = 'TVer'
_VALID_URL = r'https?://(?:www\.)?tver\.jp/(corner|episode|feature)/(?P<id>f?[0-9]+)' _VALID_URL = r'https?://(?:www\.)?tver\.jp/(corner|episode|feature)/(?P<id>f?[0-9]+)'
_GEO_COUNTRIES = ['JP'] # TVer service is limited to Japan only _GEO_COUNTRIES = ['JP'] # TVer service is limited to Japan only
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=ref:%s' BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=ref:%s'
def _real_extract(self, url): def _real_extract(self, url):
@ -90,7 +80,7 @@ class TVerIE(BrightcoveNewIE):
# extract video information # extract video information
video_info_csv = self._search_regex(r'addPlayer\((?P<video_info>.*?)\);', webpage, 'video information', flags=re.DOTALL).strip() video_info_csv = self._search_regex(r'addPlayer\((?P<video_info>.*?)\);', webpage, 'video information', flags=re.DOTALL).strip()
video_info_csv = video_info_csv.replace('\t', '').replace('\n', '').replace('\'', '') # remove \t and \n and ' video_info_csv = video_info_csv.replace('\t', '').replace('\n', '').replace('\'', '') # remove \t and \n and '
video_info = video_info_csv.split(',') video_info = video_info_csv.split(',')
# extract brightcove account id # extract brightcove account id
@ -100,7 +90,7 @@ class TVerIE(BrightcoveNewIE):
brightcove_video_id = video_info[4] brightcove_video_id = video_info[4]
# brightcove url # brightcove url
brightcove_url = self.BRIGHTCOVE_URL_TEMPLATE % (brightcove_account_id, brightcove_video_id) brightcove_url = self.BRIGHTCOVE_URL_TEMPLATE % (brightcove_account_id, brightcove_video_id)
# debug output # debug output
if self._downloader.params.get('verbose', False): if self._downloader.params.get('verbose', False):
@ -119,15 +109,22 @@ class TVerIE(BrightcoveNewIE):
# get video information # get video information
info_dict = super(TVerIE, self)._real_extract(brightcove_url) info_dict = super(TVerIE, self)._real_extract(brightcove_url)
# get video description
description = \
self._og_search_description(webpage) or \
self._html_search_meta('twitter:description', webpage) or \
self._html_search_regex(r'<div class="description">(?P<description>.*?)</div>', webpage, 'description', default=None, flags=re.DOTALL)
# undo _VALID_URL # undo _VALID_URL
self._VALID_URL = _VALID_URL self._VALID_URL = _VALID_URL
# replacement # TVer ID
info_dict['id'] = video_id # TVer ID info_dict['id'] = video_id
info_dict['display_id'] = brightcove_video_id # Brightcove ID # Brightcove ID
info_dict['thumbnail'] = info_dict['thumbnail'].replace('160x90', '1920x1080') # select large thumbnail info_dict['display_id'] = brightcove_video_id
info_dict['description'] = self._html_search_regex( # desctiption # select large thumbnail
r'<div class="description">(?P<description>.*?)</div>', info_dict['thumbnail'] = info_dict['thumbnail'].replace('160x90', '1920x1080')
webpage, 'description', flags=re.DOTALL) # desctiption
info_dict['description'] = description
return info_dict return info_dict