Last active
February 10, 2017 14:33
-
-
Save bazuzu931/6a91f0d2065c421d2b6286fcf5d44ffd to your computer and use it in GitHub Desktop.
download_big_file_by_chunks.py
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 requests | |
def download(url): | |
file = url.split('/')[-1] | |
if file.split('.')[-1] != "mp3": | |
file += ".mp3" | |
r = requests.get(url, stream=True) | |
with open(file, 'wb') as f: | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
return file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment