# Goal
Batch download our favorite youtuber's (or VTuber's) membership emoji.
# Info
Key | Value |
---|
Date created | 2023/7/7 |
Date modified | 2023/7/8 |
Author | Benjamin Yang |
Language | Python |
Used module | re , requests , tkinter , tkinter.filedialog.askdirectory |
File location | ..\Desktop\python\download youtube's stickers\download_youtube_membership_stickers.py |
# Flow chart
# Code
download_youtube_membership_stickers.py | |
| import re |
| import requests |
| import tkinter as tk |
| from tkinter.filedialog import askdirectory |
| |
| stringInput = input("Input VTr stickers' sources code:\n\n") |
| |
| |
| root = tk.Tk() |
| root.withdraw() |
| |
| print("\nWarning: the directory selector is opening, please check if it had been hidden.\n") |
| |
| 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}") |
| |
| |
| reg1 = """alt="[\S]*\"""" |
| reg2 = """src="[\S]*=w""" |
| |
| |
| |
| sticker_names = re.findall(reg1, stringInput) |
| sticker_urls = re.findall(reg2, stringInput) |
| name_and_url = {} |
| |
| 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" |
| |
| download_image(value, text) |
| |
| |
| 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