Skip to content

Commit

Permalink
Trying to implement resume download
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanshrawat15 committed Nov 2, 2018
1 parent 1524498 commit 0d8b629
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@
from urllib.request import urlopen, urljoin
import urllib
import os.path
import requests
from os import system, name

def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system("clear")

def download_video(video_rel_url, name):
if os.path.isfile(name+".mp4"):
print(""+name+".mp4 : File already exists")
filename = name + ".mp4"
r = requests.get(video_rel_url, stream=True, timeout=10)
file_size = int(r.headers['content-length'])
if os.path.isfile(filename):
file_size_local = os.stat(filename).st_size
if file_size_local == file_size:
print(""+filename+" => File already exists")
else:
print("Resuming download")
file = open(filename)
with open(filename, 'wb', int(file.seek(file_size_local))) as file:
for chunk in r.iter_content(chunk_size=1024*1024):
file.write(chunk)
else:
download = urllib.request.FancyURLopener()
download.retrieve(video_rel_url, name+".mp4")
print(""+name+" downloaded")
with open(filename, 'wb') as file:
for chunk in r.iter_content(chunk_size=1024*1024):
file.write(chunk)

def download_page(url, name):
page = urlopen(url)
Expand All @@ -35,6 +54,7 @@ def verify(pr_link):
print("The following url is not a MIT-OCW link")

def main():
clear()
link = input("Enter Download URL: ")
verify(link)

Expand Down

0 comments on commit 0d8b629

Please sign in to comment.