Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
17f29a4ac4 | |||
12410f4103 | |||
ca5af9414a | |||
c83e47d3b1 | |||
d0d234a807 |
33
README.md
33
README.md
@ -1,12 +1,12 @@
|
|||||||
ListDownloader
|
ListDownloader
|
||||||
====================
|
==============
|
||||||
|
|
||||||
About
|
About
|
||||||
--------------------
|
-----
|
||||||
This program simply takes a list of files as argument and a directory to download the files, and it downloads them sequentially, or in parallel. The program gives the option to load the whole list, or do parts of the list at a time. An option also is provided for how many threads/processes to be used.
|
This program simply takes a list of files as argument and a directory to download the files, and it downloads them sequentially, or in parallel. The program gives the option to load the whole list, or do parts of the list at a time. An option also is provided for how many threads/processes to be used.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
--------------------
|
------------
|
||||||
|
|
||||||
(Installation was prepared for and tested with Debian Jessie.)
|
(Installation was prepared for and tested with Debian Jessie.)
|
||||||
|
|
||||||
@ -14,7 +14,9 @@ You can install the package with pip using
|
|||||||
|
|
||||||
# pip install listdownloader
|
# pip install listdownloader
|
||||||
|
|
||||||
Or you can create the installation package yourself from the source using
|
OR you can use the scripts that are provided to do that (`run_build`, and `run_install`), which are available in the repository.
|
||||||
|
|
||||||
|
OR you can create the source installation package yourself using
|
||||||
|
|
||||||
python3 setup.py sdist
|
python3 setup.py sdist
|
||||||
|
|
||||||
@ -34,10 +36,14 @@ The script can be executed (globally) using:
|
|||||||
$ downloadlist.py -f file.txt -d destination -t threads -l lines
|
$ downloadlist.py -f file.txt -d destination -t threads -l lines
|
||||||
|
|
||||||
where:
|
where:
|
||||||
`file.txt` is the file name/path with the list of URLs to be downloaded
|
|
||||||
`destination` is the path, to which the files should be downloaded
|
`file.txt` is the file name/path with the list of URLs to be downloaded (line by line)
|
||||||
`threads` is the number of processes to be used to download the URLs simultaneously
|
|
||||||
`lines` is the number of lines to read from the files and read simultaneously. 0 leads to reading the whole file.
|
`destination` is the path, to which the files should be downloaded
|
||||||
|
|
||||||
|
`threads` is the number of processes to be used to download the URLs simultaneously
|
||||||
|
|
||||||
|
`lines` is the number of lines to read from the files and read simultaneously. 0 leads to reading the whole file.
|
||||||
|
|
||||||
You may use the package in your own scripts by importing it:
|
You may use the package in your own scripts by importing it:
|
||||||
|
|
||||||
@ -48,9 +54,12 @@ then you can download a list of files using:
|
|||||||
listdownloader.download_files(URLs, destination, num_threads)
|
listdownloader.download_files(URLs, destination, num_threads)
|
||||||
|
|
||||||
where:
|
where:
|
||||||
`URLs` is a list of the URLs to be downloaded
|
|
||||||
`destination` is a string with the path, at which the files have to be saved
|
`URLs` is a list of the URLs to be downloaded
|
||||||
`num_threads` is the number of threads/processes to use for the download.
|
|
||||||
|
`destination` is a string with the path, at which the files have to be saved
|
||||||
|
|
||||||
|
`num_threads` is the number of threads/processes to use for the download.
|
||||||
|
|
||||||
You can also download a single file using the function:
|
You can also download a single file using the function:
|
||||||
|
|
||||||
@ -62,4 +71,4 @@ MPL
|
|||||||
|
|
||||||
About
|
About
|
||||||
-----
|
-----
|
||||||
This script was written by Samer Afach, samer@afach.de for test purposes.
|
This script was written by Samer Afach for test purposes.
|
||||||
|
10
README.txt
10
README.txt
@ -1,12 +1,12 @@
|
|||||||
ListDownloader
|
ListDownloader
|
||||||
====================
|
==============
|
||||||
|
|
||||||
About
|
About
|
||||||
--------------------
|
-----
|
||||||
This program simply takes a list of files as argument and a directory to download the files, and it downloads them sequentially, or in parallel. The program gives the option to load the whole list, or do parts of the list at a time. An option also is provided for how many threads/processes to be used.
|
This program simply takes a list of files as argument and a directory to download the files, and it downloads them sequentially, or in parallel. The program gives the option to load the whole list, or do parts of the list at a time. An option also is provided for how many threads/processes to be used.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
--------------------
|
------------
|
||||||
|
|
||||||
(Installation was prepared for and tested with Debian Jessie.)
|
(Installation was prepared for and tested with Debian Jessie.)
|
||||||
|
|
||||||
@ -14,7 +14,9 @@ You can install the package with pip using
|
|||||||
|
|
||||||
# pip install listdownloader
|
# pip install listdownloader
|
||||||
|
|
||||||
Or you can create the installation package yourself from the source using
|
OR you can use the scripts that are provided to do that (`run_build`, and `run_install`), which are available in the repository.
|
||||||
|
|
||||||
|
OR you can create the source installation package yourself using
|
||||||
|
|
||||||
python3 setup.py sdist
|
python3 setup.py sdist
|
||||||
|
|
||||||
|
@ -171,17 +171,23 @@ def download_files(list_of_urls, to_dir, processes=0):
|
|||||||
list_of_urls = [line.replace(' ', '').replace('\n', '').replace('\t', '') for line in list_of_urls]
|
list_of_urls = [line.replace(' ', '').replace('\n', '').replace('\t', '') for line in list_of_urls]
|
||||||
if not os.path.isdir(to_dir):
|
if not os.path.isdir(to_dir):
|
||||||
mkdir_p(to_dir)
|
mkdir_p(to_dir)
|
||||||
|
|
||||||
|
# try to detect the number of CPUs automatically
|
||||||
if processes <= 0:
|
if processes <= 0:
|
||||||
try:
|
try:
|
||||||
processes = mp.cpu_count()
|
processes = mp.cpu_count()
|
||||||
except NotImplementedError as e:
|
except NotImplementedError as e:
|
||||||
sys.stderr.write("Unable to determine the number of CPUs for parallelization. Proceeding sequentially. "
|
sys.stderr.write("Unable to determine the number of CPUs for parallelization. Proceeding sequentially. "
|
||||||
"Consider inputting the number of CPUs manually.\n")
|
"Consider inputting the number of CPUs manually. The error says: " + str(e) + "\n")
|
||||||
_download_files(list_of_urls, to_dir)
|
_download_files(list_of_urls, to_dir)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# if there's only 1 process or 1 URL, there's no need to use multiprocessing
|
||||||
elif processes == 1 or len(list_of_urls) == 1:
|
elif processes == 1 or len(list_of_urls) == 1:
|
||||||
_download_files(list_of_urls, to_dir)
|
_download_files(list_of_urls, to_dir)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# if number of processes is larger than the number of URLs, reduce the number of processes to save resources
|
||||||
elif processes > len(list_of_urls):
|
elif processes > len(list_of_urls):
|
||||||
processes = len(list_of_urls)
|
processes = len(list_of_urls)
|
||||||
|
|
||||||
|
14
run_build
Normal file
14
run_build
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#go to the directory of the script
|
||||||
|
reldir=`dirname $0`
|
||||||
|
cd $reldir
|
||||||
|
directory=`pwd`
|
||||||
|
|
||||||
|
rm -rf dist
|
||||||
|
|
||||||
|
python3 setup.py sdist
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo 'Python packager source distribution tool failed.'
|
||||||
|
exit
|
||||||
|
fi
|
18
run_install
Normal file
18
run_install
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#go to the directory of the script
|
||||||
|
reldir=`dirname $0`
|
||||||
|
cd $reldir
|
||||||
|
directory=`pwd`
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "This script must be run as root" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pip3 install dist/listdownloader* --upgrade
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo 'Package installation failed. Did you build the package? Do you have pip3 installed?'
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
3
run_publish
Normal file
3
run_publish
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
python3 setup.py register sdist upload
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ del os.link
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="listdownloader",
|
name="listdownloader",
|
||||||
version="0.1.3",
|
version="0.1.4",
|
||||||
author="Samer Afach",
|
author="Samer Afach",
|
||||||
author_email="samer@afach.de",
|
author_email="samer@afach.de",
|
||||||
packages=["listdownloader"],
|
packages=["listdownloader"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user