Skip to content

Instantly share code, notes, and snippets.

@quanon
Created April 25, 2017 14:22
Show Gist options
  • Save quanon/f63f2635427bf7930f13b67b16abdf32 to your computer and use it in GitHub Desktop.
Save quanon/f63f2635427bf7930f13b67b16abdf32 to your computer and use it in GitHub Desktop.
import os
import re
import sys
import time
from urllib.request import urlretrieve
channel = sys.argv[1]
with open(f'{channel}.txt', 'rt') as f:
lines = f.readlines()
if not os.path.exists(channel):
os.makedirs(channel)
for url in lines:
name = re.findall(r'(?<=vi/).*(?=/hqdefault)', url)[0]
path = os.path.join(channel, f'{name}.jpg')
if os.path.exists(path):
print(f'{path} already exists')
continue
print(f'download {path}')
urlretrieve(url, path)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment