mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-22 02:01:50 +00:00
[extractor/common] Extract interaction statistic
This commit is contained in:
parent
6cc622327f
commit
e7e4a6e0f9
1 changed files with 35 additions and 0 deletions
|
@ -1020,6 +1020,40 @@ class InfoExtractor(object):
|
||||||
if isinstance(json_ld, dict):
|
if isinstance(json_ld, dict):
|
||||||
json_ld = [json_ld]
|
json_ld = [json_ld]
|
||||||
|
|
||||||
|
INTERACTION_TYPE_MAP = {
|
||||||
|
'CommentAction': 'comment',
|
||||||
|
'AgreeAction': 'like',
|
||||||
|
'DisagreeAction': 'dislike',
|
||||||
|
'LikeAction': 'like',
|
||||||
|
'DislikeAction': 'dislike',
|
||||||
|
'ListenAction': 'view',
|
||||||
|
'WatchAction': 'view',
|
||||||
|
'ViewAction': 'view',
|
||||||
|
}
|
||||||
|
|
||||||
|
def extract_interaction_statistic(e):
|
||||||
|
interaction_statistic = e.get('interactionStatistic')
|
||||||
|
if not isinstance(interaction_statistic, list):
|
||||||
|
return
|
||||||
|
for is_e in interaction_statistic:
|
||||||
|
if not isinstance(is_e, dict):
|
||||||
|
continue
|
||||||
|
if is_e.get('@type') != 'InteractionCounter':
|
||||||
|
continue
|
||||||
|
interaction_type = is_e.get('interactionType')
|
||||||
|
if not isinstance(interaction_type, compat_str):
|
||||||
|
continue
|
||||||
|
interaction_count = int_or_none(is_e.get('userInteractionCount'))
|
||||||
|
if interaction_count is None:
|
||||||
|
continue
|
||||||
|
count_kind = INTERACTION_TYPE_MAP.get(interaction_type.split('/')[-1])
|
||||||
|
if not count_kind:
|
||||||
|
continue
|
||||||
|
count_key = '%s_count' % count_kind
|
||||||
|
if info.get(count_key) is not None:
|
||||||
|
continue
|
||||||
|
info[count_key] = interaction_count
|
||||||
|
|
||||||
def extract_video_object(e):
|
def extract_video_object(e):
|
||||||
assert e['@type'] == 'VideoObject'
|
assert e['@type'] == 'VideoObject'
|
||||||
info.update({
|
info.update({
|
||||||
|
@ -1035,6 +1069,7 @@ class InfoExtractor(object):
|
||||||
'height': int_or_none(e.get('height')),
|
'height': int_or_none(e.get('height')),
|
||||||
'view_count': int_or_none(e.get('interactionCount')),
|
'view_count': int_or_none(e.get('interactionCount')),
|
||||||
})
|
})
|
||||||
|
extract_interaction_statistic(e)
|
||||||
|
|
||||||
for e in json_ld:
|
for e in json_ld:
|
||||||
if isinstance(e.get('@context'), compat_str) and re.match(r'^https?://schema.org/?$', e.get('@context')):
|
if isinstance(e.get('@context'), compat_str) and re.match(r'^https?://schema.org/?$', e.get('@context')):
|
||||||
|
|
Loading…
Reference in a new issue