Add get_channel_id

This commit is contained in:
tcely 2025-01-22 20:07:59 -05:00 committed by GitHub
parent ba321945b6
commit e5b4e9dbc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,31 @@ def get_yt_opts():
opts.update({'cookiefile': cookie_file_path})
return opts
def get_channel_id(url):
# yt-dlp --simulate --no-check-formats --playlist-items 1
# --print 'pre_process:%(playlist_channel_id,playlist_id,channel_id)s'
opts = get_yt_opts()
opts.update({
'skip_download': True,
'simulate': True,
'logger': log,
'extract_flat': True, # Change to False to get detailed info
'check_formats': False,
'playlist_items': '1',
})
with yt_dlp.YoutubeDL(opts) as y:
try:
response = y.extract_info(url, download=False)
channel_id = response['channel_id']
playlist_id = response['playlist_id']
playlist_channel_id = response['playlist_channel_id']
except yt_dlp.utils.DownloadError as e:
raise YouTubeError(f'Failed to extract channel ID for "{url}": {e}') from e
else:
return playlist_channel_id or playlist_id or channel_id
def get_channel_image_info(url):
opts = get_yt_opts()
opts.update({