# Goal

Batch download our favorite youtuber's (or VTuber's) membership emoji.

# Info

KeyValue
Day created2023/7/7
Day modified2023/7/8
AuthorBenjamin Yang
LanguagePython
Used modulere , requests , tkinter , tkinter.filedialog.askdirectory
File location..\Desktop\python\download youtube's stickers\download_youtube_membership_stickers.py

# Flow chart

copy stickers' htmlrun and pasteselect the foldersuccessfailmanual downloadyoutubepython filefolder selectordownloadsuccessful?done

# Code

download_youtube_membership_stickers.py
#################### Section-1 Input and Define ####################
import re
import requests
import tkinter as tk
from tkinter.filedialog import askdirectory
stringInput = input("Input VTr stickers' sources code:\n\n")
##### Get download path
root = tk.Tk()
root.withdraw()
print("\nWarning: the directory selector is opening, please check if it had been hidden.\n")
# shows dialog box and return the path
path = askdirectory(title='Select Folder')
def download_image(url, filename):
    response = requests.get(url)
    if response.status_code == 200:
        downloadPath = path + "/" + filename
        with open(downloadPath, 'wb') as f:
            f.write(response.content)
        print(f"Downloaded {filename}")
    else:
        print(f"\tFailed to download {filename}")
##### regex for Stickers
reg1 = """alt="[\S]*\""""
reg2 = """src="[\S]*=w"""
#################### Section-2 Processing ####################
##### regex-2 Stickers
sticker_names = re.findall(reg1, stringInput)
sticker_urls = re.findall(reg2, stringInput)
name_and_url = {} #for download
for name, url in zip(sticker_names, sticker_urls):
    name = name.strip("alt=\"").rstrip("\"")
    url = url.strip("src=\"").rstrip("=w")
    name_and_url[name] = url
for key, value in name_and_url.items():
    text = key + ".png"
    #print(key + " : " + value)
    download_image(value, text)
#################### Section-3 Output ####################
print("\ndone.")

# Reference

  • modify list elements in a loop
  • ..\Desktop\python\download discord's stickers\batch_download_stickers.py
  • create minimum gui
  • open file folder chosen

# Future