cubctl 1.0.0__tar.gz → 2.0.2__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 (85) hide show
  1. cubctl-2.0.2/PKG-INFO +258 -0
  2. cubctl-2.0.2/README.md +220 -0
  3. {cubctl-1.0.0 → cubctl-2.0.2}/pyproject.toml +15 -3
  4. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl/__init__.py +1 -1
  5. cubctl-2.0.2/src/cubctl/api_spec.json +5855 -0
  6. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl/auth.py +12 -4
  7. cubctl-2.0.2/src/cubctl/cli/__init__.py +53 -0
  8. cubctl-2.0.2/src/cubctl/cli/commands/__init__.py +1 -0
  9. cubctl-2.0.2/src/cubctl/cli/commands/_migration_common.py +30 -0
  10. cubctl-2.0.2/src/cubctl/cli/commands/accounts.py +154 -0
  11. cubctl-2.0.2/src/cubctl/cli/commands/backup.py +105 -0
  12. cubctl-2.0.2/src/cubctl/cli/commands/bookmarks.py +65 -0
  13. cubctl-2.0.2/src/cubctl/cli/commands/card.py +43 -0
  14. cubctl-2.0.2/src/cubctl/cli/commands/collections.py +82 -0
  15. cubctl-2.0.2/src/cubctl/cli/commands/config_cmd.py +137 -0
  16. cubctl-2.0.2/src/cubctl/cli/commands/device.py +79 -0
  17. cubctl-2.0.2/src/cubctl/cli/commands/introspect.py +92 -0
  18. cubctl-2.0.2/src/cubctl/cli/commands/migrate.py +258 -0
  19. cubctl-2.0.2/src/cubctl/cli/commands/notice.py +27 -0
  20. cubctl-2.0.2/src/cubctl/cli/commands/notifications.py +47 -0
  21. cubctl-2.0.2/src/cubctl/cli/commands/profiles.py +51 -0
  22. cubctl-2.0.2/src/cubctl/cli/commands/reactions.py +31 -0
  23. cubctl-2.0.2/src/cubctl/cli/commands/timeline.py +77 -0
  24. cubctl-2.0.2/src/cubctl/cli/commands/users.py +36 -0
  25. cubctl-1.0.0/src/cubctl/cli_helpers.py → cubctl-2.0.2/src/cubctl/cli/context.py +86 -31
  26. cubctl-2.0.2/src/cubctl/cli/docgen.py +88 -0
  27. cubctl-2.0.2/src/cubctl/cli/output.py +73 -0
  28. cubctl-2.0.2/src/cubctl/cli/runner.py +60 -0
  29. cubctl-2.0.2/src/cubctl/cli/spec_commands.py +123 -0
  30. cubctl-2.0.2/src/cubctl/client/__init__.py +7 -0
  31. cubctl-2.0.2/src/cubctl/client/base.py +80 -0
  32. cubctl-2.0.2/src/cubctl/client/methods/__init__.py +14 -0
  33. cubctl-2.0.2/src/cubctl/client/methods/bookmarks.py +37 -0
  34. cubctl-2.0.2/src/cubctl/client/methods/card.py +27 -0
  35. cubctl-2.0.2/src/cubctl/client/methods/collections.py +89 -0
  36. cubctl-2.0.2/src/cubctl/client/methods/device.py +41 -0
  37. cubctl-2.0.2/src/cubctl/client/methods/notice.py +15 -0
  38. cubctl-2.0.2/src/cubctl/client/methods/notifications.py +39 -0
  39. cubctl-2.0.2/src/cubctl/client/methods/profiles.py +23 -0
  40. cubctl-2.0.2/src/cubctl/client/methods/reactions.py +18 -0
  41. cubctl-2.0.2/src/cubctl/client/methods/timeline.py +40 -0
  42. cubctl-2.0.2/src/cubctl/client/methods/users.py +19 -0
  43. cubctl-2.0.2/src/cubctl/client/transport.py +150 -0
  44. cubctl-2.0.2/src/cubctl/config.py +315 -0
  45. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl/exceptions.py +1 -0
  46. cubctl-2.0.2/src/cubctl/migration/__init__.py +95 -0
  47. cubctl-2.0.2/src/cubctl/migration/bookmarks.py +106 -0
  48. cubctl-2.0.2/src/cubctl/migration/engine.py +183 -0
  49. cubctl-2.0.2/src/cubctl/migration/extras.py +126 -0
  50. cubctl-2.0.2/src/cubctl/migration/models.py +78 -0
  51. cubctl-2.0.2/src/cubctl/migration/notifications.py +64 -0
  52. cubctl-2.0.2/src/cubctl/migration/snapshot.py +114 -0
  53. cubctl-2.0.2/src/cubctl/migration/timeline.py +69 -0
  54. cubctl-2.0.2/src/cubctl/migration/tokens.py +71 -0
  55. cubctl-2.0.2/src/cubctl/spec.py +89 -0
  56. cubctl-2.0.2/src/cubctl.egg-info/PKG-INFO +258 -0
  57. cubctl-2.0.2/src/cubctl.egg-info/SOURCES.txt +74 -0
  58. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl.egg-info/requires.txt +3 -0
  59. cubctl-2.0.2/tests/test_accounts.py +126 -0
  60. cubctl-2.0.2/tests/test_agent_config.py +42 -0
  61. cubctl-1.0.0/tests/test_unit.py → cubctl-2.0.2/tests/test_auth_config.py +11 -10
  62. {cubctl-1.0.0 → cubctl-2.0.2}/tests/test_cli.py +9 -4
  63. cubctl-2.0.2/tests/test_golden_help.py +61 -0
  64. cubctl-2.0.2/tests/test_hardening.py +74 -0
  65. {cubctl-1.0.0 → cubctl-2.0.2}/tests/test_migration.py +0 -1
  66. cubctl-2.0.2/tests/test_migration_extras.py +74 -0
  67. cubctl-2.0.2/tests/test_safety.py +68 -0
  68. cubctl-2.0.2/tests/test_spec_client.py +121 -0
  69. cubctl-1.0.0/PKG-INFO +0 -396
  70. cubctl-1.0.0/README.md +0 -362
  71. cubctl-1.0.0/src/cubctl/api_spec.json +0 -1062
  72. cubctl-1.0.0/src/cubctl/cli.py +0 -992
  73. cubctl-1.0.0/src/cubctl/client.py +0 -417
  74. cubctl-1.0.0/src/cubctl/config.py +0 -244
  75. cubctl-1.0.0/src/cubctl/migration.py +0 -597
  76. cubctl-1.0.0/src/cubctl.egg-info/PKG-INFO +0 -396
  77. cubctl-1.0.0/src/cubctl.egg-info/SOURCES.txt +0 -24
  78. {cubctl-1.0.0 → cubctl-2.0.2}/LICENSE +0 -0
  79. {cubctl-1.0.0 → cubctl-2.0.2}/setup.cfg +0 -0
  80. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl/__main__.py +0 -0
  81. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl/hash_utils.py +0 -0
  82. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl.egg-info/dependency_links.txt +0 -0
  83. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl.egg-info/entry_points.txt +0 -0
  84. {cubctl-1.0.0 → cubctl-2.0.2}/src/cubctl.egg-info/top_level.txt +0 -0
  85. {cubctl-1.0.0 → cubctl-2.0.2}/tests/test_integration.py +0 -0
cubctl-2.0.2/PKG-INFO ADDED
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: cubctl
3
+ Version: 2.0.2
4
+ Summary: CLI and Python client for the CUB REST API (cub.best)
5
+ Author: Pavel Pikta
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/pavelpikta/lampa-cub-cli
8
+ Project-URL: Repository, https://github.com/pavelpikta/lampa-cub-cli
9
+ Project-URL: Documentation, https://github.com/pavelpikta/lampa-cub-cli#readme
10
+ Project-URL: Issues, https://github.com/pavelpikta/lampa-cub-cli/issues
11
+ Keywords: cub,lampa,cli,bookmarks,migration
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Internet :: WWW/HTTP
23
+ Classifier: Topic :: Utilities
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: requests>=2.28.0
28
+ Provides-Extra: test
29
+ Requires-Dist: pytest>=7.0; extra == "test"
30
+ Requires-Dist: pytest-cov>=4.0; extra == "test"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.5; extra == "dev"
35
+ Requires-Dist: build>=1.0; extra == "dev"
36
+ Requires-Dist: twine>=5.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # cubctl
40
+
41
+ CLI and Python library for the [CUB REST API](https://cub.best/developer/) (spec v1.31; default host `cub.best`, alternative mirror `cub.black`).
42
+ Covers all 173 documented endpoints, several named accounts with several profiles each, profile backup and migration.
43
+
44
+ ## Quick start
45
+
46
+ ```bash
47
+ pip install cubctl
48
+ cubctl accounts add home # asks for the 6-digit code from https://cub.best/add
49
+ cubctl profiles all
50
+ cubctl bookmarks counts
51
+ cubctl --help
52
+ ```
53
+
54
+ From a checkout: `pip install -e ".[dev]"` (or `PYTHONPATH=src python -m cubctl`).
55
+
56
+ ## Accounts and profiles
57
+
58
+ | Term | Flag | Env | Stored in `~/.cub/config.json` |
59
+ |------|------|-----|------|
60
+ | **Account** — a CUB login (token) with a default profile | `--account NAME` | `CUB_ACCOUNT` | `accounts.NAME` |
61
+ | **Profile** — a user profile inside an account (Pavel, Kids, …) | `--profile ID\|LABEL` | `CUB_PROFILE` | `accounts.NAME.profile` and `.profiles` (labels) |
62
+
63
+ Account names are free (`a-z 0-9 - _`, up to 32); `src` and `target` are just the conventional names used by `migrate`.
64
+
65
+ Credential chain, highest priority first:
66
+
67
+ 1. `--account NAME` (+ optional `--profile`)
68
+ 2. `--token TOKEN` (`-` reads it from stdin) or `CUB_TOKEN` — profile must then be numeric
69
+ 3. the default account: `CUB_ACCOUNT`, else `default_account` from the config, else `src`, else the only account
70
+
71
+ ```bash
72
+ cubctl accounts add work 123456 --default # one account at a time
73
+ cubctl accounts list # no tokens printed
74
+ cubctl accounts use home
75
+ cubctl accounts rename work office
76
+ cubctl accounts remove office --yes
77
+ cubctl config profile sync --account home # fetch profile names -> labels
78
+ cubctl history list --account home --profile Kids
79
+ cubctl history stats --account home --all-profiles # once per profile -> {profile_id: result}
80
+ ```
81
+
82
+ Full guide, config format and migration from the old two-slot config: [docs/accounts.md](docs/accounts.md).
83
+
84
+ ## Commands
85
+
86
+ - Hand-written: `accounts`, `config`, `device`, `migrate`, `backup`, `bookmarks`, `card`, `collections`, `notice`, `notifications`, `profiles`, `reactions`, `timeline`, `users`.
87
+ - **Every other endpoint is generated from `api_spec.json`** as `cubctl <category> <action> --flag …` (friends, history, iptv, plugins, shots, ai, …).
88
+ - Reference of all commands and flags: [docs/commands.md](docs/commands.md) (generated). In the terminal:
89
+
90
+ ```bash
91
+ cubctl endpoints --category friends # also: --public, --scope history, --search iptv
92
+ cubctl describe history add # params, errors, example response, premium flag
93
+ cubctl history add --card-id tv_1399 --watched-at now --dry-run
94
+ cubctl top fire --type movie --all-pages --format table
95
+ cubctl shots card --card-id 550 --card-type movie --select "results[0]"
96
+ cubctl api time now -p foo=bar # untyped escape hatch
97
+ ```
98
+
99
+ - `--dry-run` prints the request (token masked) without sending (generated commands). Destructive commands (`remove`, `clear`, `block`, `revoke`, …) ask for confirmation; `--yes` skips it, and is required with `--all-profiles`.
100
+ - `--format json|ndjson|table`, `--select a.b[0].c`, `--retries N`. `file` params take a path (multipart), `array` params take JSON or `1,2,3`.
101
+ - Secrets: `--token -`, and `-` for `--password`/`--pincode`/`--client-secret` values read stdin or prompt, so nothing lands in shell history.
102
+ - API errors print a hint with the meaning of the code from the spec (`555 — Нет премиум доступа`); `429` is retried with `Retry-After`, network errors and 5xx on GET are retried too.
103
+ - Shell completion: `source <(cubctl completion bash)` (zsh: `cubctl completion zsh`).
104
+ - Update the bundled spec: `cubctl spec` (diff against the live docs), `cubctl spec --write`.
105
+ - Not supported: OAuth sign-in flows (the `oauth` endpoints are callable, nothing stores/refreshes OAuth tokens). `--base-url`/`--timeout` go after the subcommand.
106
+
107
+ Python:
108
+
109
+ ```python
110
+ from cubctl import CubClient
111
+
112
+ client = CubClient.from_config(account="home", profile="311483")
113
+ client.bookmarks_all(type="book") # typed methods for the classic endpoints
114
+ client.call("friends/list") # any endpoint from the spec
115
+ client.call("shots/card/{card_id}/{card_type}", {"card_id": 550, "card_type": "movie"})
116
+ ```
117
+
118
+ ## Environment variables
119
+
120
+ | Variable | Description | Default |
121
+ |----------|-------------|---------|
122
+ | `CUB_TOKEN` / `CUB_PROFILE` | token / numeric profile ID for a one-off run | — |
123
+ | `CUB_ACCOUNT` | default account name | config default |
124
+ | `CUB_CODE_<NAME>` | device code used by `accounts add NAME` / `accounts setup` (`CUB_CODE_SRC`, `CUB_CODE_TARGET`) | — |
125
+ | `CUB_FROM_TOKEN` / `CUB_TO_TOKEN` | tokens for `migrate` without saved accounts | — |
126
+ | `CUB_BASE_URL` | API base URL | `https://cub.best/api/` |
127
+ | `CUB_CONFIG_DIR` | config directory | `~/.cub` |
128
+
129
+ `accounts.env` (see `accounts.env.example`) is loaded at startup when it sits next to a source checkout.
130
+
131
+ ## Bookmarks
132
+
133
+ Documented filter types are `book`, `history`, `like`, `wath`; `--full 1` also returns internal types (`viewed`, `scheduled`, `look`, `thrown`, …).
134
+
135
+ ```bash
136
+ cubctl bookmarks counts --account home --profile 311483
137
+ cubctl bookmarks all --account home --profile 311483 --type history
138
+ cubctl bookmarks all --account home --profile 311483 --full 1
139
+ ```
140
+
141
+ Timeline (`timeline/*`), `history/*` and several friends/ai endpoints need CUB Premium (`cubctl endpoints` marks them `[premium]`).
142
+
143
+ ## Backup and migration
144
+
145
+ JSON snapshot format **v3** (v1/v2 files still load): bookmarks (all internal types), timeline, and optional `notifications`, `history`, `collections` (saved), `person`, `plugins`, `iptv`.
146
+
147
+ ```bash
148
+ cubctl backup create --account home --profile 311483 --include bookmarks,timeline,history
149
+ cubctl backup restore --account office --profile 796529 -i backup.json --dry-run
150
+ cubctl migrate run --from home --from-profile 311483 --to office --to-profile 796529 --dry-run
151
+ cubctl migrate export --from home --from-profile 311483 -o pavel.json
152
+ cubctl migrate import --to office --to-profile 796529 -i pavel.json --progress
153
+ ```
154
+
155
+ **Always pass profile IDs** — an account stores the login profile, not named ones. Same account, two profiles: `cubctl migrate run --from-profile 311484 --to-profile 311483`.
156
+
157
+ | Flag | Description |
158
+ |------|-------------|
159
+ | `--from` / `--to` | account names |
160
+ | `--from-profile` / `--to-profile` | profile ID within each account |
161
+ | `--include bookmarks,timeline,notifications,history,collections,person,plugins,iptv` | what to copy. `history` is per profile; `collections`, `person`, `plugins`, `iptv` are account-wide and only added when missing on the target. `history` replays `history/add` (Premium may mark timecodes at 98%) |
162
+ | `--merge skip\|overwrite` | skip existing items (default) or overwrite timeline entries |
163
+ | `--dry-run` / `--progress` / `--quiet` / `--delay SECS` | simulate / progress to stderr / compact JSON / pause between writes |
164
+
165
+ ## Security
166
+
167
+ - `~/.cub/config.json` holds tokens in plain text: it is written atomically with mode `0600` (directory `0700`) and loosened files are tightened on load. Use full-disk encryption on shared machines.
168
+ - Prefer `CUB_TOKEN`, saved accounts or `--token -` over `--token VALUE`; `ps` and shell history show command lines.
169
+ - `--dry-run` masks `token`/`Authorization` headers.
170
+
171
+ ## Development
172
+
173
+ ```bash
174
+ pip install -e ".[dev]"
175
+ pytest -m "not integration" --cov=cubctl # unit tests, no network
176
+ pytest -m integration # live API; needs CUB_TEST_DEVICE_CODE
177
+ ruff check src tests
178
+ python scripts/gen_commands_doc.py # refresh docs/commands.md after changing commands/spec
179
+ CUBCTL_UPDATE_GOLDEN=1 pytest tests/test_golden_help.py # accept intended --help changes
180
+ ```
181
+
182
+ ```
183
+ src/cubctl/
184
+ ├── api_spec.json # endpoint table (source of truth for generated commands)
185
+ ├── spec.py # load/lookup/diff/update of the spec, error hints
186
+ ├── client/ # CubClient: transport.py (HTTP, retry, dry-run), base.py (call()), methods/ (typed, per category)
187
+ ├── cli/ # __init__.py (parser + main), context.py, runner.py, output.py, spec_commands.py, docgen.py
188
+ │ └── commands/ # one module per command group: register(sub, ...) + run(args)
189
+ ├── migration/ # models, tokens, bookmarks, timeline, notifications, extras, snapshot, engine
190
+ └── auth.py config.py exceptions.py hash_utils.py
191
+ ```
192
+
193
+ New command group: add `cli/commands/<name>.py` with `register()`/`run()` and list it in `cli/__init__.py`. See [CHANGELOG.md](CHANGELOG.md).
194
+
195
+ ## Publish to PyPI
196
+
197
+ ### Recommended: Trusted Publisher (no long-lived token)
198
+
199
+ PyPI exchanges a short-lived token with GitHub via OIDC. You do **not** need `PYPI_API_TOKEN` in GitHub Secrets when this is configured.
200
+
201
+ **1. PyPI** — [Account → Publishing](https://pypi.org/manage/account/publishing/) (or project → Publishing after the first release)
202
+
203
+ Add a **GitHub** trusted publisher:
204
+
205
+ | Field | Value |
206
+ |-------|--------|
207
+ | Owner | `pavelpikta` |
208
+ | Repository | `lampa-cub-cli` |
209
+ | Workflow name | `publish.yml` |
210
+ | Environment | `pypi` *(optional but matches this repo’s workflow)* |
211
+
212
+ For the **first upload**, you can add a [pending publisher](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) before the `cubctl` project exists on PyPI.
213
+
214
+ **2. GitHub** — repo [Settings → Environments](https://github.com/pavelpikta/lampa-cub-cli/settings/environments)
215
+
216
+ Create environment **`pypi`** (optional protections: required reviewers, branch rules).
217
+
218
+ No repository secret is required for trusted publishing.
219
+
220
+ **3. Release**
221
+
222
+ ```bash
223
+ git tag v1.0.0
224
+ git push origin v1.0.0
225
+ # GitHub → Releases → Draft new release from tag v1.0.0 → Publish
226
+ ```
227
+
228
+ Or run **Actions → publish → Run workflow** manually.
229
+
230
+ The workflow uses [`pypa/gh-action-pypi-publish`](https://github.com/marketplace/actions/pypi-publish) with `id-token: write` (see `.github/workflows/publish.yml`).
231
+
232
+ ### Alternative: API token + secret
233
+
234
+ If you prefer a classic token instead of trusted publishing:
235
+
236
+ 1. PyPI → Account settings → API tokens → create token (scope: entire account or project `cubctl`)
237
+ 2. GitHub → Settings → Secrets and variables → Actions → **`PYPI_API_TOKEN`**
238
+ 3. Replace the publish step in `publish.yml` with:
239
+
240
+ ```yaml
241
+ - name: Publish to PyPI
242
+ env:
243
+ TWINE_USERNAME: __token__
244
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
245
+ run: twine upload dist/*
246
+ ```
247
+
248
+ Remove `id-token: write` if you use only the token method.
249
+
250
+ ### Manual upload (local)
251
+
252
+ ```bash
253
+ pip install build twine
254
+ python -m build
255
+ twine check dist/*
256
+ twine upload dist/*
257
+ # Username: __token__ Password: pypi-Ag... (API token)
258
+ ```
cubctl-2.0.2/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # cubctl
2
+
3
+ CLI and Python library for the [CUB REST API](https://cub.best/developer/) (spec v1.31; default host `cub.best`, alternative mirror `cub.black`).
4
+ Covers all 173 documented endpoints, several named accounts with several profiles each, profile backup and migration.
5
+
6
+ ## Quick start
7
+
8
+ ```bash
9
+ pip install cubctl
10
+ cubctl accounts add home # asks for the 6-digit code from https://cub.best/add
11
+ cubctl profiles all
12
+ cubctl bookmarks counts
13
+ cubctl --help
14
+ ```
15
+
16
+ From a checkout: `pip install -e ".[dev]"` (or `PYTHONPATH=src python -m cubctl`).
17
+
18
+ ## Accounts and profiles
19
+
20
+ | Term | Flag | Env | Stored in `~/.cub/config.json` |
21
+ |------|------|-----|------|
22
+ | **Account** — a CUB login (token) with a default profile | `--account NAME` | `CUB_ACCOUNT` | `accounts.NAME` |
23
+ | **Profile** — a user profile inside an account (Pavel, Kids, …) | `--profile ID\|LABEL` | `CUB_PROFILE` | `accounts.NAME.profile` and `.profiles` (labels) |
24
+
25
+ Account names are free (`a-z 0-9 - _`, up to 32); `src` and `target` are just the conventional names used by `migrate`.
26
+
27
+ Credential chain, highest priority first:
28
+
29
+ 1. `--account NAME` (+ optional `--profile`)
30
+ 2. `--token TOKEN` (`-` reads it from stdin) or `CUB_TOKEN` — profile must then be numeric
31
+ 3. the default account: `CUB_ACCOUNT`, else `default_account` from the config, else `src`, else the only account
32
+
33
+ ```bash
34
+ cubctl accounts add work 123456 --default # one account at a time
35
+ cubctl accounts list # no tokens printed
36
+ cubctl accounts use home
37
+ cubctl accounts rename work office
38
+ cubctl accounts remove office --yes
39
+ cubctl config profile sync --account home # fetch profile names -> labels
40
+ cubctl history list --account home --profile Kids
41
+ cubctl history stats --account home --all-profiles # once per profile -> {profile_id: result}
42
+ ```
43
+
44
+ Full guide, config format and migration from the old two-slot config: [docs/accounts.md](docs/accounts.md).
45
+
46
+ ## Commands
47
+
48
+ - Hand-written: `accounts`, `config`, `device`, `migrate`, `backup`, `bookmarks`, `card`, `collections`, `notice`, `notifications`, `profiles`, `reactions`, `timeline`, `users`.
49
+ - **Every other endpoint is generated from `api_spec.json`** as `cubctl <category> <action> --flag …` (friends, history, iptv, plugins, shots, ai, …).
50
+ - Reference of all commands and flags: [docs/commands.md](docs/commands.md) (generated). In the terminal:
51
+
52
+ ```bash
53
+ cubctl endpoints --category friends # also: --public, --scope history, --search iptv
54
+ cubctl describe history add # params, errors, example response, premium flag
55
+ cubctl history add --card-id tv_1399 --watched-at now --dry-run
56
+ cubctl top fire --type movie --all-pages --format table
57
+ cubctl shots card --card-id 550 --card-type movie --select "results[0]"
58
+ cubctl api time now -p foo=bar # untyped escape hatch
59
+ ```
60
+
61
+ - `--dry-run` prints the request (token masked) without sending (generated commands). Destructive commands (`remove`, `clear`, `block`, `revoke`, …) ask for confirmation; `--yes` skips it, and is required with `--all-profiles`.
62
+ - `--format json|ndjson|table`, `--select a.b[0].c`, `--retries N`. `file` params take a path (multipart), `array` params take JSON or `1,2,3`.
63
+ - Secrets: `--token -`, and `-` for `--password`/`--pincode`/`--client-secret` values read stdin or prompt, so nothing lands in shell history.
64
+ - API errors print a hint with the meaning of the code from the spec (`555 — Нет премиум доступа`); `429` is retried with `Retry-After`, network errors and 5xx on GET are retried too.
65
+ - Shell completion: `source <(cubctl completion bash)` (zsh: `cubctl completion zsh`).
66
+ - Update the bundled spec: `cubctl spec` (diff against the live docs), `cubctl spec --write`.
67
+ - Not supported: OAuth sign-in flows (the `oauth` endpoints are callable, nothing stores/refreshes OAuth tokens). `--base-url`/`--timeout` go after the subcommand.
68
+
69
+ Python:
70
+
71
+ ```python
72
+ from cubctl import CubClient
73
+
74
+ client = CubClient.from_config(account="home", profile="311483")
75
+ client.bookmarks_all(type="book") # typed methods for the classic endpoints
76
+ client.call("friends/list") # any endpoint from the spec
77
+ client.call("shots/card/{card_id}/{card_type}", {"card_id": 550, "card_type": "movie"})
78
+ ```
79
+
80
+ ## Environment variables
81
+
82
+ | Variable | Description | Default |
83
+ |----------|-------------|---------|
84
+ | `CUB_TOKEN` / `CUB_PROFILE` | token / numeric profile ID for a one-off run | — |
85
+ | `CUB_ACCOUNT` | default account name | config default |
86
+ | `CUB_CODE_<NAME>` | device code used by `accounts add NAME` / `accounts setup` (`CUB_CODE_SRC`, `CUB_CODE_TARGET`) | — |
87
+ | `CUB_FROM_TOKEN` / `CUB_TO_TOKEN` | tokens for `migrate` without saved accounts | — |
88
+ | `CUB_BASE_URL` | API base URL | `https://cub.best/api/` |
89
+ | `CUB_CONFIG_DIR` | config directory | `~/.cub` |
90
+
91
+ `accounts.env` (see `accounts.env.example`) is loaded at startup when it sits next to a source checkout.
92
+
93
+ ## Bookmarks
94
+
95
+ Documented filter types are `book`, `history`, `like`, `wath`; `--full 1` also returns internal types (`viewed`, `scheduled`, `look`, `thrown`, …).
96
+
97
+ ```bash
98
+ cubctl bookmarks counts --account home --profile 311483
99
+ cubctl bookmarks all --account home --profile 311483 --type history
100
+ cubctl bookmarks all --account home --profile 311483 --full 1
101
+ ```
102
+
103
+ Timeline (`timeline/*`), `history/*` and several friends/ai endpoints need CUB Premium (`cubctl endpoints` marks them `[premium]`).
104
+
105
+ ## Backup and migration
106
+
107
+ JSON snapshot format **v3** (v1/v2 files still load): bookmarks (all internal types), timeline, and optional `notifications`, `history`, `collections` (saved), `person`, `plugins`, `iptv`.
108
+
109
+ ```bash
110
+ cubctl backup create --account home --profile 311483 --include bookmarks,timeline,history
111
+ cubctl backup restore --account office --profile 796529 -i backup.json --dry-run
112
+ cubctl migrate run --from home --from-profile 311483 --to office --to-profile 796529 --dry-run
113
+ cubctl migrate export --from home --from-profile 311483 -o pavel.json
114
+ cubctl migrate import --to office --to-profile 796529 -i pavel.json --progress
115
+ ```
116
+
117
+ **Always pass profile IDs** — an account stores the login profile, not named ones. Same account, two profiles: `cubctl migrate run --from-profile 311484 --to-profile 311483`.
118
+
119
+ | Flag | Description |
120
+ |------|-------------|
121
+ | `--from` / `--to` | account names |
122
+ | `--from-profile` / `--to-profile` | profile ID within each account |
123
+ | `--include bookmarks,timeline,notifications,history,collections,person,plugins,iptv` | what to copy. `history` is per profile; `collections`, `person`, `plugins`, `iptv` are account-wide and only added when missing on the target. `history` replays `history/add` (Premium may mark timecodes at 98%) |
124
+ | `--merge skip\|overwrite` | skip existing items (default) or overwrite timeline entries |
125
+ | `--dry-run` / `--progress` / `--quiet` / `--delay SECS` | simulate / progress to stderr / compact JSON / pause between writes |
126
+
127
+ ## Security
128
+
129
+ - `~/.cub/config.json` holds tokens in plain text: it is written atomically with mode `0600` (directory `0700`) and loosened files are tightened on load. Use full-disk encryption on shared machines.
130
+ - Prefer `CUB_TOKEN`, saved accounts or `--token -` over `--token VALUE`; `ps` and shell history show command lines.
131
+ - `--dry-run` masks `token`/`Authorization` headers.
132
+
133
+ ## Development
134
+
135
+ ```bash
136
+ pip install -e ".[dev]"
137
+ pytest -m "not integration" --cov=cubctl # unit tests, no network
138
+ pytest -m integration # live API; needs CUB_TEST_DEVICE_CODE
139
+ ruff check src tests
140
+ python scripts/gen_commands_doc.py # refresh docs/commands.md after changing commands/spec
141
+ CUBCTL_UPDATE_GOLDEN=1 pytest tests/test_golden_help.py # accept intended --help changes
142
+ ```
143
+
144
+ ```
145
+ src/cubctl/
146
+ ├── api_spec.json # endpoint table (source of truth for generated commands)
147
+ ├── spec.py # load/lookup/diff/update of the spec, error hints
148
+ ├── client/ # CubClient: transport.py (HTTP, retry, dry-run), base.py (call()), methods/ (typed, per category)
149
+ ├── cli/ # __init__.py (parser + main), context.py, runner.py, output.py, spec_commands.py, docgen.py
150
+ │ └── commands/ # one module per command group: register(sub, ...) + run(args)
151
+ ├── migration/ # models, tokens, bookmarks, timeline, notifications, extras, snapshot, engine
152
+ └── auth.py config.py exceptions.py hash_utils.py
153
+ ```
154
+
155
+ New command group: add `cli/commands/<name>.py` with `register()`/`run()` and list it in `cli/__init__.py`. See [CHANGELOG.md](CHANGELOG.md).
156
+
157
+ ## Publish to PyPI
158
+
159
+ ### Recommended: Trusted Publisher (no long-lived token)
160
+
161
+ PyPI exchanges a short-lived token with GitHub via OIDC. You do **not** need `PYPI_API_TOKEN` in GitHub Secrets when this is configured.
162
+
163
+ **1. PyPI** — [Account → Publishing](https://pypi.org/manage/account/publishing/) (or project → Publishing after the first release)
164
+
165
+ Add a **GitHub** trusted publisher:
166
+
167
+ | Field | Value |
168
+ |-------|--------|
169
+ | Owner | `pavelpikta` |
170
+ | Repository | `lampa-cub-cli` |
171
+ | Workflow name | `publish.yml` |
172
+ | Environment | `pypi` *(optional but matches this repo’s workflow)* |
173
+
174
+ For the **first upload**, you can add a [pending publisher](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) before the `cubctl` project exists on PyPI.
175
+
176
+ **2. GitHub** — repo [Settings → Environments](https://github.com/pavelpikta/lampa-cub-cli/settings/environments)
177
+
178
+ Create environment **`pypi`** (optional protections: required reviewers, branch rules).
179
+
180
+ No repository secret is required for trusted publishing.
181
+
182
+ **3. Release**
183
+
184
+ ```bash
185
+ git tag v1.0.0
186
+ git push origin v1.0.0
187
+ # GitHub → Releases → Draft new release from tag v1.0.0 → Publish
188
+ ```
189
+
190
+ Or run **Actions → publish → Run workflow** manually.
191
+
192
+ The workflow uses [`pypa/gh-action-pypi-publish`](https://github.com/marketplace/actions/pypi-publish) with `id-token: write` (see `.github/workflows/publish.yml`).
193
+
194
+ ### Alternative: API token + secret
195
+
196
+ If you prefer a classic token instead of trusted publishing:
197
+
198
+ 1. PyPI → Account settings → API tokens → create token (scope: entire account or project `cubctl`)
199
+ 2. GitHub → Settings → Secrets and variables → Actions → **`PYPI_API_TOKEN`**
200
+ 3. Replace the publish step in `publish.yml` with:
201
+
202
+ ```yaml
203
+ - name: Publish to PyPI
204
+ env:
205
+ TWINE_USERNAME: __token__
206
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
207
+ run: twine upload dist/*
208
+ ```
209
+
210
+ Remove `id-token: write` if you use only the token method.
211
+
212
+ ### Manual upload (local)
213
+
214
+ ```bash
215
+ pip install build twine
216
+ python -m build
217
+ twine check dist/*
218
+ twine upload dist/*
219
+ # Username: __token__ Password: pypi-Ag... (API token)
220
+ ```
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "cubctl"
3
- version = "1.0.0"
4
- description = "CLI and Python client for the CUB REST API (cub.rip)"
3
+ version = "2.0.2"
4
+ description = "CLI and Python client for the CUB REST API (cub.best)"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
7
7
  license = "MIT"
8
8
  license-files = ["LICENSE"]
9
9
  authors = [{ name = "Pavel Pikta" }]
10
- keywords = ["cub", "cub.rip", "lampa", "cli", "bookmarks", "migration"]
10
+ keywords = ["cub", "lampa", "cli", "bookmarks", "migration"]
11
11
  classifiers = [
12
12
  "Development Status :: 4 - Beta",
13
13
  "Environment :: Console",
@@ -18,6 +18,7 @@ classifiers = [
18
18
  "Programming Language :: Python :: 3.11",
19
19
  "Programming Language :: Python :: 3.12",
20
20
  "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14",
21
22
  "Topic :: Internet :: WWW/HTTP",
22
23
  "Topic :: Utilities",
23
24
  ]
@@ -37,9 +38,12 @@ cubctl = "cubctl.cli:main"
37
38
  [project.optional-dependencies]
38
39
  test = [
39
40
  "pytest>=7.0",
41
+ "pytest-cov>=4.0",
40
42
  ]
41
43
  dev = [
42
44
  "pytest>=7.0",
45
+ "pytest-cov>=4.0",
46
+ "ruff>=0.5",
43
47
  "build>=1.0",
44
48
  "twine>=5.0",
45
49
  ]
@@ -64,3 +68,11 @@ where = ["src"]
64
68
 
65
69
  [tool.setuptools.package-data]
66
70
  cubctl = ["api_spec.json"]
71
+
72
+ [tool.ruff]
73
+ line-length = 120
74
+ target-version = "py310"
75
+
76
+ [tool.ruff.lint]
77
+ select = ["F", "E9", "B"]
78
+ ignore = ["B904"]
@@ -1,6 +1,6 @@
1
1
  """CUB REST API Python client and CLI."""
2
2
 
3
- __version__ = "1.0.0"
3
+ __version__ = "2.0.2"
4
4
 
5
5
  from .auth import DEVICE_CODE_URL, DeviceCredentials, login_device, normalize_device_code
6
6
  from .client import CubClient, DEFAULT_BASE_URL