GithubHelp home page GithubHelp logo

aryanvikash / pyaiodl Goto Github PK

View Code? Open in Web Editor NEW
39.0 4.0 16.0 13 KB

A python Asynchronous Downloader - Pyaiodl

Python 100.00%
downloader pypi python async asynchronous python-downloader aiohttp hacktoberfest python3

pyaiodl's Introduction

Python Asynchronous Downloader - pyaoidl

Don't Use it in Production or Live Projects Currently Its Unstable


Python 3.6 Maintenance PyPI license Open Source Love png3 Hits


Version

Beta badge

PyPI version

installation

pypi Method (Recommended)

pip3 install pyaiodl

Github repo method

pip3 install git+https://github.com/aryanvikash/pyaiodl.git

Available Methods

  • Downloader class Instance Non-blocking , params = [fake_useragent:bool,chunk_size:int ,download_path:str] optinals

      dl = Downloader()
    
  • Download [ download(self,url) ]

    uuid = await dl.download(url)
    
  • Errors [iserror(self, uuid)] : Returns - Error Or None , Even On cancel It returns an error "{uuid} Cancelled"

    await dl.iserror(uuid)
    
  • cancel [ cancel(self, uuid) ]

     await dl.cancel(uuid)
    
  • Get Status [ status(self, uuid) ]

      response = await dl.status(uuid)
      
    
    
      returns a dict
    
      """
      filename:str
      file_type :str
      total_size :int
      total_size_str : str
      downloaded :int
      downloaded_str :str
      progress:int
      download_speed:str
      complete :bool
      download_path:str
    
      """
    
  • is_active returns : bool [ is_active( self,uuid ) ] - on cancel ,error , download complete return False

      result = await dl.is_active(uuid)
    

Usage

Example :


from pyaiodl import Downloader, errors
import asyncio
url = "https://speed.hetzner.de/100MB.bin"


async def main():
    dl = Downloader()
    # you can pass your
    # custom chunk size and Download Path
    # dl = Downloader(download_path="/your_dir/", chunk_size=10000)
    uuid = await dl.download(url)
    try:
        while await dl.is_active(uuid):

            r = await dl.status(uuid)

               #cancel
            if r['progress'] > 0:
                try:
                    await dl.cancel("your_uuid")
                except errors.DownloadNotActive as na:
                    print(na)


            print(f"""
            Filename: {r['filename']}
            Total : {r['total_size_str']}
            Downloaded : {r['downloaded_str']}
            Download Speed : {r['download_speed']}
            progress: {r['progress']}
             """)

            # let him breath  for a second:P
            await asyncio.sleep(1)

    # If You are putting uuid  manually Than its better handle This Exception
    except errors.InvalidId:
        print("not valid uuid")
        return

    # when loop Breaks There are 2 Possibility
    # either Its An error Or Download Complete
    # Cancelled Is also count as error
    if await dl.iserror(uuid):
        print(await dl.iserror(uuid))

    else:
        # Final filename / path
       print("Download completed : ", r['download_path'])


asyncio.get_event_loop().run_until_complete(main())

known Bugs -

  • None Please Report :)

TODO

  • Multipart Download
  • Queue Download / Parallel Downloads Limit
  • Better Error Handling

Thanks ❤️


Powered badge

pyaiodl's People

Contributors

aryanvikash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.