web-dl-cli 0.1.0__py3-none-any.whl
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.
web_dl/__init__.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""web-dl: download a URL with yt-dlp when a site is supported, otherwise with curl."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import urllib.parse
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
SITE = "https://web-dl.net"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def is_p2p(url):
|
|
16
|
+
u = url.lower().split("?")[0]
|
|
17
|
+
return (u.startswith("magnet:") or u.endswith((".torrent", ".nzb"))
|
|
18
|
+
or re.fullmatch(r"[0-9a-f]{40}|[a-z2-7]{32}", u) is not None)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def content_type(url):
|
|
22
|
+
"""The final Content-Type after redirects, from a HEAD request; '' if unknown."""
|
|
23
|
+
try:
|
|
24
|
+
out = subprocess.run(["curl", "-sIL", "--max-time", "15", "-o", os.devnull, "-w", "%{content_type}", url],
|
|
25
|
+
capture_output=True, text=True).stdout
|
|
26
|
+
except OSError:
|
|
27
|
+
return ""
|
|
28
|
+
return out.split(";")[0].strip().lower()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def ytdlp(url, outdir, audio):
|
|
32
|
+
cmd = [sys.executable, "-m", "yt_dlp", "-P", outdir]
|
|
33
|
+
if audio:
|
|
34
|
+
cmd.append("-x")
|
|
35
|
+
proc = subprocess.Popen(cmd + [url], stderr=subprocess.PIPE, text=True, errors="replace")
|
|
36
|
+
unsupported = False
|
|
37
|
+
for line in proc.stderr:
|
|
38
|
+
sys.stderr.write(line)
|
|
39
|
+
unsupported |= "Unsupported URL" in line
|
|
40
|
+
return proc.wait(), unsupported
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def curl(url, outdir):
|
|
44
|
+
if not shutil.which("curl"):
|
|
45
|
+
print("web-dl: curl not found", file=sys.stderr)
|
|
46
|
+
return 127
|
|
47
|
+
parts = urllib.parse.urlsplit(url)
|
|
48
|
+
if os.path.basename(parts.path):
|
|
49
|
+
name = ["-O", "-J"] # name from the URL, or from Content-Disposition when the server sends one
|
|
50
|
+
else:
|
|
51
|
+
name = ["-o", (parts.hostname or "index") + ".html"]
|
|
52
|
+
return subprocess.call(["curl", "-fL", "--retry", "3", *name, url], cwd=outdir)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main():
|
|
56
|
+
ap = argparse.ArgumentParser(prog="web-dl", description="Download a URL: yt-dlp for media sites, curl for files.")
|
|
57
|
+
ap.add_argument("urls", nargs="+", metavar="URL")
|
|
58
|
+
ap.add_argument("-o", "--output", default=".", help="directory to save into (default: current)")
|
|
59
|
+
ap.add_argument("-x", "--audio", action="store_true", help="audio only (yt-dlp)")
|
|
60
|
+
ap.add_argument("-V", "--version", action="version", version=f"web-dl {__version__}")
|
|
61
|
+
args = ap.parse_args()
|
|
62
|
+
os.makedirs(args.output, exist_ok=True)
|
|
63
|
+
status = 0
|
|
64
|
+
for url in args.urls:
|
|
65
|
+
if is_p2p(url):
|
|
66
|
+
print(f"web-dl: torrents and Usenet are not in the CLI yet, open {SITE} to stream or download them",
|
|
67
|
+
file=sys.stderr)
|
|
68
|
+
status = 2
|
|
69
|
+
continue
|
|
70
|
+
ctype = content_type(url)
|
|
71
|
+
if ctype and ctype != "text/html" and not args.audio:
|
|
72
|
+
status = status or curl(url, args.output) # a file, not a page: plain download keeps its name
|
|
73
|
+
continue
|
|
74
|
+
code, unsupported = ytdlp(url, args.output, args.audio)
|
|
75
|
+
if code != 0 and unsupported:
|
|
76
|
+
print("web-dl: not a media page, downloading with curl", file=sys.stderr)
|
|
77
|
+
code = curl(url, args.output)
|
|
78
|
+
status = status or code
|
|
79
|
+
sys.exit(status)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: web-dl-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: web-dl: download anything from a URL, using yt-dlp for media sites and curl for files
|
|
5
|
+
Project-URL: Homepage, https://web-dl.net
|
|
6
|
+
Author-email: web-dl <hello@web-dl.net>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Requires-Dist: yt-dlp
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# web-dl CLI
|
|
16
|
+
|
|
17
|
+
Early versions of the `web-dl` command, published to hold the name on each registry. Today it is a thin wrapper:
|
|
18
|
+
`web-dl <url>` downloads with yt-dlp when the site is one yt-dlp supports, and falls back to curl for plain files.
|
|
19
|
+
Magnet links, infohashes, .torrent and .nzb files are pointed to https://web-dl.net until the real client ships.
|
|
20
|
+
|
|
21
|
+
| Registry | Package | Install |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| PyPI | `web-dl-cli` (`web-dl` is blocked as too similar to `webdl`) | `pipx install web-dl-cli` |
|
|
24
|
+
| npm | see `node/package.json` | `npm i -g <package>` |
|
|
25
|
+
| crates.io | `web-dl` | `cargo install web-dl` |
|
|
26
|
+
|
|
27
|
+
The Python package depends on yt-dlp, so it works without anything else installed. The npm and Rust versions call
|
|
28
|
+
`yt-dlp` and `curl` from PATH.
|
|
29
|
+
|
|
30
|
+
Usage: `web-dl [-o DIR] [-x] URL...` where `-x` extracts audio only (yt-dlp).
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
web_dl/__init__.py,sha256=F4wE79LTS3aPWwllAZF4CEDqIXtm5B4AhdltIlp6suU,2984
|
|
2
|
+
web_dl_cli-0.1.0.dist-info/METADATA,sha256=lsj_EqXCBhRZxCSW-1aez7SU_KXT_q_o1QJ2CIyWf6Q,1301
|
|
3
|
+
web_dl_cli-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
4
|
+
web_dl_cli-0.1.0.dist-info/entry_points.txt,sha256=5oMalr3TYPWNSSrTse-mivKqxAIH-EH6xreVC7oQdDk,39
|
|
5
|
+
web_dl_cli-0.1.0.dist-info/RECORD,,
|