rayohx-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.
- rayohx_cli/__init__.py +3 -0
- rayohx_cli/__main__.py +6 -0
- rayohx_cli/cli/__init__.py +26 -0
- rayohx_cli/cli/clean.py +59 -0
- rayohx_cli/cli/common.py +108 -0
- rayohx_cli/cli/config.py +82 -0
- rayohx_cli/cli/download.py +262 -0
- rayohx_cli/cli/info.py +121 -0
- rayohx_cli/cli/lifecycle.py +190 -0
- rayohx_cli/cli/root.py +105 -0
- rayohx_cli/events.py +40 -0
- rayohx_cli/format.py +34 -0
- rayohx_cli/output.py +119 -0
- rayohx_cli/params/__init__.py +147 -0
- rayohx_cli/params/display.py +35 -0
- rayohx_cli/params/engine.py +106 -0
- rayohx_cli/params/network.py +227 -0
- rayohx_cli/params/output.py +77 -0
- rayohx_cli/params/panels.py +7 -0
- rayohx_cli/params/selection.py +187 -0
- rayohx_cli/progress/__init__.py +24 -0
- rayohx_cli/progress/_factory.py +20 -0
- rayohx_cli/progress/_text.py +47 -0
- rayohx_cli/progress/reporters/__init__.py +8 -0
- rayohx_cli/progress/reporters/bar.py +60 -0
- rayohx_cli/progress/reporters/base.py +19 -0
- rayohx_cli/progress/reporters/null.py +16 -0
- rayohx_cli/progress/reporters/plain.py +38 -0
- rayohx_cli/py.typed +0 -0
- rayohx_cli/render.py +122 -0
- rayohx_cli/settings.py +78 -0
- rayohx_cli/values.py +284 -0
- rayohx_cli-0.1.0.dist-info/METADATA +92 -0
- rayohx_cli-0.1.0.dist-info/RECORD +37 -0
- rayohx_cli-0.1.0.dist-info/WHEEL +4 -0
- rayohx_cli-0.1.0.dist-info/entry_points.txt +2 -0
- rayohx_cli-0.1.0.dist-info/licenses/LICENSE +201 -0
rayohx_cli/__init__.py
ADDED
rayohx_cli/__main__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Command line interface built on Typer and Rich. It only parses input and shows output.
|
|
2
|
+
|
|
3
|
+
All the work is done by the ``rayohx`` library: ``inspect`` for ``info`` and ``Downloader`` for
|
|
4
|
+
``download``. Data (the result) goes to stdout and messages go to stderr, so the result can be
|
|
5
|
+
piped. Exit codes: 0 success, 1 the operation failed, 2 the command or a setting was invalid,
|
|
6
|
+
130 stopped with Ctrl-C.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from rayohx_cli import output
|
|
10
|
+
from rayohx_cli.cli import clean, config, download, info # noqa: F401 (registers the commands)
|
|
11
|
+
from rayohx_cli.cli.common import EXIT_CANCELLED, EXIT_FAILED, EXIT_USAGE
|
|
12
|
+
from rayohx_cli.cli.root import app
|
|
13
|
+
|
|
14
|
+
__all__ = ["EXIT_CANCELLED", "EXIT_FAILED", "EXIT_USAGE", "app", "run"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run() -> None:
|
|
18
|
+
"""Console script entry point: run the app and report unexpected errors briefly."""
|
|
19
|
+
try:
|
|
20
|
+
app()
|
|
21
|
+
except KeyboardInterrupt:
|
|
22
|
+
output.err_console.print("Interrupted.")
|
|
23
|
+
raise SystemExit(EXIT_CANCELLED) from None
|
|
24
|
+
except Exception as exc:
|
|
25
|
+
output.print_exception(exc)
|
|
26
|
+
raise SystemExit(EXIT_FAILED) from exc
|
rayohx_cli/cli/clean.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""The ``clean`` command: remove working folders left behind by interrupted downloads."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from rayohx_cli import format as fmt
|
|
9
|
+
from rayohx_cli import output
|
|
10
|
+
from rayohx_cli.cli.root import app
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@app.command()
|
|
14
|
+
def clean(
|
|
15
|
+
folders: Annotated[
|
|
16
|
+
list[Path] | None,
|
|
17
|
+
typer.Argument(
|
|
18
|
+
help="Folders to look in (default: the current folder). Use the folder you gave "
|
|
19
|
+
"to --workspace or --output.",
|
|
20
|
+
metavar="[FOLDER]...",
|
|
21
|
+
),
|
|
22
|
+
] = None,
|
|
23
|
+
older_than: Annotated[
|
|
24
|
+
float,
|
|
25
|
+
typer.Option(
|
|
26
|
+
"--older-than", min=0, help="Only folders not used for this many days (default 0)."
|
|
27
|
+
),
|
|
28
|
+
] = 0,
|
|
29
|
+
dry_run: Annotated[
|
|
30
|
+
bool, typer.Option("--dry-run", help="Only list what would be removed.")
|
|
31
|
+
] = False,
|
|
32
|
+
yes: Annotated[bool, typer.Option("--yes", "-y", help="Do not ask first.")] = False,
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Remove working folders left by interrupted downloads.
|
|
35
|
+
|
|
36
|
+
Removing one means that download starts again from the beginning. Folders in use by a
|
|
37
|
+
running download are never removed. The folders removed are printed on stdout.
|
|
38
|
+
"""
|
|
39
|
+
from rayohx import find_workspaces, remove_workspaces
|
|
40
|
+
|
|
41
|
+
found = find_workspaces(folders, older_than)
|
|
42
|
+
candidates = [w for w in found if not w.in_use]
|
|
43
|
+
skipped = len(found) - len(candidates)
|
|
44
|
+
if not candidates:
|
|
45
|
+
output.message("Nothing to clean." + (f" {skipped} in use." if skipped else ""))
|
|
46
|
+
return
|
|
47
|
+
total = sum(w.size for w in candidates)
|
|
48
|
+
for w in candidates:
|
|
49
|
+
output.message(f"{w.path} {fmt.size(w.size)}, last used {w.age_days:.1f} days ago")
|
|
50
|
+
if dry_run:
|
|
51
|
+
output.message(f"Would remove {len(candidates)} folder(s), {fmt.size(total)}.")
|
|
52
|
+
return
|
|
53
|
+
if not yes and not typer.confirm(
|
|
54
|
+
f"Remove {len(candidates)} folder(s) ({fmt.size(total)})?", err=True
|
|
55
|
+
):
|
|
56
|
+
raise typer.Exit(1)
|
|
57
|
+
for path in remove_workspaces(candidates):
|
|
58
|
+
output.data(str(path))
|
|
59
|
+
output.message(f"Removed {len(candidates)} folder(s), {fmt.size(total)}.", style="green")
|
rayohx_cli/cli/common.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""What every command shares: exit codes and turning bad settings into a usage error."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import TYPE_CHECKING, NoReturn
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from rayohx.config import DownloadConfig
|
|
11
|
+
from rayohx.errors import ConfigurationError, RayoHXError
|
|
12
|
+
|
|
13
|
+
from rayohx_cli import output
|
|
14
|
+
from rayohx_cli.values import build_config
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
EXIT_FAILED = 1
|
|
21
|
+
EXIT_USAGE = 2
|
|
22
|
+
EXIT_CANCELLED = 130
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def usage_error(exc: RayoHXError) -> NoReturn:
|
|
26
|
+
output.error_from(exc)
|
|
27
|
+
raise typer.Exit(EXIT_USAGE)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def make_config(**options: object) -> DownloadConfig:
|
|
31
|
+
"""Build the engine's settings, turning a bad value into a usage error."""
|
|
32
|
+
try:
|
|
33
|
+
return build_config(**options) # type: ignore[arg-type]
|
|
34
|
+
except ConfigurationError as exc:
|
|
35
|
+
usage_error(exc)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def read_playlist_file(path: Path) -> str:
|
|
39
|
+
"""The playlist text in ``path``, or a usage error if it cannot be read."""
|
|
40
|
+
try:
|
|
41
|
+
return path.read_text(encoding="utf-8")
|
|
42
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
43
|
+
usage_error(ConfigurationError(f"The playlist file {path} cannot be read."))
|
|
44
|
+
raise exc # unreachable: usage_error exits
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def gather_urls(urls: Sequence[str], input_file: Path | None) -> list[str]:
|
|
48
|
+
"""The addresses given as arguments, then those listed in ``input_file`` (``-`` is stdin)."""
|
|
49
|
+
found = list(urls)
|
|
50
|
+
if input_file is not None:
|
|
51
|
+
try:
|
|
52
|
+
if str(input_file) == "-":
|
|
53
|
+
text = sys.stdin.read()
|
|
54
|
+
else:
|
|
55
|
+
text = input_file.read_text(encoding="utf-8")
|
|
56
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
57
|
+
usage_error(ConfigurationError(f"The address list {input_file} cannot be read."))
|
|
58
|
+
raise exc # unreachable: usage_error exits
|
|
59
|
+
found.extend(
|
|
60
|
+
line.strip()
|
|
61
|
+
for line in text.splitlines()
|
|
62
|
+
if line.strip() and not line.strip().startswith("#")
|
|
63
|
+
)
|
|
64
|
+
if not found:
|
|
65
|
+
usage_error(
|
|
66
|
+
ConfigurationError(
|
|
67
|
+
"There is nothing to download.",
|
|
68
|
+
hint="Give an address, or a list of addresses with --input-file.",
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
return found
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass(frozen=True)
|
|
75
|
+
class Source:
|
|
76
|
+
"""Where a playlist comes from: a web address, or playlist text already read from a file."""
|
|
77
|
+
|
|
78
|
+
url: str
|
|
79
|
+
text: str | None = None
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def label(self) -> str:
|
|
83
|
+
from rayohx._redaction import redact_url
|
|
84
|
+
|
|
85
|
+
return redact_url(self.url) if self.text is None else self.url
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
PLACEHOLDER_HOST = "https://playlist.invalid/"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def open_source(target: str, base_url: str | None, playlist_file: Path | None = None) -> Source:
|
|
92
|
+
"""A web address as it is, or a local playlist file read in.
|
|
93
|
+
|
|
94
|
+
``playlist_file`` names the file explicitly; otherwise ``target`` is taken as a file when it
|
|
95
|
+
is not a web address and exists. The playlist's relative addresses are resolved against
|
|
96
|
+
``base_url``, or the address given. A local file given alone, with no ``base_url``, gets a
|
|
97
|
+
placeholder address, which suits playlists whose addresses are all absolute.
|
|
98
|
+
"""
|
|
99
|
+
if playlist_file is not None:
|
|
100
|
+
return Source(base_url or target, read_playlist_file(playlist_file))
|
|
101
|
+
if target.lower().startswith(("http://", "https://")):
|
|
102
|
+
return Source(target)
|
|
103
|
+
from pathlib import Path
|
|
104
|
+
|
|
105
|
+
path = Path(target).expanduser()
|
|
106
|
+
if not path.is_file():
|
|
107
|
+
return Source(target) # not a file: let the address check explain what is wrong
|
|
108
|
+
return Source(base_url or PLACEHOLDER_HOST + path.name, read_playlist_file(path))
|
rayohx_cli/cli/config.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""The ``config`` command: show which settings are in effect."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING, Annotated
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
|
|
10
|
+
from rayohx_cli import output
|
|
11
|
+
from rayohx_cli.cli.common import usage_error
|
|
12
|
+
from rayohx_cli.cli.root import app
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from collections.abc import Mapping
|
|
16
|
+
|
|
17
|
+
_SECRET_WORDS = ("PASSWORD", "PROXY", "COOKIE", "HEADER", "KEY", "TOKEN", "SECRET")
|
|
18
|
+
_HIDDEN = "***"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def environment_settings(environ: Mapping[str, str]) -> dict[str, str]:
|
|
22
|
+
"""The ``RAYOHX_*`` variables that are set, with anything that may be secret hidden."""
|
|
23
|
+
return {
|
|
24
|
+
name: _HIDDEN if any(word in name for word in _SECRET_WORDS) else value
|
|
25
|
+
for name, value in sorted(environ.items())
|
|
26
|
+
if name.startswith("RAYOHX_")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@app.command()
|
|
31
|
+
def config(
|
|
32
|
+
ctx: typer.Context,
|
|
33
|
+
json_output: Annotated[
|
|
34
|
+
bool, typer.Option("--json", help="Print the result as JSON on stdout.")
|
|
35
|
+
] = False,
|
|
36
|
+
) -> None:
|
|
37
|
+
"""Show the settings file in use and the RAYOHX_ environment variables that are set.
|
|
38
|
+
|
|
39
|
+
Values that may be secret (proxies, passwords, cookies, headers, keys) are hidden.
|
|
40
|
+
"""
|
|
41
|
+
import os
|
|
42
|
+
|
|
43
|
+
from rayohx.errors import ConfigurationError
|
|
44
|
+
|
|
45
|
+
from rayohx_cli.settings import FILE_NAME, find_config, load_config, user_config_file
|
|
46
|
+
|
|
47
|
+
parent = ctx.parent.params if ctx.parent else {}
|
|
48
|
+
given = parent.get("config")
|
|
49
|
+
explicit, ignored = (Path(given) if given else None), bool(parent.get("no_config"))
|
|
50
|
+
path = None
|
|
51
|
+
values: dict[str, object] = {}
|
|
52
|
+
if not ignored:
|
|
53
|
+
try:
|
|
54
|
+
path = find_config(explicit)
|
|
55
|
+
if path is not None:
|
|
56
|
+
commands = getattr(typer.main.get_command(app), "commands", {})
|
|
57
|
+
known = {o.name for c in commands.values() for o in c.params if o.name}
|
|
58
|
+
values = load_config(path, known)
|
|
59
|
+
except ConfigurationError as exc:
|
|
60
|
+
usage_error(exc)
|
|
61
|
+
hidden = {
|
|
62
|
+
key: _HIDDEN if any(word in key.upper() for word in _SECRET_WORDS) else value
|
|
63
|
+
for key, value in values.items()
|
|
64
|
+
}
|
|
65
|
+
environment = environment_settings(os.environ)
|
|
66
|
+
document: dict[str, object] = {
|
|
67
|
+
"settings_file": str(path) if path else None,
|
|
68
|
+
"searched": [FILE_NAME, str(user_config_file())],
|
|
69
|
+
"ignored": ignored,
|
|
70
|
+
"settings": hidden,
|
|
71
|
+
"environment": environment,
|
|
72
|
+
}
|
|
73
|
+
if json_output:
|
|
74
|
+
output.print_json(document)
|
|
75
|
+
return
|
|
76
|
+
output.data(f"settings file: {document['settings_file'] or 'none'}")
|
|
77
|
+
if not path and not ignored:
|
|
78
|
+
output.message(f"Looked for ./{FILE_NAME} and {user_config_file()}")
|
|
79
|
+
for key, value in hidden.items():
|
|
80
|
+
output.data(f" {key} = {value!r}")
|
|
81
|
+
for name, value in environment.items():
|
|
82
|
+
output.data(f"{name}={value}")
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""The ``download`` command: save a stream to a file."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
from rayohx import Downloader, OutputFormat, RemuxBackend, StorageStrategy
|
|
8
|
+
from rayohx.errors import ConfigurationError
|
|
9
|
+
|
|
10
|
+
from rayohx_cli import output, params
|
|
11
|
+
from rayohx_cli.cli.common import (
|
|
12
|
+
EXIT_CANCELLED,
|
|
13
|
+
Source,
|
|
14
|
+
gather_urls,
|
|
15
|
+
make_config,
|
|
16
|
+
open_source,
|
|
17
|
+
usage_error,
|
|
18
|
+
)
|
|
19
|
+
from rayohx_cli.cli.lifecycle import finish, graceful_interrupt, pause_toggle
|
|
20
|
+
from rayohx_cli.cli.root import app
|
|
21
|
+
from rayohx_cli.progress import MODES, make_reporter
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from rayohx.config import DownloadConfig
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@app.command()
|
|
28
|
+
def download(
|
|
29
|
+
urls: params.Urls = None,
|
|
30
|
+
output_path: params.OutputPath = None,
|
|
31
|
+
quality: params.Quality = "best",
|
|
32
|
+
max_resolution: params.MaxResolution = None,
|
|
33
|
+
max_bitrate: params.MaxBitrate = None,
|
|
34
|
+
variant: params.Variant = None,
|
|
35
|
+
resolution: params.Resolution = None,
|
|
36
|
+
bandwidth: params.Bandwidth = None,
|
|
37
|
+
variant_name: params.VariantName = None,
|
|
38
|
+
codec: params.Codec = None,
|
|
39
|
+
video_range: params.VideoRange = None,
|
|
40
|
+
max_frame_rate: params.MaxFrameRate = None,
|
|
41
|
+
audio: params.Audio = None,
|
|
42
|
+
audio_name: params.AudioName = None,
|
|
43
|
+
subtitles: params.Subtitles = None,
|
|
44
|
+
subtitle_name: params.SubtitleName = None,
|
|
45
|
+
video_only: params.VideoOnly = False,
|
|
46
|
+
format_: params.Format = OutputFormat.AUTO,
|
|
47
|
+
overwrite: params.Overwrite = False,
|
|
48
|
+
validate: params.Validate = True,
|
|
49
|
+
remux_backend: params.RemuxBackendOption = RemuxBackend.AUTO,
|
|
50
|
+
ffmpeg: params.Ffmpeg = None,
|
|
51
|
+
header: params.Header = None,
|
|
52
|
+
cookie: params.Cookie = None,
|
|
53
|
+
user_agent: params.UserAgent = None,
|
|
54
|
+
referer: params.Referer = None,
|
|
55
|
+
origin: params.Origin = None,
|
|
56
|
+
proxy: params.Proxy = None,
|
|
57
|
+
proxy_username: params.ProxyUsername = None,
|
|
58
|
+
proxy_password: params.ProxyPassword = None,
|
|
59
|
+
backoff: params.Backoff = None,
|
|
60
|
+
max_redirects: params.MaxRedirects = None,
|
|
61
|
+
cookie_file: params.CookieFile = None,
|
|
62
|
+
insecure: params.Insecure = False,
|
|
63
|
+
ca_bundle: params.CaBundle = None,
|
|
64
|
+
env_proxy: params.EnvProxy = False,
|
|
65
|
+
client_cert: params.ClientCert = None,
|
|
66
|
+
client_key: params.ClientKey = None,
|
|
67
|
+
client_key_password: params.ClientKeyPassword = None,
|
|
68
|
+
connect_timeout: params.ConnectTimeout = None,
|
|
69
|
+
read_timeout: params.ReadTimeout = None,
|
|
70
|
+
timeout: params.Timeout = None,
|
|
71
|
+
retries: params.Retries = None,
|
|
72
|
+
rate_limit: params.RateLimit = None,
|
|
73
|
+
credential_host: params.CredentialHost = None,
|
|
74
|
+
concurrency: params.Concurrency = None,
|
|
75
|
+
resume: params.Resume = True,
|
|
76
|
+
storage: params.Storage = StorageStrategy.AUTO,
|
|
77
|
+
workspace: params.Workspace = None,
|
|
78
|
+
buffer_size: params.BufferSize = None,
|
|
79
|
+
max_temp_size: params.MaxTempSize = None,
|
|
80
|
+
space_check: params.SpaceCheck = True,
|
|
81
|
+
reserve_space: params.ReserveSpace = None,
|
|
82
|
+
keep_state: params.KeepState = True,
|
|
83
|
+
directory: params.Directory = None,
|
|
84
|
+
allow_file_keys: params.AllowFileKeys = False,
|
|
85
|
+
json_output: params.JsonOutput = False,
|
|
86
|
+
progress: params.ProgressMode = "auto",
|
|
87
|
+
input_file: params.InputFile = None,
|
|
88
|
+
playlist_file: params.PlaylistFile = None,
|
|
89
|
+
base_url: params.BaseUrl = None,
|
|
90
|
+
events: params.Events = False,
|
|
91
|
+
stop_on_error: params.StopOnError = False,
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Download one or more streams to files.
|
|
94
|
+
|
|
95
|
+
The path of each saved file is printed on stdout. With several addresses (or --input-file),
|
|
96
|
+
--output names a folder and the files are named after the addresses. Interrupted downloads
|
|
97
|
+
continue where they stopped when you run the same command again. Press Ctrl-C once to stop
|
|
98
|
+
cleanly.
|
|
99
|
+
"""
|
|
100
|
+
if progress not in MODES:
|
|
101
|
+
raise typer.BadParameter(f"must be one of {', '.join(MODES)}.", param_hint="--progress")
|
|
102
|
+
config = make_config(
|
|
103
|
+
quality=quality,
|
|
104
|
+
max_resolution=max_resolution,
|
|
105
|
+
max_bitrate=max_bitrate,
|
|
106
|
+
variant=variant,
|
|
107
|
+
resolution=resolution,
|
|
108
|
+
bandwidth=bandwidth,
|
|
109
|
+
variant_name=variant_name,
|
|
110
|
+
codec=codec,
|
|
111
|
+
video_range=video_range,
|
|
112
|
+
max_frame_rate=max_frame_rate,
|
|
113
|
+
audio=audio or [],
|
|
114
|
+
audio_name=audio_name or [],
|
|
115
|
+
subtitles=subtitles or [],
|
|
116
|
+
subtitle_name=subtitle_name or [],
|
|
117
|
+
video_only=video_only,
|
|
118
|
+
format=format_,
|
|
119
|
+
overwrite=overwrite,
|
|
120
|
+
validate=validate,
|
|
121
|
+
remux_backend=remux_backend,
|
|
122
|
+
ffmpeg=ffmpeg,
|
|
123
|
+
header=header or [],
|
|
124
|
+
cookie=cookie or [],
|
|
125
|
+
user_agent=user_agent,
|
|
126
|
+
referer=referer,
|
|
127
|
+
origin=origin,
|
|
128
|
+
proxy=proxy,
|
|
129
|
+
proxy_username=proxy_username,
|
|
130
|
+
proxy_password=proxy_password,
|
|
131
|
+
backoff=backoff,
|
|
132
|
+
max_redirects=max_redirects,
|
|
133
|
+
cookie_file=cookie_file,
|
|
134
|
+
insecure=insecure,
|
|
135
|
+
ca_bundle=ca_bundle,
|
|
136
|
+
env_proxy=env_proxy,
|
|
137
|
+
client_cert=client_cert,
|
|
138
|
+
client_key=client_key,
|
|
139
|
+
client_key_password=client_key_password,
|
|
140
|
+
connect_timeout=connect_timeout,
|
|
141
|
+
read_timeout=read_timeout,
|
|
142
|
+
timeout=timeout,
|
|
143
|
+
retries=retries,
|
|
144
|
+
rate_limit=rate_limit,
|
|
145
|
+
credential_host=credential_host or [],
|
|
146
|
+
concurrency=concurrency,
|
|
147
|
+
resume=resume,
|
|
148
|
+
storage=storage,
|
|
149
|
+
workspace=workspace,
|
|
150
|
+
buffer_size=buffer_size,
|
|
151
|
+
max_temp_size=max_temp_size,
|
|
152
|
+
space_check=space_check,
|
|
153
|
+
reserve_space=reserve_space,
|
|
154
|
+
keep_state=keep_state,
|
|
155
|
+
directory=directory,
|
|
156
|
+
allow_file_keys=allow_file_keys,
|
|
157
|
+
)
|
|
158
|
+
targets = gather_urls(urls or [], input_file)
|
|
159
|
+
if playlist_file is not None and len(targets) > 1:
|
|
160
|
+
usage_error(
|
|
161
|
+
ConfigurationError(
|
|
162
|
+
"--playlist-file works with one address.",
|
|
163
|
+
hint="Give the address the playlist came from, and nothing else.",
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
sources = [open_source(t, base_url, playlist_file) for t in targets]
|
|
167
|
+
if events:
|
|
168
|
+
progress = "none"
|
|
169
|
+
if directory is not None:
|
|
170
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
171
|
+
if len(targets) > 1 and output_path is None:
|
|
172
|
+
output_path = directory
|
|
173
|
+
if len(targets) == 1:
|
|
174
|
+
run_one(sources[0], output_path, config, progress, json_output, events=events)
|
|
175
|
+
return
|
|
176
|
+
run_many(sources, output_path, config, progress, json_output, stop_on_error, events)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def run_one(
|
|
180
|
+
source: Source,
|
|
181
|
+
output_path: Path | None,
|
|
182
|
+
config: "DownloadConfig",
|
|
183
|
+
progress: str,
|
|
184
|
+
json_output: bool,
|
|
185
|
+
documents: list[dict[str, object]] | None = None,
|
|
186
|
+
downloader: Downloader | None = None,
|
|
187
|
+
events: bool = False,
|
|
188
|
+
) -> None:
|
|
189
|
+
"""Download one address with a progress display, then report how it ended."""
|
|
190
|
+
try:
|
|
191
|
+
downloader = downloader or Downloader(
|
|
192
|
+
source.url, output=output_path, config=config, playlist_text=source.text
|
|
193
|
+
)
|
|
194
|
+
except ConfigurationError as exc:
|
|
195
|
+
usage_error(exc)
|
|
196
|
+
reporter = make_reporter(
|
|
197
|
+
progress,
|
|
198
|
+
output.err_console,
|
|
199
|
+
quiet=output.settings.quiet,
|
|
200
|
+
json_output=json_output,
|
|
201
|
+
verbose=output.settings.verbose,
|
|
202
|
+
)
|
|
203
|
+
downloader.events.subscribe(reporter)
|
|
204
|
+
if events:
|
|
205
|
+
from rayohx_cli.events import EventStream
|
|
206
|
+
|
|
207
|
+
downloader.events.subscribe(EventStream())
|
|
208
|
+
reporter.start()
|
|
209
|
+
try:
|
|
210
|
+
with graceful_interrupt(downloader), pause_toggle(downloader):
|
|
211
|
+
result = downloader.run()
|
|
212
|
+
finally:
|
|
213
|
+
reporter.close()
|
|
214
|
+
finish(result, downloader, json_output=json_output, documents=documents)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def run_many(
|
|
218
|
+
targets: list[Source],
|
|
219
|
+
output_path: Path | None,
|
|
220
|
+
config: "DownloadConfig",
|
|
221
|
+
progress: str,
|
|
222
|
+
json_output: bool,
|
|
223
|
+
stop_on_error: bool,
|
|
224
|
+
events: bool = False,
|
|
225
|
+
) -> None:
|
|
226
|
+
"""Download several addresses in turn into one folder."""
|
|
227
|
+
from rayohx import batch_outputs
|
|
228
|
+
|
|
229
|
+
if output_path is not None and output_path.exists() and not output_path.is_dir():
|
|
230
|
+
usage_error(
|
|
231
|
+
ConfigurationError(
|
|
232
|
+
f"{output_path} is a file, but there are {len(targets)} addresses to download.",
|
|
233
|
+
hint="With several addresses, --output names a folder.",
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
paths = batch_outputs([source.url for source in targets], output_path)
|
|
237
|
+
# Check every address and setting before anything is downloaded.
|
|
238
|
+
try:
|
|
239
|
+
downloaders = [
|
|
240
|
+
Downloader(s.url, output=p, config=config, playlist_text=s.text)
|
|
241
|
+
for s, p in zip(targets, paths, strict=True)
|
|
242
|
+
]
|
|
243
|
+
except ConfigurationError as exc:
|
|
244
|
+
usage_error(exc)
|
|
245
|
+
if output_path is not None:
|
|
246
|
+
output_path.mkdir(parents=True, exist_ok=True)
|
|
247
|
+
documents: list[dict[str, object]] = []
|
|
248
|
+
code = 0
|
|
249
|
+
for position, (source, downloader) in enumerate(
|
|
250
|
+
zip(targets, downloaders, strict=True), start=1
|
|
251
|
+
):
|
|
252
|
+
output.message(f"[{position}/{len(targets)}] {source.label}")
|
|
253
|
+
try:
|
|
254
|
+
run_one(source, None, config, progress, json_output, documents, downloader, events)
|
|
255
|
+
except typer.Exit as exit_:
|
|
256
|
+
code = EXIT_CANCELLED if exit_.exit_code == EXIT_CANCELLED else code or exit_.exit_code
|
|
257
|
+
if exit_.exit_code == EXIT_CANCELLED or stop_on_error:
|
|
258
|
+
break
|
|
259
|
+
if json_output:
|
|
260
|
+
output.print_json(documents)
|
|
261
|
+
if code:
|
|
262
|
+
raise typer.Exit(code)
|
rayohx_cli/cli/info.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""The ``info`` command: show what a stream offers without downloading it."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
from rayohx import MasterPlaylist, inspect, inspect_text, playlist_to_dict, select_stream
|
|
5
|
+
from rayohx.errors import ConfigurationError, RayoHXError
|
|
6
|
+
|
|
7
|
+
from rayohx_cli import output, params, render
|
|
8
|
+
from rayohx_cli.cli.common import EXIT_FAILED, make_config, open_source, usage_error
|
|
9
|
+
from rayohx_cli.cli.root import app
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@app.command()
|
|
13
|
+
def info(
|
|
14
|
+
url: params.Url,
|
|
15
|
+
playlist_file: params.PlaylistFile = None,
|
|
16
|
+
base_url: params.BaseUrl = None,
|
|
17
|
+
quality: params.Quality = "best",
|
|
18
|
+
max_resolution: params.MaxResolution = None,
|
|
19
|
+
max_bitrate: params.MaxBitrate = None,
|
|
20
|
+
variant: params.Variant = None,
|
|
21
|
+
resolution: params.Resolution = None,
|
|
22
|
+
bandwidth: params.Bandwidth = None,
|
|
23
|
+
variant_name: params.VariantName = None,
|
|
24
|
+
codec: params.Codec = None,
|
|
25
|
+
video_range: params.VideoRange = None,
|
|
26
|
+
max_frame_rate: params.MaxFrameRate = None,
|
|
27
|
+
audio: params.Audio = None,
|
|
28
|
+
audio_name: params.AudioName = None,
|
|
29
|
+
subtitles: params.Subtitles = None,
|
|
30
|
+
subtitle_name: params.SubtitleName = None,
|
|
31
|
+
video_only: params.VideoOnly = False,
|
|
32
|
+
header: params.Header = None,
|
|
33
|
+
cookie: params.Cookie = None,
|
|
34
|
+
user_agent: params.UserAgent = None,
|
|
35
|
+
referer: params.Referer = None,
|
|
36
|
+
origin: params.Origin = None,
|
|
37
|
+
proxy: params.Proxy = None,
|
|
38
|
+
proxy_username: params.ProxyUsername = None,
|
|
39
|
+
proxy_password: params.ProxyPassword = None,
|
|
40
|
+
backoff: params.Backoff = None,
|
|
41
|
+
max_redirects: params.MaxRedirects = None,
|
|
42
|
+
cookie_file: params.CookieFile = None,
|
|
43
|
+
insecure: params.Insecure = False,
|
|
44
|
+
ca_bundle: params.CaBundle = None,
|
|
45
|
+
env_proxy: params.EnvProxy = False,
|
|
46
|
+
client_cert: params.ClientCert = None,
|
|
47
|
+
client_key: params.ClientKey = None,
|
|
48
|
+
client_key_password: params.ClientKeyPassword = None,
|
|
49
|
+
connect_timeout: params.ConnectTimeout = None,
|
|
50
|
+
read_timeout: params.ReadTimeout = None,
|
|
51
|
+
timeout: params.Timeout = None,
|
|
52
|
+
retries: params.Retries = None,
|
|
53
|
+
credential_host: params.CredentialHost = None,
|
|
54
|
+
json_output: params.JsonOutput = False,
|
|
55
|
+
) -> None:
|
|
56
|
+
"""Show what a stream offers, without downloading it.
|
|
57
|
+
|
|
58
|
+
Lists the streams (size, bit rate, codecs), the audio and subtitle tracks, and which of them
|
|
59
|
+
a download with the same options would pick (marked with *).
|
|
60
|
+
"""
|
|
61
|
+
config = make_config(
|
|
62
|
+
quality=quality,
|
|
63
|
+
max_resolution=max_resolution,
|
|
64
|
+
max_bitrate=max_bitrate,
|
|
65
|
+
variant=variant,
|
|
66
|
+
resolution=resolution,
|
|
67
|
+
bandwidth=bandwidth,
|
|
68
|
+
variant_name=variant_name,
|
|
69
|
+
codec=codec,
|
|
70
|
+
video_range=video_range,
|
|
71
|
+
max_frame_rate=max_frame_rate,
|
|
72
|
+
audio=audio or [],
|
|
73
|
+
audio_name=audio_name or [],
|
|
74
|
+
subtitles=subtitles or [],
|
|
75
|
+
subtitle_name=subtitle_name or [],
|
|
76
|
+
video_only=video_only,
|
|
77
|
+
header=header or [],
|
|
78
|
+
cookie=cookie or [],
|
|
79
|
+
user_agent=user_agent,
|
|
80
|
+
referer=referer,
|
|
81
|
+
origin=origin,
|
|
82
|
+
proxy=proxy,
|
|
83
|
+
proxy_username=proxy_username,
|
|
84
|
+
proxy_password=proxy_password,
|
|
85
|
+
backoff=backoff,
|
|
86
|
+
max_redirects=max_redirects,
|
|
87
|
+
cookie_file=cookie_file,
|
|
88
|
+
insecure=insecure,
|
|
89
|
+
ca_bundle=ca_bundle,
|
|
90
|
+
env_proxy=env_proxy,
|
|
91
|
+
client_cert=client_cert,
|
|
92
|
+
client_key=client_key,
|
|
93
|
+
client_key_password=client_key_password,
|
|
94
|
+
connect_timeout=connect_timeout,
|
|
95
|
+
read_timeout=read_timeout,
|
|
96
|
+
timeout=timeout,
|
|
97
|
+
retries=retries,
|
|
98
|
+
credential_host=credential_host or [],
|
|
99
|
+
)
|
|
100
|
+
try:
|
|
101
|
+
source = open_source(url, base_url, playlist_file)
|
|
102
|
+
playlist = (
|
|
103
|
+
inspect(source.url, config.network)
|
|
104
|
+
if source.text is None
|
|
105
|
+
else inspect_text(source.text, source.url)
|
|
106
|
+
)
|
|
107
|
+
selection = (
|
|
108
|
+
select_stream(playlist, config.selection)
|
|
109
|
+
if isinstance(playlist, MasterPlaylist)
|
|
110
|
+
else None
|
|
111
|
+
)
|
|
112
|
+
except ConfigurationError as exc:
|
|
113
|
+
usage_error(exc)
|
|
114
|
+
except RayoHXError as exc:
|
|
115
|
+
output.error_from(exc)
|
|
116
|
+
raise typer.Exit(EXIT_FAILED) from exc
|
|
117
|
+
data = playlist_to_dict(playlist, selection)
|
|
118
|
+
if json_output:
|
|
119
|
+
output.print_json(data)
|
|
120
|
+
else:
|
|
121
|
+
render.show(data)
|