So , I am trying to download a single file in parts using the Python Threading
module and requests
to download.
Now the thing is I am able to download the file into four separate parts but not able to join them.
I tried using PyPDF2
to join pdf and ffmpeg
to join video files but no help. I am not able to open any of the downloaded files which explains that they are not getting downloaded correctly.
PyPDF2
giving error
PdfReadError: EOF marker not found
What should I do so that that I am able to join the files correctly.
Secondly , do I have to use seperate methods to join them, Or I can implement one method which can be used for different file formats
Below is the download
function I implemented.
def download(threadId, drange, url):
headers = {"Range":"bytes={0}-{1}".format(drange[0], drange[1])}
print headers
size = drange[1] - drange[0]
print "Starting Thread {0}".format(threadId)
req = requests.get(url, headers=headers, stream=True)
download_status[size] = size
download_status[threadId] = 0
# return req
with open('test{0}.mp4'.format(threadId), 'wb') as f:
for r in pr.bar(req.iter_content(chunk_size=2048), expected_size=(size/2048)+1):
if r:
f.write(r)
f.flush()