diff options
author | Matthew <colethedj@protonmail.com> | 2021-03-21 21:23:34 +0000 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-03-22 02:58:41 +0530 |
commit | c224251aad3d30a2283b459fcb46ff52344d11a8 (patch) | |
tree | 43e65c16bce1a4279d4773b6440f102b9276e25a /yt_dlp/extractor/youtube.py | |
parent | 037cc66ec8c7cb0dfe9f333a0079201868e44e1b (diff) | |
download | hypervideo-pre-c224251aad3d30a2283b459fcb46ff52344d11a8.tar.lz hypervideo-pre-c224251aad3d30a2283b459fcb46ff52344d11a8.tar.xz hypervideo-pre-c224251aad3d30a2283b459fcb46ff52344d11a8.zip |
[youtube] Show if video is `private`, `unlisted` etc in new field `availability` (#188)
Closes: #185, https://github.com/ytdl-org/youtube-dl/issues/25631
Authored by: colethedj, pukkandan
Diffstat (limited to 'yt_dlp/extractor/youtube.py')
-rw-r--r-- | yt_dlp/extractor/youtube.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index b0f52ff96..6c93517d4 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -25,6 +25,7 @@ from ..compat import ( ) from ..jsinterp import JSInterpreter from ..utils import ( + bool_or_none, clean_html, dict_get, ExtractorError, @@ -2066,7 +2067,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): 'tags': keywords, 'is_live': is_live, 'playable_in_embed': playability_status.get('playableInEmbed'), - 'was_live': video_details.get('isLiveContent') + 'was_live': video_details.get('isLiveContent'), } pctr = try_get( @@ -2283,6 +2284,30 @@ class YoutubeIE(YoutubeBaseInfoExtractor): if v: info[d_k] = v + is_private = bool_or_none(video_details.get('isPrivate')) + is_unlisted = bool_or_none(microformat.get('isUnlisted')) + is_membersonly = None + if initial_data and is_private is not None: + is_membersonly = False + contents = try_get(initial_data, lambda x: x['contents']['twoColumnWatchNextResults']['results']['results']['contents'], list) + for content in contents or []: + badges = try_get(content, lambda x: x['videoPrimaryInfoRenderer']['badges'], list) + for badge in badges or []: + label = try_get(badge, lambda x: x['metadataBadgeRenderer']['label']) or '' + if label.lower() == 'members only': + is_membersonly = True + break + if is_membersonly: + break + + # TODO: Add this for playlists + info['availability'] = self._availability( + is_private=is_private, + needs_premium=False, # Youtube no longer have premium-only videos? + needs_subscription=is_membersonly, + needs_auth=info['age_limit'] >= 18, + is_unlisted=None if is_private is None else is_unlisted) + # get xsrf for annotations or comments get_annotations = self._downloader.params.get('writeannotations', False) get_comments = self._downloader.params.get('getcomments', False) |