- # Start extracting information
- title = (
- get_video_info_xml('title') # prefer to get the untranslated original title
- or get_video_info_web(['originalTitle', 'title'])
- or self._og_search_title(webpage, default=None)
- or self._html_search_regex(
- r'<span[^>]+class="videoHeaderTitle"[^>]*>([^<]+)</span>',
- webpage, 'video title'))
-
- watch_api_data_string = self._html_search_regex(
- r'<div[^>]+id="watchAPIDataContainer"[^>]+>([^<]+)</div>',
- webpage, 'watch api data', default=None)
- watch_api_data = self._parse_json(watch_api_data_string, video_id) if watch_api_data_string else {}
- video_detail = watch_api_data.get('videoDetail', {})
-
- thumbnail = (
- self._html_search_regex(r'<meta property="og:image" content="([^"]+)">', webpage, 'thumbnail data', default=None)
- or dict_get( # choose highest from 720p to 240p
- get_video_info_web('thumbnail'),
- ['ogp', 'player', 'largeUrl', 'middleUrl', 'url'])
- or self._html_search_meta('image', webpage, 'thumbnail', default=None)
- or video_detail.get('thumbnail'))
-
- description = get_video_info_web('description')
-
- if not timestamp:
- match = self._html_search_meta('datePublished', webpage, 'date published', default=None)
- if match:
- timestamp = parse_iso8601(match.replace('+', ':00+'))
- if not timestamp and video_detail.get('postedAt'):
- timestamp = parse_iso8601(
- video_detail['postedAt'].replace('/', '-'),
- delimiter=' ', timezone=datetime.timedelta(hours=9))
- timestamp = timestamp or try_get(api_data, lambda x: parse_iso8601(x['video']['registeredAt']))
-
- view_count = int_or_none(get_video_info_web(['view_counter', 'viewCount']))
- if not view_count:
- match = self._html_search_regex(
- r'>Views: <strong[^>]*>([^<]+)</strong>',
- webpage, 'view count', default=None)
- if match:
- view_count = int_or_none(match.replace(',', ''))
- view_count = (
- view_count
- or video_detail.get('viewCount')
- or try_get(api_data, lambda x: x['video']['count']['view']))
-
- comment_count = (
- int_or_none(get_video_info_web('comment_num'))
- or video_detail.get('commentCount')
- or try_get(api_data, lambda x: x['video']['count']['comment']))
-
- if not comment_count:
- match = self._html_search_regex(
- r'>Comments: <strong[^>]*>([^<]+)</strong>',
- webpage, 'comment count', default=None)
- if match:
- comment_count = int_or_none(match.replace(',', ''))
-
- duration = (parse_duration(
- get_video_info_web('length')
- or self._html_search_meta(
- 'video:duration', webpage, 'video duration', default=None))
- or video_detail.get('length')
- or get_video_info_web('duration'))
-
- webpage_url = get_video_info_web('watch_url') or url
-
- # for channel movie and community movie
- channel_id = try_get(
- api_data,
- (lambda x: x['channel']['globalId'],
- lambda x: x['community']['globalId']))
- channel = try_get(
- api_data,
- (lambda x: x['channel']['name'],
- lambda x: x['community']['name']))
-
- # Note: cannot use api_data.get('owner', {}) because owner may be set to "null"
- # in the JSON, which will cause None to be returned instead of {}.
- owner = try_get(api_data, lambda x: x.get('owner'), dict) or {}
- uploader_id = str_or_none(
- get_video_info_web(['ch_id', 'user_id'])
- or owner.get('id')
- or channel_id
- )
- uploader = (
- get_video_info_web(['ch_name', 'user_nickname'])
- or owner.get('nickname')
- or channel
- )