·8 min read
Using the banner.yt API with Python
Download YouTube banners and fetch channel data with Python using requests, httpx, or urllib. Includes saving to disk and batch download examples.
APIPythonTutorialDeveloper
Using the banner.yt API with Python
The API is plain HTTP so Python's standard library urllib works fine. The examples below use requests since most people have it installed.
Install requests
pip install requests
Download a banner and save to disk
import requests
channel_id = 'UCX6OQ3DkcsbYNE6H8uQQuVA'
url = f'https://banner.yt/api/banner/{channel_id}'
res = requests.get(url)
res.raise_for_status()
with open('mrbeast-banner.webp', 'wb') as f:
f.write(res.content)
print('Saved banner.webp')
Download in a specific format and size
params = {
'format': 'jpeg',
'type': 'mobile',
'quality': '90',
}
res = requests.get(f'https://banner.yt/api/banner/{channel_id}', params=params)
with open('banner-mobile.jpg', 'wb') as f:
f.write(res.content)
Get channel data as JSON
res = requests.get(f'https://banner.yt/api/channel/{channel_id}')
channel = res.json()
print(channel['title'])
print(channel['subscriberCount'])
print(channel['bannerUrl'])
Search for channels
res = requests.get('https://banner.yt/api/search', params={'q': 'Linus Tech Tips'})
results = res.json()['results']
for ch in results:
print(ch['channelId'], ch['title'])
Bulk download with rate limit handling
import time
import requests
channel_ids = [
'UCX6OQ3DkcsbYNE6H8uQQuVA', # MrBeast
'UC-lHJZR3Gqxm24_Vd_AJ5Yw', # PewDiePie
'UCq-Fj5jknLsUf-MWSy4_brA', # T-Series
]
for cid in channel_ids:
res = requests.get(f'https://banner.yt/api/banner/{cid}')
if res.status_code == 200:
with open(f'{cid}.webp', 'wb') as f:
f.write(res.content)
print(f'Saved {cid}.webp')
elif res.status_code == 429:
print('Rate limited, waiting 30s...')
time.sleep(30)
time.sleep(0.5) # Be polite
Using httpx with async
import asyncio
import httpx
async def fetch_banner(client, channel_id):
res = await client.get(f'https://banner.yt/api/banner/{channel_id}')
return channel_id, res.content
async def main():
ids = ['UCX6OQ3DkcsbYNE6H8uQQuVA', 'UC-lHJZR3Gqxm24_Vd_AJ5Yw']
async with httpx.AsyncClient() as client:
tasks = [fetch_banner(client, cid) for cid in ids]
results = await asyncio.gather(*tasks)
for cid, data in results:
with open(f'{cid}.webp', 'wb') as f:
f.write(data)
asyncio.run(main())