Git Product home page Git Product logo

downloader-cli's Introduction

downloader-cli

A simple downloader written in Python with an awesome progressbar.


Installation   |   Requirements   |   Usage   |   Use It   |   Other examples   

forthebadge made-with-python

License Downloads PyPI AUR PRs Welcome

Installation

NOTE: The following packages (except installing manually) will get you the latest release. If you want to try out the latest development stuff, install manually.

PyPI

The package is available in PyPI here

Install it using

pip install downloader-cli

Arch

The package is available in the AUR here

Install it using yay

yay -S downloader-cli

Gentoo

The package is also available in src_prepare Gentoo overlay here

First set up src_prepare-overlay

sudo emerge -anv --noreplace app-eselect/eselect-repository
sudo eselect repository enable src_prepare-overlay
sudo emaint sync -r src_prepare-overlay

Install it using

sudo emerge -anv --autounmask net-misc/downloader-cli

Conda-Forge

Installing downloader-cli from the conda-forge channel can be achieved by adding conda-forge to your channels with:

conda config --add channels conda-forge
conda config --set channel_priority strict

Once the conda-forge channel has been enabled, downloader-cli can be installed with:

conda install downloader-cli

It is possible to list all of the versions of downloader-cli available on your platform with:

conda search downloader-cli --channel conda-forge

Manual

If you want to manuall install, clone the repo and run the following command

sudo python setup.py install

Requirements

downloader-cli requires just one external module.

Usage

The script also allows some other values from the commandline.

usage: dw [-h] [-f | -c] [-e] [-q] [-b] [-v] [--done DONE] [--left LEFT]
          [--current CURRENT] [--color-done COLOR_DONE]
          [--color-left COLOR_LEFT] [--color-current COLOR_CURRENT]
          [--icon-border ICON_BORDER]
          SOURCE [TARGET]

positional arguments:
  SOURCE                URL of the file
  TARGET                target filepath (existing directories will be treated
                        as the target location)

optional arguments:
  -h, --help            show this help message and exit
  -f, -o, --force       overwrite if the file already exists
  -c, --resume          resume failed or cancelled download (partial sanity
                        check)
  -e, --echo            print the filepath to stdout after downloading (other
                        output will be redirected to stderr)
  -q, --quiet           suppress filesize and progress info
  -b, --batch           Download files in batch. If this flag is passed the
                        passed source will be considered as a file with
                        download links seperated by a newline. This flag will
                        be ignored if source is a valid URL.
  -v, --version         show the program version number and exit

UI Group:
  --done DONE           Icon indicating the percentage done of the downloader
  --left LEFT           Icon indicating the percentage remaining to download
  --current CURRENT     Icon indicating the current percentage in the progress
                        bar
  --color-done COLOR_DONE
                        Color for the done percentage icon
  --color-left COLOR_LEFT
                        Color for the remaining percentage icon
  --color-current COLOR_CURRENT
                        Color for the current indicator icon in the progress
                        bar
  --icon-border ICON_BORDER
                        Icon for the border of the progress bar

Use It

Want to use it in your project?

Import the Download class using the following.

from downloader_cli.download import Download
Download(url).download()

Above is the simplest way to use it in your app. The other arguments are optional.

Arguments

The module takes various arguments. Only one is required though.

Name required default
URL/file Yes
des No None (Current directory is selected and the name is extracted from the URL)
overwrite No False
continue_download No False
echo No False
quiet No False
batch No False
icon_done No
icon_left No
icon_current No
icon_border No | (If a single char is passed, it will be used for both the right and left border. If a string of 2 chars are passed, 1st char will be used as left border and the 2nd as the right border)
color_done No blue
color_left No blue
color_current No blue

NOTE For details regarding the arguments, check Usage

NOTE In case the file size is not available, the bar is shown as indefinite, in which case the icon_left by default space(" ").

Other examples

In case you want to experiment with the progress bar's icons, here's some examples.

  • This is when I passed icon_done as # and icon_left as space.

  • In case a file's size is not available from the server, the progressbar is indefinite.

downloader-cli's People

Contributors

chancencounter avatar deepjyoti30 avatar heavytony2 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

downloader-cli's Issues

Filesize check on line 76 can fail on missing Content-Length header

I don't know much more about it than the person on reddit knew, but I thought I'd document this here. Some download requests don't get Content-Length, causing a TypeError exception on line 76. I was able to reproduce this by attempting to download download.py directly from this repo (via the raw content link.)

doesn't skip fully downloaded files

Seems to download unnecessary data onto already completed files instead of skipping it. The file size just ends up larger than the original size. So maybe add a condition for cur_size >= int(original_size) or something

if original_size is None:
print("WARNING: Could not perform sanity check on partial download.",
file=self.ostream)
self._build_headers(cur_size)
elif cur_size < int(original_size):
self._build_headers(cur_size)

ERROR: Errno 22 on instagram pictures

If I try to download a picture from instagram I get errno 22.

For example if I try to download the picture from this url:

https://scontent-muc2-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/138734412_2824463591207841_3866668501561580560_n.jpg?_nc_ht=scontent-muc2-1.cdninstagram.com&_nc_cat=109&_nc_ohc=KyByhjfBR1cAX9pp60k&tp=1&oh=c6072950e86196c504ac446f885378f3&oe=6037334E

I get following error:

ERROR: [Errno 22] Invalid argument: '138734412_2824463591207841_3866668501561580560_n.jpg?_nc_ht=scontent-muc2-1.cdninstagram.com&_nc_cat=109&_nc_ohc=KyByhjfBR1cAX9pp60k&tp=1&oh=c6072950e86196c504ac446f885378f3&oe=6037334E'

I think it tries to get the filename and splits the url wrong?

UPDATE: Only happens on Python3 installed on Windows 10. On my linux machine it runs without an error.

Robust tests

Now that GitHub Actions are free, depending on the storage situation, it might be possible to run pytest on push/PR. Also to have it try each invocation in succession, against a checksum (download, check integrity, delete, download, interrupt, resume, check integrity...)

Inappropriate ioctl for device

The downloader in a specific machine writes 8192 bytes to a file and an exception occurs with this message: ERROR: [Errno 25] Inappropriate ioctl for device

Any ideas?

ERROR 'is a directory'

Everytime I try to download a file I get the error '{foldername} is a directory'.
des= the foldername I wan't to download the file to.

Where is the error?

image

Thanks!

ERROR: float division by zero

Hey, I've noticed that I often get a divide by zero error when trying to download files.
It appears the code does not handle the case when cur_time - beg_time is 0

Traceback (most recent call last):
  File "downloader-cli\0.3.1\downloader_cli\download.py", line 376, in _download
    speed, s_unit, time_left, time_unit = self._get_speed_n_time(
  File "downloader-cli\0.3.1\downloader_cli\download.py", line 264, in _get_speed_n_time
    speed = (file_size_dl / 1024) / (cur_time - beg_time)
ZeroDivisionError: float division by zero

Turn this into a package?

Display is very cool, but having an alias/copying download.py to whatever directory you want to use it it in is fiddly, especially in big projects.

It would be easier if this was installed using setuptools, which would automatically install urllib3, and create the dw console script regardless of OS. (so no need to create the alias)

If it was installed into the global python packages, one could use it anywhere, by doing something like

pip3 install --user git+https://github.com/deepjyoti30/downloader-cli

and then importing it like any other package you'd install with pip.

If this seems like something you'd want to do, I can create a PR.

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.