python-download 0.0.1__tar.gz → 0.0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-download
3
- Version: 0.0.1
4
- Summary: Python functions for download.
3
+ Version: 0.0.1.1
4
+ Summary: Python for download.
5
5
  Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-download
6
6
  License: MIT
7
- Keywords: python-download,posixpath
7
+ Keywords: download
8
8
  Author: ChenyangGao
9
9
  Author-email: wosiwujm@gmail.com
10
10
  Requires-Python: >=3.11,<4.0
@@ -32,7 +32,7 @@ Requires-Dist: requests_request
32
32
  Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-download
33
33
  Description-Content-Type: text/markdown
34
34
 
35
- # Python functions for download..
35
+ # Python for download..
36
36
 
37
37
  ## Installation
38
38
 
@@ -44,7 +44,31 @@ pip install -U python-download
44
44
 
45
45
  ## Usage
46
46
 
47
+ ### Module
48
+
47
49
  ```python
48
50
  import download
49
51
  ```
50
52
 
53
+ ### Command
54
+
55
+ ```console
56
+ $ python -m urlopen -h
57
+ usage: python-download [-h] [-d SAVEDIR] [-r] [-hs HEADERS] [-rq] [-v] [url]
58
+
59
+ python url downloader
60
+
61
+ positional arguments:
62
+ url URL(s) to be downloaded (one URL per line), if omitted, read from stdin
63
+
64
+ options:
65
+ -h, --help show this help message and exit
66
+ -d SAVEDIR, --savedir SAVEDIR
67
+ path to the downloaded file
68
+ -r, --resume skip downloaded data
69
+ -hs HEADERS, --headers HEADERS
70
+ dictionary of HTTP Headers to send with
71
+ -rq, --use-requests use `requests` module
72
+ -v, --version print the current version
73
+ ```
74
+
@@ -26,7 +26,7 @@ from os import fsdecode, fstat, makedirs, PathLike
26
26
  from os.path import abspath, dirname, isdir, join as joinpath
27
27
  from shutil import COPY_BUFSIZE # type: ignore
28
28
  from threading import Event
29
- from typing import cast, Any, NamedTuple, Optional, Self
29
+ from typing import cast, Any, NamedTuple, Self
30
30
 
31
31
  from aiohttp_client_request import request as aiohttp_request
32
32
  from asynctools import ensure_async, as_thread
@@ -72,6 +72,7 @@ class DownloadProgress(NamedTuple):
72
72
  return self.completed >= self.total
73
73
 
74
74
 
75
+ # TODO 设计一个 AsyncDownloadTask
75
76
  class DownloadTask:
76
77
 
77
78
  def __init__(self, /, gen, submit=run_as_thread):
@@ -83,7 +84,12 @@ class DownloadTask:
83
84
  self._done_event = Event()
84
85
 
85
86
  def __repr__(self, /) -> str:
86
- return f"<{type(self).__qualname__} :: state={self.state!r} progress={self.progress!r}>"
87
+ match state := self.state:
88
+ case "FINISHED":
89
+ return f"<{type(self).__qualname__} :: state={state!r} result={self.result} progress={self.progress!r}>"
90
+ case "FAILED":
91
+ return f"<{type(self).__qualname__} :: state={state!r} reason={self.result} progress={self.progress!r}>"
92
+ return f"<{type(self).__qualname__} :: state={state!r} progress={self.progress!r}>"
87
93
 
88
94
  @classmethod
89
95
  def create_task(
@@ -100,7 +106,7 @@ class DownloadTask:
100
106
  return self._state in ("CANCELED", "FAILED", "FINISHED")
101
107
 
102
108
  @property
103
- def progress(self, /) -> Optional[DownloadProgress]:
109
+ def progress(self, /) -> None | DownloadProgress:
104
110
  return self.__dict__.get("_progress")
105
111
 
106
112
  @property
@@ -15,7 +15,7 @@ from . import download, requests_download, __version__
15
15
 
16
16
  def parse_args():
17
17
  parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
18
- parser.add_argument("urls", metavar="url", nargs="?", help="URL(s) to be downloaded (one URL per line), if omitted, read from stdin")
18
+ parser.add_argument("urls", metavar="url", nargs="*", help="URL(s) to be downloaded, if omitted, read from stdin (one URL per line)")
19
19
  parser.add_argument("-d", "--savedir", default="", help="path to the downloaded file")
20
20
  parser.add_argument("-r", "--resume", action="store_true", help="skip downloaded data")
21
21
  parser.add_argument("-hs", "--headers", help="dictionary of HTTP Headers to send with")
@@ -55,7 +55,7 @@ def main():
55
55
  args = parse_args()
56
56
 
57
57
  if args.urls:
58
- urls = args.urls.splitlines()
58
+ urls = args.urls
59
59
  else:
60
60
  from sys import stdin
61
61
  urls = (l.removesuffix("\n") for l in stdin)
@@ -85,7 +85,7 @@ def main():
85
85
  headers=headers,
86
86
  )
87
87
  print(f"\r\x1b[K\x1b[1;32mDOWNLOADED\x1b[0m \x1b[4;34m{url!r}\x1b[0m\n |_ ⏬ \x1b[4;34m{file!r}\x1b[0m")
88
- except BaseException as e:
88
+ except Exception as e:
89
89
  print(f"\r\x1b[K\x1b[1;31mERROR\x1b[0m \x1b[4;34m{url!r}\x1b[0m\n |_ 🙅 \x1b[1;31m{type(e).__qualname__}\x1b[0m: {e}")
90
90
  except (EOFError, KeyboardInterrupt):
91
91
  pass
@@ -1,13 +1,13 @@
1
1
  [tool.poetry]
2
2
  name = "python-download"
3
- version = "0.0.1"
4
- description = "Python functions for download."
3
+ version = "0.0.1.1"
4
+ description = "Python for download."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "readme.md"
8
8
  homepage = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-download"
9
9
  repository = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-download"
10
- keywords = ["python-download", "posixpath"]
10
+ keywords = ["download"]
11
11
  classifiers = [
12
12
  "License :: OSI Approved :: MIT License",
13
13
  "Development Status :: 5 - Production/Stable",
@@ -0,0 +1,39 @@
1
+ # Python for download..
2
+
3
+ ## Installation
4
+
5
+ You can install from [pypi](https://pypi.org/project/python-download/)
6
+
7
+ ```console
8
+ pip install -U python-download
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Module
14
+
15
+ ```python
16
+ import download
17
+ ```
18
+
19
+ ### Command
20
+
21
+ ```console
22
+ $ python -m urlopen -h
23
+ usage: python-download [-h] [-d SAVEDIR] [-r] [-hs HEADERS] [-rq] [-v] [url]
24
+
25
+ python url downloader
26
+
27
+ positional arguments:
28
+ url URL(s) to be downloaded (one URL per line), if omitted, read from stdin
29
+
30
+ options:
31
+ -h, --help show this help message and exit
32
+ -d SAVEDIR, --savedir SAVEDIR
33
+ path to the downloaded file
34
+ -r, --resume skip downloaded data
35
+ -hs HEADERS, --headers HEADERS
36
+ dictionary of HTTP Headers to send with
37
+ -rq, --use-requests use `requests` module
38
+ -v, --version print the current version
39
+ ```
@@ -1,15 +0,0 @@
1
- # Python functions for download..
2
-
3
- ## Installation
4
-
5
- You can install from [pypi](https://pypi.org/project/python-download/)
6
-
7
- ```console
8
- pip install -U python-download
9
- ```
10
-
11
- ## Usage
12
-
13
- ```python
14
- import download
15
- ```