Created
January 20, 2022 18:17
-
-
Save seakintruth/67ba1dad7b8588ed148caaa44525000f to your computer and use it in GitHub Desktop.
Download just the first chunk of an mp4 file to test that the url contains something.
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 | |
# From https://stackoverflow.com/a/28374584 | |
def downloadfile(name,url): | |
name=name+".mp4" | |
r=requests.get(url) | |
print("****Connected****") | |
f=open(name,'wb'); | |
print("Downloading.....") | |
for chunk in r.iter_content(chunk_size=255): | |
if chunk: # filter out keep-alive new chunks | |
f.write(chunk) | |
print("Done") | |
f.close() | |
def download_file_first_chunk(name,url): | |
name=name+".mp4" | |
r=requests.get(url) | |
print("****Connected****") | |
f=open(name,'wb'); | |
print("Downloading.....") | |
for chunk in r.iter_content(chunk_size=255): | |
if chunk: # filter out keep-alive new chunks | |
f.write(chunk) | |
break | |
print("Done") | |
f.close() | |
#Test downloading a single mp4 file (this file was randomly selected from 3speak) | |
downloadfile("Test_One", "https://threespeakvideo.b-cdn.net/qnofhybs/NDSQFvtUiifagTtvdZeaCQFdgbLHZrGKzhuzjUlspEAXrOVUHXgWsLzJHDZaaUZH.mp4") | |
download_file_first_chunk("Test_One_first_chunk", "https://threespeakvideo.b-cdn.net/qnofhybs/NDSQFvtUiifagTtvdZeaCQFdgbLHZrGKzhuzjUlspEAXrOVUHXgWsLzJHDZaaUZH.mp4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment