@@ -3,17 +3,17 @@ pyloader - A simple python downloader
3
3
[ ![ Build Status] ( https://travis-ci.org/linuxwhatelse/pyloader.svg?branch=master )] ( https://travis-ci.org/linuxwhatelse/pyloader )
4
4
[ ![ pypi] ( https://img.shields.io/pypi/v/lwe-pyloader.svg )] ( https://pypi.python.org/pypi/lwe-pyloader )
5
5
6
- ** pyloader** is a simple, easy to use, multi-threaded downloader with queuing support.
6
+ ** pyloader** is a simple, easy to use, multi-threaded downloader with queuing support.
7
7
8
- It is ** NOT** a command-line utility but instead something you can (if you want) implement
9
- in one (or more, I don't care :)) of your applications.
8
+ It is ** NOT** a command-line utility but instead something you can (if you want) implement
9
+ in one (or more, I don't care :)) of your applications.
10
10
11
- I was in need for such a thing and that's why I wrote it myself after only finding command-line utilities.
12
- (I haven 't spent a lot of time searching though)
11
+ I wrote project-specific downloader a few times now and finally decided to create a proper module for it as
12
+ I couldn 't find an existing one (Haven't spent that much time searching though).
13
13
14
14
## Important notice
15
15
As of right now, this is ** Beta** , so treat it as such ;)
16
- I added some unittests but there're still many more to go
16
+ I added some unittests but there're still more to go!
17
17
18
18
## ToDo
19
19
Things to implement:
@@ -26,106 +26,22 @@ What you need:
26
26
* The great python [ requests] ( https://github.com/kennethreitz/requests ) module
27
27
28
28
## Installation
29
- Just run:
29
+ ### From pypi (recommanded)
30
30
``` bash
31
31
pip install lwe-pyloader
32
32
```
33
-
33
+ ### From source
34
+ ``` bash
35
+ git clone https://github.com/linuxwhatelse/pyloader
36
+ cd pyloader
37
+ python setup.py install
38
+ ```
34
39
## Usage
35
- The source has been commented quite well so at any point in time you might just:
40
+ The source has been commented quite well so at any point you might just:
36
41
``` python
37
42
import pyloader
38
43
help (pyloader)
39
44
```
40
45
41
- But to get you started, here are some examples :)
42
- ``` python
43
- import pyloader
44
-
45
- def progress_callback (progress ):
46
- # !!!IMPORTANT NOTE !!!
47
- # The callback will NOT be called within a separate thread
48
- # (to ensure consistancy) and WILL block the download
49
- # for as long as your callback runs!
50
- # Think twice about what you do in here.
51
- # Usually you just want to persist/visualize data.
52
-
53
- # Use ``help(pyloader.Progress)`` to know what's available
54
- print (progress.percent)
55
-
56
- # To cancel the download
57
- return True
58
- # If you don't want to cancel,
59
- return False
60
- # or return nothing at all
61
-
62
- def url_resolver (item ):
63
- # Here you would resolve the url to something
64
- # that can actually be downloaded.
65
- # Useful in case resource-urls would expire after
66
- # a set amount of time.
67
- return item.url
68
-
69
- if __name__ == ' __main__' :
70
- # Create a loader instance
71
- dl = pyloader.Loader.get_loader()
72
- dl.configure(
73
- max_concurrent = 3 ,
74
- update_interval = 3 ,
75
- progress_cb = progress_callback,
76
- url_resolve_cb = url_resolver,
77
- daemon = False
78
- )
79
-
80
- # Start the loader
81
- # Make sure you know how the `daemon` flag
82
- # affects the liftime of your program
83
- dl.start()
84
-
85
- # Create a downloadable item
86
- # Make sure to read the docstrings via
87
- # help(pyloader.DLable)
88
- # for available arguments
89
- item = pyloader.DLable(
90
- url = ' http://download.thinkbroadband.com/5MB.zip' ,
91
- target_dir = ' ~/Downloads/' ,
92
- )
93
-
94
- # Queue an item or...
95
- dl.queue(item)
96
- # ...alternatively you can force a download,
97
- # ignoring ``max_concurrent``
98
- dl.download(item)
99
-
100
- # If you don't use a callback (to, if necessary, cancel a download),
101
- # you can stop one via:
102
- dl.stop(item)
103
- # or via its uid
104
- dl.stop(item.uid)
105
-
106
- # You can also clear the queue by
107
- dl.clear_queue()
108
- # and active items as well
109
- dl.clear_active()
110
- # though you'll never need the second one as there
111
- # are little to none cases where items are actually
112
- # stuck within the active queue
113
-
114
- # To check the downloaders state you can:
115
- print (dl.is_alive) # True if both necessary main threads are still alive and kicking
116
- print (dl.is_active) # True if items are queued and/or downloading
117
-
118
- print (dl.queued) # Returns the amount of queued items
119
- print (dl.active) # Returns the amount of active/downloading items
120
-
121
- print (dl.max_concurrent) # The amount of maximum concurrent allowed downloads
122
- dl.max_concurrent = 5 # Set the amount up to 5 and starts new downloads (if any)
123
-
124
- # To stop all downloads and end the downloader just do:
125
- dl.exit()
126
-
127
- # Important to note here, queued/active items will **NOT** be persisted upon exit (or any other point in time)
128
- # It's up to you to keep track of the items ;)
129
- ```
130
- Well, that should be enough to get you going (I hope)
46
+ To get you started though, check the included [ examples] ( examples ) .
131
47
Happy coding! :)
0 commit comments