Search code examples
python-3.xpython-requestsresumedownload-managerraw-data

Add Resume's property to the download manager written with Python and Requests


I wrote a small script can get a link and download it. Now I want to add Resume's property to my script. This script written in python 3 and requests library.

Below is main download section of my code:

class downloader(Thread):
    def __init__(self,url,filename):
        super().__init__()
        self.filename=filename
        self.url=url
    def run(self):
        self.request()
    def request(self):
        headers = {'user-agent': 'pydownloader/0.0.1'}
        r=get(self.url,headers=headers,timeout=10,stream=True)
        with open(self.filename, 'wb') as fd:
            for chunk in r.iter_content(chunk_size=128):
                fd.write(chunk)     
        _exit(1)

Solution

  • I implemented that via Range in http header

    example:

    Range:12343- ===> from 12343 to end

    headers = {'user-agent': 'pydownloader/0.0.1','Range':'bytes=12343-'}