carrot-leaf 0.1.0__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.
Files changed (29) hide show
  1. carrot_leaf-0.1.0/LICENSE +21 -0
  2. carrot_leaf-0.1.0/PKG-INFO +155 -0
  3. carrot_leaf-0.1.0/README.md +129 -0
  4. carrot_leaf-0.1.0/pyproject.toml +74 -0
  5. carrot_leaf-0.1.0/pyproject.toml.orig +59 -0
  6. carrot_leaf-0.1.0/src/carrot_leaf/__init__.py +8 -0
  7. carrot_leaf-0.1.0/src/carrot_leaf/__main__.py +5 -0
  8. carrot_leaf-0.1.0/src/carrot_leaf/app.py +35 -0
  9. carrot_leaf-0.1.0/src/carrot_leaf/cli.py +55 -0
  10. carrot_leaf-0.1.0/src/carrot_leaf/config.py +62 -0
  11. carrot_leaf-0.1.0/src/carrot_leaf/engine/__init__.py +0 -0
  12. carrot_leaf-0.1.0/src/carrot_leaf/engine/deps.py +97 -0
  13. carrot_leaf-0.1.0/src/carrot_leaf/engine/errors.py +116 -0
  14. carrot_leaf-0.1.0/src/carrot_leaf/engine/options.py +157 -0
  15. carrot_leaf-0.1.0/src/carrot_leaf/engine/probe.py +118 -0
  16. carrot_leaf-0.1.0/src/carrot_leaf/engine/runner.py +148 -0
  17. carrot_leaf-0.1.0/src/carrot_leaf/engine/update.py +69 -0
  18. carrot_leaf-0.1.0/src/carrot_leaf/logo.py +69 -0
  19. carrot_leaf-0.1.0/src/carrot_leaf/py.typed +0 -0
  20. carrot_leaf-0.1.0/src/carrot_leaf/screens/__init__.py +0 -0
  21. carrot_leaf-0.1.0/src/carrot_leaf/screens/convert.py +158 -0
  22. carrot_leaf-0.1.0/src/carrot_leaf/screens/main.py +369 -0
  23. carrot_leaf-0.1.0/src/carrot_leaf/screens/settings.py +145 -0
  24. carrot_leaf-0.1.0/src/carrot_leaf/styles.tcss +316 -0
  25. carrot_leaf-0.1.0/src/carrot_leaf/theme.py +35 -0
  26. carrot_leaf-0.1.0/src/carrot_leaf/widgets/__init__.py +0 -0
  27. carrot_leaf-0.1.0/src/carrot_leaf/widgets/queue.py +120 -0
  28. carrot_leaf-0.1.0/src/carrot_leaf/widgets/thumbnail.py +58 -0
  29. carrot_leaf-0.1.0/src/carrot_leaf/widgets/video_card.py +90 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yore Des
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: carrot-leaf
3
+ Version: 0.1.0
4
+ Summary: A good-looking terminal app for downloading and converting YouTube (and 1000+ other sites) videos, powered by yt-dlp.
5
+ Keywords: youtube,yt-dlp,downloader,tui,terminal,converter,mp3
6
+ Author: Yore Des
7
+ Author-email: Yore Des <designsbyyore@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Environment :: Console
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Multimedia :: Video
14
+ Requires-Dist: yt-dlp[default]>=2026.8.19
15
+ Requires-Dist: textual>=8.2
16
+ Requires-Dist: pillow>=10
17
+ Requires-Dist: platformdirs>=4
18
+ Requires-Dist: tomli-w>=1.0
19
+ Requires-Dist: tomli>=2.0 ; python_full_version < '3.11'
20
+ Requires-Dist: static-ffmpeg>=3.0
21
+ Requires-Dist: deno>=2.0
22
+ Requires-Python: >=3.10
23
+ Project-URL: Homepage, https://github.com/Yore-Des/carrot-leaf
24
+ Project-URL: Issues, https://github.com/Yore-Des/carrot-leaf/issues
25
+ Description-Content-Type: text/markdown
26
+
27
+ <pre>
28
+ \ | / ██████╗ █████╗ ██████╗ ██████╗ ██████╗ ████████╗ ██╗ ███████╗ █████╗ ███████╗
29
+ \|/ ██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔═══██╗╚══██╔══╝ ██║ ██╔════╝██╔══██╗██╔════╝
30
+ ▐█████▌ ██║ ███████║██████╔╝██████╔╝██║ ██║ ██║ ██║ █████╗ ███████║█████╗
31
+ ▐███▌ ██║ ██╔══██║██╔══██╗██╔══██╗██║ ██║ ██║ ██║ ██╔══╝ ██╔══██║██╔══╝
32
+ ▐█▌ ╚██████╗██║ ██║██║ ██║██║ ██║╚██████╔╝ ██║ ███████╗███████╗██║ ██║██║
33
+ ▀ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝
34
+ </pre>
35
+
36
+ A good-looking terminal app for downloading and converting videos from YouTube and
37
+ 1,000+ other sites. Paste a link, then **Download** or **Convert**. Built on
38
+ [yt-dlp](https://github.com/yt-dlp/yt-dlp) and [Textual](https://textual.textualize.io/).
39
+
40
+ ## Install
41
+
42
+ **macOS / Linux**
43
+
44
+ ```sh
45
+ curl -LsSf https://raw.githubusercontent.com/Yore-Des/carrot-leaf/main/install.sh | sh
46
+ ```
47
+
48
+ **Windows** (PowerShell)
49
+
50
+ ```powershell
51
+ powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/Yore-Des/carrot-leaf/main/install.ps1 | iex"
52
+ ```
53
+
54
+ The script installs [uv](https://docs.astral.sh/uv/) if you don't have it, then installs
55
+ Carrot Leaf with its own Python. Your system Python doesn't matter, and you don't need to
56
+ install ffmpeg or anything else.
57
+
58
+ Already use uv or pipx?
59
+
60
+ ```sh
61
+ uv tool install carrot-leaf
62
+ pipx install carrot-leaf # needs Python 3.10+
63
+ ```
64
+
65
+ ## Use it
66
+
67
+ ```sh
68
+ carrot # open the app
69
+ carrot <url> # open with a link already loaded
70
+ carrot update # update yt-dlp
71
+ carrot --version
72
+ ```
73
+
74
+ Paste a link anywhere in the app. The video's details and thumbnail show up, then:
75
+
76
+ | Key | Does |
77
+ | ----- | ------------------------------------------------------- |
78
+ | `d` | **Download**: best quality, saved as MP4 |
79
+ | `c` | **Convert**: pick a video or audio format and a quality |
80
+ | `s` | Settings: download folder, browser cookies |
81
+ | `o` | Show the last downloaded file in Finder / Explorer |
82
+ | `u` | Update yt-dlp |
83
+ | `esc` | Back to the URL bar |
84
+ | `q` | Quit |
85
+
86
+ You can paste another link while a download is running. Jobs wait in line and run one
87
+ at a time.
88
+
89
+ ### Formats
90
+
91
+ | Video | Audio |
92
+ | ------------------------- | ---------------------------------- |
93
+ | MP4, MKV, WebM, MOV, GIF | MP3, M4A, Opus, FLAC, WAV, OGG |
94
+ | best, 2160p … 360p | best, 320 / 192 / 128 kbps |
95
+
96
+ Carrot Leaf only offers resolutions the video actually has. Files get the title, artist
97
+ and cover art embedded where the format supports it.
98
+
99
+ ### Where files go
100
+
101
+ Files are saved to your Downloads folder as `Title [video-id].ext`. Change the folder with
102
+ `s`. If a file with the same name exists, the new one is saved as `Title [id] (2).ext`.
103
+
104
+ Settings are stored in:
105
+
106
+ - macOS: `~/Library/Application Support/carrot-leaf/config.toml`
107
+ - Linux: `~/.config/carrot-leaf/config.toml`
108
+ - Windows: `%LOCALAPPDATA%\carrot-leaf\config.toml`
109
+
110
+ ### Age-restricted and members-only videos
111
+
112
+ These need you to be signed in. When Carrot Leaf hits one, it offers to use the cookies
113
+ from a browser where you're signed in (Chrome, Firefox, Safari, Edge, Brave, …). This is
114
+ off until you pick a browser, and you can turn it off again in Settings. On a Mac you may
115
+ see a Keychain prompt the first time.
116
+
117
+ ### When downloads break
118
+
119
+ Sites change often, and YouTube most of all, so yt-dlp ships fixes every few weeks.
120
+ Carrot Leaf checks for a new yt-dlp when it starts and shows a notice if one is out.
121
+ Press `u` or run `carrot update`.
122
+
123
+ ### ffmpeg and Deno
124
+
125
+ Converting needs ffmpeg, and YouTube needs a JavaScript runtime (Deno). If they're
126
+ already installed, Carrot Leaf uses them. If not, it uses bundled copies: Deno comes with
127
+ the package, and ffmpeg is downloaded once (about 70 MB) the first time it's needed.
128
+
129
+ ## Uninstall
130
+
131
+ ```sh
132
+ uv tool uninstall carrot-leaf
133
+ ```
134
+
135
+ ## Development
136
+
137
+ ```sh
138
+ git clone https://github.com/Yore-Des/carrot-leaf && cd carrot-leaf
139
+ uv sync
140
+ uv run carrot
141
+ uv run pytest # offline tests
142
+ CARROT_LIVE=1 uv run pytest # also run real downloads
143
+ uv run ruff check src tests && uv run ruff format src tests
144
+ ```
145
+
146
+ Releases: bump `version` in `pyproject.toml`, then push a `vX.Y.Z` tag. GitHub Actions
147
+ publishes to PyPI.
148
+
149
+ ## Please be nice
150
+
151
+ Only download videos you have the right to download, and respect each site's terms.
152
+
153
+ ## License
154
+
155
+ MIT
@@ -0,0 +1,129 @@
1
+ <pre>
2
+ \ | / ██████╗ █████╗ ██████╗ ██████╗ ██████╗ ████████╗ ██╗ ███████╗ █████╗ ███████╗
3
+ \|/ ██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔═══██╗╚══██╔══╝ ██║ ██╔════╝██╔══██╗██╔════╝
4
+ ▐█████▌ ██║ ███████║██████╔╝██████╔╝██║ ██║ ██║ ██║ █████╗ ███████║█████╗
5
+ ▐███▌ ██║ ██╔══██║██╔══██╗██╔══██╗██║ ██║ ██║ ██║ ██╔══╝ ██╔══██║██╔══╝
6
+ ▐█▌ ╚██████╗██║ ██║██║ ██║██║ ██║╚██████╔╝ ██║ ███████╗███████╗██║ ██║██║
7
+ ▀ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝
8
+ </pre>
9
+
10
+ A good-looking terminal app for downloading and converting videos from YouTube and
11
+ 1,000+ other sites. Paste a link, then **Download** or **Convert**. Built on
12
+ [yt-dlp](https://github.com/yt-dlp/yt-dlp) and [Textual](https://textual.textualize.io/).
13
+
14
+ ## Install
15
+
16
+ **macOS / Linux**
17
+
18
+ ```sh
19
+ curl -LsSf https://raw.githubusercontent.com/Yore-Des/carrot-leaf/main/install.sh | sh
20
+ ```
21
+
22
+ **Windows** (PowerShell)
23
+
24
+ ```powershell
25
+ powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/Yore-Des/carrot-leaf/main/install.ps1 | iex"
26
+ ```
27
+
28
+ The script installs [uv](https://docs.astral.sh/uv/) if you don't have it, then installs
29
+ Carrot Leaf with its own Python. Your system Python doesn't matter, and you don't need to
30
+ install ffmpeg or anything else.
31
+
32
+ Already use uv or pipx?
33
+
34
+ ```sh
35
+ uv tool install carrot-leaf
36
+ pipx install carrot-leaf # needs Python 3.10+
37
+ ```
38
+
39
+ ## Use it
40
+
41
+ ```sh
42
+ carrot # open the app
43
+ carrot <url> # open with a link already loaded
44
+ carrot update # update yt-dlp
45
+ carrot --version
46
+ ```
47
+
48
+ Paste a link anywhere in the app. The video's details and thumbnail show up, then:
49
+
50
+ | Key | Does |
51
+ | ----- | ------------------------------------------------------- |
52
+ | `d` | **Download**: best quality, saved as MP4 |
53
+ | `c` | **Convert**: pick a video or audio format and a quality |
54
+ | `s` | Settings: download folder, browser cookies |
55
+ | `o` | Show the last downloaded file in Finder / Explorer |
56
+ | `u` | Update yt-dlp |
57
+ | `esc` | Back to the URL bar |
58
+ | `q` | Quit |
59
+
60
+ You can paste another link while a download is running. Jobs wait in line and run one
61
+ at a time.
62
+
63
+ ### Formats
64
+
65
+ | Video | Audio |
66
+ | ------------------------- | ---------------------------------- |
67
+ | MP4, MKV, WebM, MOV, GIF | MP3, M4A, Opus, FLAC, WAV, OGG |
68
+ | best, 2160p … 360p | best, 320 / 192 / 128 kbps |
69
+
70
+ Carrot Leaf only offers resolutions the video actually has. Files get the title, artist
71
+ and cover art embedded where the format supports it.
72
+
73
+ ### Where files go
74
+
75
+ Files are saved to your Downloads folder as `Title [video-id].ext`. Change the folder with
76
+ `s`. If a file with the same name exists, the new one is saved as `Title [id] (2).ext`.
77
+
78
+ Settings are stored in:
79
+
80
+ - macOS: `~/Library/Application Support/carrot-leaf/config.toml`
81
+ - Linux: `~/.config/carrot-leaf/config.toml`
82
+ - Windows: `%LOCALAPPDATA%\carrot-leaf\config.toml`
83
+
84
+ ### Age-restricted and members-only videos
85
+
86
+ These need you to be signed in. When Carrot Leaf hits one, it offers to use the cookies
87
+ from a browser where you're signed in (Chrome, Firefox, Safari, Edge, Brave, …). This is
88
+ off until you pick a browser, and you can turn it off again in Settings. On a Mac you may
89
+ see a Keychain prompt the first time.
90
+
91
+ ### When downloads break
92
+
93
+ Sites change often, and YouTube most of all, so yt-dlp ships fixes every few weeks.
94
+ Carrot Leaf checks for a new yt-dlp when it starts and shows a notice if one is out.
95
+ Press `u` or run `carrot update`.
96
+
97
+ ### ffmpeg and Deno
98
+
99
+ Converting needs ffmpeg, and YouTube needs a JavaScript runtime (Deno). If they're
100
+ already installed, Carrot Leaf uses them. If not, it uses bundled copies: Deno comes with
101
+ the package, and ffmpeg is downloaded once (about 70 MB) the first time it's needed.
102
+
103
+ ## Uninstall
104
+
105
+ ```sh
106
+ uv tool uninstall carrot-leaf
107
+ ```
108
+
109
+ ## Development
110
+
111
+ ```sh
112
+ git clone https://github.com/Yore-Des/carrot-leaf && cd carrot-leaf
113
+ uv sync
114
+ uv run carrot
115
+ uv run pytest # offline tests
116
+ CARROT_LIVE=1 uv run pytest # also run real downloads
117
+ uv run ruff check src tests && uv run ruff format src tests
118
+ ```
119
+
120
+ Releases: bump `version` in `pyproject.toml`, then push a `vX.Y.Z` tag. GitHub Actions
121
+ publishes to PyPI.
122
+
123
+ ## Please be nice
124
+
125
+ Only download videos you have the right to download, and respect each site's terms.
126
+
127
+ ## License
128
+
129
+ MIT
@@ -0,0 +1,74 @@
1
+ [project]
2
+ name = "carrot-leaf"
3
+ version = "0.1.0"
4
+ description = "A good-looking terminal app for downloading and converting YouTube (and 1000+ other sites) videos, powered by yt-dlp."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.10"
9
+ keywords = [
10
+ "youtube",
11
+ "yt-dlp",
12
+ "downloader",
13
+ "tui",
14
+ "terminal",
15
+ "converter",
16
+ "mp3",
17
+ ]
18
+ classifiers = [
19
+ "Environment :: Console",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Topic :: Multimedia :: Video",
23
+ ]
24
+ dependencies = [
25
+ "yt-dlp[default]>=2026.8.19",
26
+ "textual>=8.2",
27
+ "pillow>=10",
28
+ "platformdirs>=4",
29
+ "tomli-w>=1.0",
30
+ "tomli>=2.0; python_version < '3.11'",
31
+ "static-ffmpeg>=3.0",
32
+ "deno>=2.0",
33
+ ]
34
+
35
+ [[project.authors]]
36
+ name = "Yore Des"
37
+ email = "designsbyyore@gmail.com"
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/Yore-Des/carrot-leaf"
41
+ Issues = "https://github.com/Yore-Des/carrot-leaf/issues"
42
+
43
+ [project.scripts]
44
+ carrot = "carrot_leaf.cli:main"
45
+ carrot-leaf = "carrot_leaf.cli:main"
46
+
47
+ [dependency-groups]
48
+ dev = [
49
+ "pytest>=8",
50
+ "pytest-asyncio>=0.24",
51
+ "ruff>=0.6",
52
+ ]
53
+
54
+ [build-system]
55
+ requires = ["uv_build>=0.11.23,<0.12.0"]
56
+ build-backend = "uv_build"
57
+
58
+ [tool.ruff]
59
+ line-length = 100
60
+ target-version = "py310"
61
+
62
+ [tool.ruff.lint]
63
+ select = [
64
+ "E",
65
+ "F",
66
+ "I",
67
+ "B",
68
+ "UP",
69
+ ]
70
+ ignore = ["E501"]
71
+
72
+ [tool.pytest.ini_options]
73
+ asyncio_mode = "auto"
74
+ testpaths = ["tests"]
@@ -0,0 +1,59 @@
1
+ [project]
2
+ name = "carrot-leaf"
3
+ version = "0.1.0"
4
+ description = "A good-looking terminal app for downloading and converting YouTube (and 1000+ other sites) videos, powered by yt-dlp."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "Yore Des", email = "designsbyyore@gmail.com" }
10
+ ]
11
+ requires-python = ">=3.10"
12
+ keywords = ["youtube", "yt-dlp", "downloader", "tui", "terminal", "converter", "mp3"]
13
+ classifiers = [
14
+ "Environment :: Console",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Topic :: Multimedia :: Video",
18
+ ]
19
+ dependencies = [
20
+ "yt-dlp[default]>=2026.8.19",
21
+ "textual>=8.2",
22
+ "pillow>=10",
23
+ "platformdirs>=4",
24
+ "tomli-w>=1.0",
25
+ "tomli>=2.0; python_version < '3.11'",
26
+ "static-ffmpeg>=3.0",
27
+ "deno>=2.0",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/Yore-Des/carrot-leaf"
32
+ Issues = "https://github.com/Yore-Des/carrot-leaf/issues"
33
+
34
+ [project.scripts]
35
+ carrot = "carrot_leaf.cli:main"
36
+ carrot-leaf = "carrot_leaf.cli:main"
37
+
38
+ [dependency-groups]
39
+ dev = [
40
+ "pytest>=8",
41
+ "pytest-asyncio>=0.24",
42
+ "ruff>=0.6",
43
+ ]
44
+
45
+ [build-system]
46
+ requires = ["uv_build>=0.11.23,<0.12.0"]
47
+ build-backend = "uv_build"
48
+
49
+ [tool.ruff]
50
+ line-length = 100
51
+ target-version = "py310"
52
+
53
+ [tool.ruff.lint]
54
+ select = ["E", "F", "I", "B", "UP"]
55
+ ignore = ["E501"]
56
+
57
+ [tool.pytest.ini_options]
58
+ asyncio_mode = "auto"
59
+ testpaths = ["tests"]
@@ -0,0 +1,8 @@
1
+ """Carrot Leaf: a terminal video downloader and converter built on yt-dlp."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ try:
6
+ __version__ = version("carrot-leaf")
7
+ except PackageNotFoundError: # pragma: no cover - running from a source tree
8
+ __version__ = "0.0.0"
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,35 @@
1
+ """The Textual application."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from textual.app import App
6
+
7
+ from . import config
8
+ from .screens.main import MainScreen
9
+ from .theme import THEMES
10
+
11
+
12
+ class CarrotLeafApp(App):
13
+ CSS_PATH = "styles.tcss"
14
+ TITLE = "Carrot Leaf"
15
+ ENABLE_COMMAND_PALETTE = True
16
+
17
+ def __init__(self, initial_url: str = "") -> None:
18
+ super().__init__()
19
+ self.initial_url = initial_url
20
+ self.settings = config.load()
21
+
22
+ def on_mount(self) -> None:
23
+ for theme in THEMES:
24
+ self.register_theme(theme)
25
+ self.theme = "carrot"
26
+
27
+ def get_default_screen(self) -> MainScreen:
28
+ return MainScreen(self.initial_url)
29
+
30
+ def save_settings(self, settings: config.Settings) -> None:
31
+ self.settings = settings
32
+ try:
33
+ config.save(settings)
34
+ except OSError as exc:
35
+ self.notify(f"Couldn't save settings: {exc}", severity="error")
@@ -0,0 +1,55 @@
1
+ """Command-line entry point: `carrot [URL]`, `carrot update`, `carrot --version`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import sys
7
+
8
+ from . import __version__
9
+
10
+
11
+ def main(argv: list[str] | None = None) -> int:
12
+ argv = sys.argv[1:] if argv is None else argv
13
+ if argv[:1] == ["update"]:
14
+ return _update()
15
+
16
+ parser = argparse.ArgumentParser(
17
+ prog="carrot",
18
+ description="Download or convert videos from YouTube and 1,000+ other sites.",
19
+ epilog="Run `carrot update` to update yt-dlp.",
20
+ )
21
+ parser.add_argument("url", nargs="?", default="", help="video link to open straight away")
22
+ parser.add_argument("--version", action="version", version=_version_text())
23
+ args = parser.parse_args(argv)
24
+
25
+ from .app import CarrotLeafApp
26
+
27
+ CarrotLeafApp(initial_url=args.url).run()
28
+ return 0
29
+
30
+
31
+ def _version_text() -> str:
32
+ from .engine.update import installed_version
33
+
34
+ return f"carrot-leaf {__version__} (yt-dlp {installed_version()})"
35
+
36
+
37
+ def _update() -> int:
38
+ from .engine import update
39
+
40
+ current = update.installed_version()
41
+ latest = update.latest_version()
42
+ if latest and update._key(latest) <= update._key(current):
43
+ print(f"yt-dlp {current} is already the latest version.")
44
+ return 0
45
+ print(f"Updating yt-dlp {current} → {latest or 'latest'}…")
46
+ print("$ " + " ".join(update.upgrade_command()))
47
+ ok, output = update.upgrade()
48
+ if output:
49
+ print(output)
50
+ print("Done." if ok else "Update failed.")
51
+ return 0 if ok else 1
52
+
53
+
54
+ if __name__ == "__main__":
55
+ sys.exit(main())
@@ -0,0 +1,62 @@
1
+ """User settings, stored as TOML in the platform config directory."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from dataclasses import asdict, dataclass, fields
7
+ from pathlib import Path
8
+
9
+ import platformdirs
10
+ import tomli_w
11
+
12
+ if sys.version_info >= (3, 11):
13
+ import tomllib
14
+ else: # pragma: no cover
15
+ import tomli as tomllib
16
+
17
+ APP_NAME = "carrot-leaf"
18
+
19
+
20
+ def default_download_dir() -> str:
21
+ return str(Path(platformdirs.user_downloads_dir()))
22
+
23
+
24
+ def config_path() -> Path:
25
+ return Path(platformdirs.user_config_dir(APP_NAME, appauthor=False)) / "config.toml"
26
+
27
+
28
+ @dataclass
29
+ class Settings:
30
+ download_dir: str = ""
31
+ # Last choice made in the Convert dialog, so it opens where the user left it.
32
+ last_kind: str = "video"
33
+ last_video_format: str = "mp4"
34
+ last_video_quality: str = "best"
35
+ last_audio_format: str = "mp3"
36
+ last_audio_quality: str = "best"
37
+ # Browser cookies stay off until the user opts in for a login-only video.
38
+ cookies_browser: str = ""
39
+
40
+ def __post_init__(self) -> None:
41
+ if not self.download_dir:
42
+ self.download_dir = default_download_dir()
43
+
44
+ @property
45
+ def download_path(self) -> Path:
46
+ return Path(self.download_dir).expanduser()
47
+
48
+
49
+ def load(path: Path | None = None) -> Settings:
50
+ path = path or config_path()
51
+ try:
52
+ data = tomllib.loads(path.read_text(encoding="utf-8"))
53
+ except (OSError, tomllib.TOMLDecodeError):
54
+ return Settings()
55
+ known = {f.name for f in fields(Settings)}
56
+ return Settings(**{k: v for k, v in data.items() if k in known and isinstance(v, str)})
57
+
58
+
59
+ def save(settings: Settings, path: Path | None = None) -> None:
60
+ path = path or config_path()
61
+ path.parent.mkdir(parents=True, exist_ok=True)
62
+ path.write_text(tomli_w.dumps(asdict(settings)), encoding="utf-8")
File without changes