Created
April 17, 2022 06:48
-
-
Save ryankert01/edd774e2036c29d5903bdc95d9a1d501 to your computer and use it in GitHub Desktop.
downlaod youtube tumbnails image in the folder you like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import requests | |
import os | |
#urls to id | |
url = "YouTube URL" | |
exp = "^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*" | |
s = re.findall(exp,url)[0][-1] | |
thumbnail = f"https://i.ytimg.com/vi/{s}/maxresdefault.jpg" | |
#image scraping | |
def imagedown(url, folder): | |
try: | |
os.mkdir(os.path.join(os.getcwd(), folder)) | |
except: | |
pass | |
os.chdir(os.path.join(os.getcwd(), folder)) | |
name = url | |
link = url | |
with open(name.replace(' ', '-').replace('/', '') + '.jpg', 'wb') as f: | |
im = requests.get(link) | |
f.write(im.content) | |
print('Writing: ', name) | |
imagedown(thumbnail, 'image') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment