Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Download twitch emotes from channel
import os
from requests import Session
from bs4 import BeautifulSoup
requests = Session()
class EmoteNotFoundError(RuntimeError):
def get_emote(emote_page, size="3.0"): # valid sizes are 1.0 2.0 and 3.0
soup = BeautifulSoup(requests.get(emote_page).text, 'html.parser')
big_img = soup.find(lambda tag: == 'img' and tag.get('src', '').endswith(f'/{size}'))
if not big_img:
raise EmoteNotFoundError(f'Emote image not found on page {emote_page}')
name = soup.find('h2').text
return name, big_img.get('src')
def download_file(link, dest_fp):
data = requests.get(link).content
with open(dest_fp, 'wb') as f:
def overwrite_yesnoall(filepath):
prompt = f'{filepath} already exists. Do you want to overwrite this file? ([Y]es/[N]o/[A]ll): '
while True:
response = input(prompt)
if response.lower() in ('y', 'yes'):
return 'y'
if response.lower() in ('n', 'no'):
return 'n'
if response.lower() in ('a', 'all'):
return 'a'
def emote_links_from_channel_link(channel_link):
resp = requests.get(channel_link)
soup = BeautifulSoup(resp.text, 'html.parser')
emote_pages = []
for tag in soup.find_all(lambda tag: == 'a' and 'emote' in tag.get('href', '')):
link = ''+tag.get('href')
return emote_pages
def download_channel(channel_link, dest=None):
print('Never use emotes without creator permission!')
overwrite_all = False
if dest is None:
dest = os.getcwd()
emote_pages = emote_links_from_channel_link(channel_link)
for page in emote_pages:
name, image_link = get_emote(page)
except EmoteNotFoundError as e:
print(str(e), 'Skipping')
if 'animated' in image_link:
extension = '.gif'
extension = '.png'
fp = os.path.join(dest, name + extension)
if not overwrite_all and os.path.exists(fp):
user_response = overwrite_yesnoall(fp)
if user_response == 'n':
if user_response == 'a':
overwrite_all = True
print(f'Downloading {name} to {fp}')
download_file(image_link, fp)
Copy link

DaveidWeba commented Feb 28, 2021

Hello, may I ask how to use this code you've written? I am trying to archive a list of twitch channels and the only thing I don't have right now are their emotes. I haven't figured out how to run this successfully, can you provide me more context please? I would greatly appreciate it! I have the channel names in a txt file currently separate by a new line and I can fetch the channel IDs using Twitch's API if needed. Thank you!

Copy link

spyoungtech commented Feb 28, 2021

You need to go to and find the URL for their channel and pass that to the download_channel function


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment