Skip to content

Instantly share code, notes, and snippets.

@seakintruth
Created January 20, 2022 18:17
Show Gist options
  • Save seakintruth/67ba1dad7b8588ed148caaa44525000f to your computer and use it in GitHub Desktop.
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.
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