[youtube] Extract channel subscriber count (#2399)

Closes #2350
* Adds `channel_follower_count` field
Authored-by: coletdjnz
This commit is contained in:
coletdjnz 2022-01-21 06:04:36 +00:00 committed by GitHub
parent 593e43c030
commit 6c73052c0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 7 deletions

View file

@ -1138,6 +1138,7 @@ The available fields are:
- `uploader_id` (string): Nickname or id of the video uploader - `uploader_id` (string): Nickname or id of the video uploader
- `channel` (string): Full name of the channel the video is uploaded on - `channel` (string): Full name of the channel the video is uploaded on
- `channel_id` (string): Id of the channel - `channel_id` (string): Id of the channel
- `channel_follower_count` (numeric): Number of followers of the channel
- `location` (string): Physical location where the video was filmed - `location` (string): Physical location where the video was filmed
- `duration` (numeric): Length of the video in seconds - `duration` (numeric): Length of the video in seconds
- `duration_string` (string): Length of the video (HH:mm:ss) - `duration_string` (string): Length of the video (HH:mm:ss)

View file

@ -261,6 +261,7 @@ class InfoExtractor(object):
fields. This depends on a particular extractor. fields. This depends on a particular extractor.
channel_id: Id of the channel. channel_id: Id of the channel.
channel_url: Full URL to a channel webpage. channel_url: Full URL to a channel webpage.
channel_follower_count: Number of followers of the channel.
location: Physical location where the video was filmed. location: Physical location where the video was filmed.
subtitles: The available subtitles as a dictionary in the format subtitles: The available subtitles as a dictionary in the format
{tag: subformats}. "tag" is usually a language code, and {tag: subformats}. "tag" is usually a language code, and

View file

@ -515,7 +515,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
Appears to be used to track session state Appears to be used to track session state
""" """
return get_first( return get_first(
args, (('VISITOR_DATA', ('INNERTUBE_CONTEXT', 'client', 'visitorData'), ('responseContext', 'visitorData'))), args, [('VISITOR_DATA', ('INNERTUBE_CONTEXT', 'client', 'visitorData'), ('responseContext', 'visitorData'))],
expected_type=str) expected_type=str)
@property @property
@ -1034,6 +1034,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'age_limit': 0, 'age_limit': 0,
'start_time': 1, 'start_time': 1,
'end_time': 9, 'end_time': 9,
'channel_follower_count': int
} }
}, },
{ {
@ -1077,6 +1078,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg', 'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg',
'live_status': 'not_live', 'live_status': 'not_live',
'age_limit': 0, 'age_limit': 0,
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1129,6 +1131,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'categories': ['Music'], 'categories': ['Music'],
'age_limit': 0, 'age_limit': 0,
'alt_title': 'The Spark', 'alt_title': 'The Spark',
'channel_follower_count': int
}, },
'params': { 'params': {
'youtube_include_dash_manifest': True, 'youtube_include_dash_manifest': True,
@ -1161,6 +1164,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'channel_id': 'UCzybXLxv08IApdjdN0mJhEg', 'channel_id': 'UCzybXLxv08IApdjdN0mJhEg',
'playable_in_embed': True, 'playable_in_embed': True,
'view_count': int, 'view_count': int,
'channel_follower_count': int
}, },
}, },
{ {
@ -1188,6 +1192,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'like_count': int, 'like_count': int,
'duration': 177, 'duration': 177,
'playable_in_embed': True, 'playable_in_embed': True,
'channel_follower_count': int
}, },
}, },
{ {
@ -1215,6 +1220,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'categories': ['Entertainment'], 'categories': ['Entertainment'],
'duration': 106, 'duration': 106,
'channel_url': 'https://www.youtube.com/channel/UC1yoRdFoFJaCY-AGfD9W0wQ', 'channel_url': 'https://www.youtube.com/channel/UC1yoRdFoFJaCY-AGfD9W0wQ',
'channel_follower_count': int
}, },
}, },
{ {
@ -1246,6 +1252,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'channel_url': 'https://www.youtube.com/channel/UCdR3RSDPqub28LjZx0v9-aA', 'channel_url': 'https://www.youtube.com/channel/UCdR3RSDPqub28LjZx0v9-aA',
'live_status': 'not_live', 'live_status': 'not_live',
'artist': 'OOMPH!', 'artist': 'OOMPH!',
'channel_follower_count': int
}, },
}, },
{ {
@ -1284,6 +1291,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'channel_url': 'https://www.youtube.com/channel/UCYEK6xds6eo-3tr4xRdflmQ', 'channel_url': 'https://www.youtube.com/channel/UCYEK6xds6eo-3tr4xRdflmQ',
'categories': ['Music'], 'categories': ['Music'],
'album': 'Some Chords', 'album': 'Some Chords',
'channel_follower_count': int
}, },
'expected_warnings': [ 'expected_warnings': [
'DASH manifest missing', 'DASH manifest missing',
@ -1316,6 +1324,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'live_status': 'was_live', 'live_status': 'was_live',
'view_count': int, 'view_count': int,
'channel_url': 'https://www.youtube.com/channel/UCTl3QQTvqHFjurroKxexy2Q', 'channel_url': 'https://www.youtube.com/channel/UCTl3QQTvqHFjurroKxexy2Q',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': 'requires avconv', 'skip_download': 'requires avconv',
@ -1347,6 +1356,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'like_count': int, 'like_count': int,
'live_status': 'not_live', 'live_status': 'not_live',
'availability': 'unlisted', 'availability': 'unlisted',
'channel_follower_count': int
}, },
}, },
# url_encoded_fmt_stream_map is empty string # url_encoded_fmt_stream_map is empty string
@ -1515,6 +1525,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'playable_in_embed': True, 'playable_in_embed': True,
'like_count': int, 'like_count': int,
'age_limit': 0, 'age_limit': 0,
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1573,6 +1584,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'thumbnail': 'https://i.ytimg.com/vi_webp/M4gD1WSo5mA/maxresdefault.webp', 'thumbnail': 'https://i.ytimg.com/vi_webp/M4gD1WSo5mA/maxresdefault.webp',
'live_status': 'not_live', 'live_status': 'not_live',
'playable_in_embed': True, 'playable_in_embed': True,
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1604,6 +1616,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'view_count': int, 'view_count': int,
'live_status': 'not_live', 'live_status': 'not_live',
'channel_url': 'https://www.youtube.com/channel/UCH1dpzjCEiGAt8CXkryhkZg', 'channel_url': 'https://www.youtube.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1667,6 +1680,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'like_count': int, 'like_count': int,
'playable_in_embed': True, 'playable_in_embed': True,
'live_status': 'not_live', 'live_status': 'not_live',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1776,6 +1790,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'channel_id': 'UC-pWHpBjdGG69N9mM2auIAA', 'channel_id': 'UC-pWHpBjdGG69N9mM2auIAA',
'tags': 'count:11', 'tags': 'count:11',
'live_status': 'not_live', 'live_status': 'not_live',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1831,6 +1846,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'playable_in_embed': True, 'playable_in_embed': True,
'live_status': 'not_live', 'live_status': 'not_live',
'channel': 'ElevageOrVert', 'channel': 'ElevageOrVert',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1864,6 +1880,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'view_count': int, 'view_count': int,
'duration': 522, 'duration': 522,
'channel': 'kudvenkat', 'channel': 'kudvenkat',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1908,6 +1925,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'thumbnail': 'https://i.ytimg.com/vi/OtqTfy26tG0/maxresdefault.jpg', 'thumbnail': 'https://i.ytimg.com/vi/OtqTfy26tG0/maxresdefault.jpg',
'categories': ['Music'], 'categories': ['Music'],
'playable_in_embed': True, 'playable_in_embed': True,
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -1943,6 +1961,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'like_count': int, 'like_count': int,
'live_status': 'not_live', 'live_status': 'not_live',
'playable_in_embed': True, 'playable_in_embed': True,
'channel_follower_count': int
} }
}, },
{ {
@ -1969,6 +1988,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'channel_url': 'https://www.youtube.com/channel/UC3o_t8PzBmXf5S9b7GLx1Mw', 'channel_url': 'https://www.youtube.com/channel/UC3o_t8PzBmXf5S9b7GLx1Mw',
'live_status': 'not_live', 'live_status': 'not_live',
'playable_in_embed': True, 'playable_in_embed': True,
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -2010,6 +2030,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'like_count': int, 'like_count': int,
'live_status': 'not_live', 'live_status': 'not_live',
'playable_in_embed': True, 'playable_in_embed': True,
'channel_follower_count': int
}, },
'params': { 'params': {
'format': '17', # 3gp format available on android 'format': '17', # 3gp format available on android
@ -2053,6 +2074,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'duration': 248, 'duration': 248,
'categories': ['Education'], 'categories': ['Education'],
'age_limit': 0, 'age_limit': 0,
'channel_follower_count': int
}, 'params': {'format': 'mhtml', 'skip_download': True} }, 'params': {'format': 'mhtml', 'skip_download': True}
} }
] ]
@ -3489,7 +3511,11 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
}) })
vsir = content.get('videoSecondaryInfoRenderer') vsir = content.get('videoSecondaryInfoRenderer')
if vsir: if vsir:
info['channel'] = self._get_text(vsir, ('owner', 'videoOwnerRenderer', 'title')) vor = traverse_obj(vsir, ('owner', 'videoOwnerRenderer'))
info.update({
'channel': self._get_text(vor, 'title'),
'channel_follower_count': self._get_count(vor, 'subscriberCountText')})
rows = try_get( rows = try_get(
vsir, vsir,
lambda x: x['metadataRowContainer']['metadataRowContainerRenderer']['rows'], lambda x: x['metadataRowContainer']['metadataRowContainerRenderer']['rows'],
@ -3969,7 +3995,8 @@ class YoutubeTabBaseInfoExtractor(YoutubeBaseInfoExtractor):
'view_count': self._get_count(playlist_stats, 1), 'view_count': self._get_count(playlist_stats, 1),
'availability': self._extract_availability(data), 'availability': self._extract_availability(data),
'modified_date': strftime_or_none(last_updated_unix, '%Y%m%d'), 'modified_date': strftime_or_none(last_updated_unix, '%Y%m%d'),
'playlist_count': self._get_count(playlist_stats, 0) 'playlist_count': self._get_count(playlist_stats, 0),
'channel_follower_count': self._get_count(data, ('header', ..., 'subscriberCountText')),
} }
if not channel_id: if not channel_id:
metadata.update(self._extract_uploader(data)) metadata.update(self._extract_uploader(data))
@ -4265,6 +4292,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'tags': ['"критическое', 'мышление"', '"наука', 'просто"', 'математика', '"анализ', 'данных"'], 'tags': ['"критическое', 'мышление"', '"наука', 'просто"', 'математика', '"анализ', 'данных"'],
'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg', 'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
'uploader_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg', 'uploader_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
'channel_follower_count': int
}, },
}, { }, {
'note': 'playlists, multipage, different order', 'note': 'playlists, multipage, different order',
@ -4281,6 +4309,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel_id': 'UCqj7Cz7revf5maW9g5pgNcg', 'channel_id': 'UCqj7Cz7revf5maW9g5pgNcg',
'channel': 'Igor Kleiner', 'channel': 'Igor Kleiner',
'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg', 'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
'channel_follower_count': int
}, },
}, { }, {
'note': 'playlists, series', 'note': 'playlists, series',
@ -4297,6 +4326,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel': '3Blue1Brown', 'channel': '3Blue1Brown',
'channel_id': 'UCYO_jab_esuFRV4b17AJtAw', 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
'tags': ['Mathematics'], 'tags': ['Mathematics'],
'channel_follower_count': int
}, },
}, { }, {
'note': 'playlists, singlepage', 'note': 'playlists, singlepage',
@ -4313,6 +4343,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel_id': 'UCAEtajcuhQ6an9WEzY9LEMQ', 'channel_id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
'tags': 'count:13', 'tags': 'count:13',
'channel': 'ThirstForScience', 'channel': 'ThirstForScience',
'channel_follower_count': int
} }
}, { }, {
'url': 'https://www.youtube.com/c/ChristophLaimer/playlists', 'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
@ -4366,6 +4397,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_follower_count': int
}, },
'playlist_mincount': 2, 'playlist_mincount': 2,
}, { }, {
@ -4382,6 +4414,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel': 'lex will', 'channel': 'lex will',
'channel_follower_count': int
}, },
'playlist_mincount': 975, 'playlist_mincount': 975,
}, { }, {
@ -4398,6 +4431,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel': 'lex will', 'channel': 'lex will',
'tags': ['bible', 'history', 'prophesy'], 'tags': ['bible', 'history', 'prophesy'],
'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_follower_count': int
}, },
'playlist_mincount': 199, 'playlist_mincount': 199,
}, { }, {
@ -4414,6 +4448,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
'tags': ['bible', 'history', 'prophesy'], 'tags': ['bible', 'history', 'prophesy'],
'channel_follower_count': int
}, },
'playlist_mincount': 17, 'playlist_mincount': 17,
}, { }, {
@ -4430,6 +4465,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
'tags': ['bible', 'history', 'prophesy'], 'tags': ['bible', 'history', 'prophesy'],
'channel_follower_count': int
}, },
'playlist_mincount': 18, 'playlist_mincount': 18,
}, { }, {
@ -4446,6 +4482,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w', 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
'tags': ['bible', 'history', 'prophesy'], 'tags': ['bible', 'history', 'prophesy'],
'channel_follower_count': int
}, },
'playlist_mincount': 12, 'playlist_mincount': 12,
}, { }, {
@ -4463,6 +4500,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'tags': ['Mathematics'], 'tags': ['Mathematics'],
'channel': '3Blue1Brown', 'channel': '3Blue1Brown',
'channel_id': 'UCYO_jab_esuFRV4b17AJtAw', 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
'channel_follower_count': int
}, },
}, { }, {
'url': 'https://invidio.us/channel/UCmlqkdCBesrv2Lak1mF_MxA', 'url': 'https://invidio.us/channel/UCmlqkdCBesrv2Lak1mF_MxA',
@ -4622,7 +4660,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
}, { }, {
'url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ/live', 'url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ/live',
'info_dict': { 'info_dict': {
'id': 'zpsbVPFwsqk', # This will keep changing 'id': 'GgL890LIznQ', # This will keep changing
'ext': 'mp4', 'ext': 'mp4',
'title': str, 'title': str,
'uploader': 'Sky News', 'uploader': 'Sky News',
@ -4633,17 +4671,18 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'categories': ['News & Politics'], 'categories': ['News & Politics'],
'tags': list, 'tags': list,
'like_count': int, 'like_count': int,
'release_timestamp': 1640164857, 'release_timestamp': 1642502819,
'channel': 'Sky News', 'channel': 'Sky News',
'channel_id': 'UCoMdktPbSTixAyNGwb-UYkQ', 'channel_id': 'UCoMdktPbSTixAyNGwb-UYkQ',
'age_limit': 0, 'age_limit': 0,
'view_count': int, 'view_count': int,
'thumbnail': 'https://i.ytimg.com/vi/zpsbVPFwsqk/maxresdefault_live.jpg', 'thumbnail': 'https://i.ytimg.com/vi/GgL890LIznQ/maxresdefault_live.jpg',
'playable_in_embed': True, 'playable_in_embed': True,
'release_date': '20211222', 'release_date': '20220118',
'availability': 'public', 'availability': 'public',
'live_status': 'is_live', 'live_status': 'is_live',
'channel_url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ', 'channel_url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ',
'channel_follower_count': int
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -4825,6 +4864,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'info_dict': { 'info_dict': {
'id': 'recommended', 'id': 'recommended',
'title': 'recommended', 'title': 'recommended',
'tags': [],
}, },
'playlist_mincount': 50, 'playlist_mincount': 50,
'params': { 'params': {
@ -4845,6 +4885,7 @@ class YoutubeTabIE(YoutubeTabBaseInfoExtractor):
'tags': [], 'tags': [],
'channel_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw', 'channel_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw',
'uploader_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw', 'uploader_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw',
'channel_follower_count': int
}, },
'playlist_mincount': 650, 'playlist_mincount': 650,
'params': { 'params': {