Merge pull request #5609 from PKC278/v2

This commit is contained in:
jxxghp
2026-03-23 17:18:51 +08:00
committed by GitHub
2 changed files with 77 additions and 74 deletions
+4 -2
View File
@@ -147,8 +147,10 @@ class MediaChain(ChainBase, ConfigReloadMixin, metaclass=Singleton):
'thumb': ScrapingMetadata.THUMB, 'thumb': ScrapingMetadata.THUMB,
} }
scraping_policies = ScrapingConfig.from_system_config() def __init__(self):
storagechain = StorageChain() super().__init__()
self.storagechain = StorageChain()
self.scraping_policies = ScrapingConfig.from_system_config()
def on_config_changed(self): def on_config_changed(self):
self.scraping_policies = ScrapingConfig.from_system_config() self.scraping_policies = ScrapingConfig.from_system_config()
+73 -72
View File
@@ -11,10 +11,9 @@ Use `scripts/mp-cli.js` to interact with the MoviePilot backend.
## Discover Commands ## Discover Commands
```bash List all available commands: `node scripts/mp-cli.js list`
node scripts/mp-cli.js list # list all available commands
node scripts/mp-cli.js show <command> # show parameters and usage Show parameters and usage for a specific command: `node scripts/mp-cli.js show <command>`
```
Always run `show <command>` before calling a command — parameter names are not inferable, do not guess. Always run `show <command>` before calling a command — parameter names are not inferable, do not guess.
@@ -37,46 +36,44 @@ Always run `show <command>` before calling a command — parameter names are not
#### 1. Search TMDB #### 1. Search TMDB
```bash Search for a movie or TV show by title:
node scripts/mp-cli.js search_media title="..." media_type="movie" `node scripts/mp-cli.js search_media title="..." media_type="movie"`
```
For TV with user-specified season: the user's season may not match TMDB — run Season Validation (see below). If the user specifies a TV season, run Season Validation step first — the season number provided by the user may not match TMDB.
```bash
node scripts/mp-cli.js query_media_detail tmdb_id=... media_type="tv"
```
#### 2. Search torrents #### 2. Search torrents
Prefer `tmdb_id`; use `douban_id` only when `tmdb_id` is unavailable. Prefer `tmdb_id`; use `douban_id` only when `tmdb_id` is unavailable.
Omitting `sites=` uses the user's default sites. If the user specifies sites, run `query_sites` first to get site IDs, then pass them via `sites=` to `search_torrents` — do not skip this step.
```bash Omitting `sites=` uses the user's default sites. If the user specifies sites, first retrieve site IDs:
node scripts/mp-cli.js query_sites # get site IDs `node scripts/mp-cli.js query_sites`
node scripts/mp-cli.js search_torrents tmdb_id=791373 media_type="movie" # default sites
node scripts/mp-cli.js search_torrents tmdb_id=791373 media_type="movie" sites='1,3' # user-specified sites
```
After `search_torrents` returns, you must stop and present **all** `filter_options` fields and values to the user verbatim — show every field and all of its values; do not pre-select, summarize, or omit any. Do not call `get_search_results` until the user has explicitly selected filters or confirmed that no filters should be applied. Search torrents using default sites:
`node scripts/mp-cli.js search_torrents tmdb_id=791373 media_type="movie"`
Search torrents using user-specified sites (pass site IDs from `query_sites`):
`node scripts/mp-cli.js search_torrents tmdb_id=791373 media_type="movie" sites='1,3'`
When `search_torrents` returns:
1. **Stop** — do not call `get_search_results` yet.
2. Present all `filter_options` fields and every value within each field to the user verbatim.
3. Do not pre-select, summarize, or omit any field or value.
4. Wait for the user to select filters or confirm no filters are needed before moving to the next step.
#### 3. Get filtered results (only after user has responded to filter_options) #### 3. Get filtered results (only after user has responded to filter_options)
Array params: `site`, `season`, `free_state`, `video_code`, `edition`, `resolution`, `release_group` OR within a field, AND across fields. Run `node scripts/mp-cli.js show get_search_results` to check available parameters. Filter logic: OR within a field, AND across fields.
`title_pattern`: regex string for torrent title matching (e.g., `4K|2160p|UHD`). Use only when user explicitly requests pattern matching.
`show_filter_options=true`: re-check available filters only, not for fetching results.
Filter values must come from the `filter_options` returned by `search_torrents` in step 2 — do not invent, translate, normalize, or use values from any other source. Note: `filter_options` keys are camelCase (e.g., `freeState`), but `get_search_results` params are snake_case (e.g., `free_state`). Filter values must come from the `filter_options` returned by `search_torrents` — do not invent, translate, normalize, or use values from any other source. Note: `filter_options` keys are camelCase (e.g., `freeState`), but `get_search_results` params are snake_case (e.g., `free_state`).
```bash Fetch results with selected filters:
node scripts/mp-cli.js get_search_results resolution='1080p,2160p' free_state='免费,50%' `node scripts/mp-cli.js get_search_results resolution='1080p,2160p' free_state='免费,50%'`
```
If empty, tell the user which filter to relax and ask before retrying. If empty, tell the user which filter to relax and ask before retrying.
#### 4. Present results as a numbered list #### 4. Present results as a numbered list
Show all results without pre-selection. Each row: index, title, size, seeders, resolution, release group (verbatim, keep `@` etc.), `volume_factor`, `freedate_diff`. Show all results without pre-selection. Each row: index, title, size, seeders, resolution, release group, `volume_factor`, `freedate_diff`.
| `volume_factor` | Meaning | | `volume_factor` | Meaning |
|---|---| |---|---|
@@ -90,15 +87,14 @@ Show all results without pre-selection. Each row: index, title, size, seeders, r
#### 5. Check before downloading #### 5. Check before downloading
After user picks, run **Check Library and Subscriptions** (see section below) before calling `add_download`. If the media already exists in the library or is already subscribed, stop and tell the user what was found — do not call `add_download` until the user explicitly confirms they still want to proceed. After the user picks torrents: Run **Check Library and Subscriptions** step.
If the media already exists in the library or is already subscribed, **stop** and report the finding to the user.
#### 6. Add download #### 6. Add download
`torrent_url` comes from the `torrent_url` field in `get_search_results` output. Download one or more torrents (`torrent_url` comes from `get_search_results` output):
`node scripts/mp-cli.js add_download torrent_url="abc1234:1,def5678:2"`
```bash
node scripts/mp-cli.js add_download torrent_url="abc1234:1,def5678:2" # comma-separated for multiple
```
#### Error handling #### Error handling
@@ -111,45 +107,53 @@ node scripts/mp-cli.js add_download torrent_url="abc1234:1,def5678:2" # comma-s
### Add Subscription ### Add Subscription
1. `search_media` to get `tmdb_id` 1. Search for the media to get `tmdb_id`: Run `search_media`.
2. Run **Check Library and Subscriptions** 2. Run **Check Library and Subscriptions** step, if media already exists or is subscribed, **stop** and report to user.
3. If user specified a season, run **Season Validation** to get correct `season` and `start_episode` — must complete before calling `add_subscribe` 3. If the user specifies a TV season, run Season Validation step first.
Pass `start_episode=` when the user's season maps to a mid-season episode range (e.g., user call it "Season 2" but TMDB has Season 1, episodes starting at 13). Subscribe to a movie or TV show:
`node scripts/mp-cli.js add_subscribe title="..." year="2011" media_type="tv" tmdb_id=42009`
```bash Subscribe to a specific season:
node scripts/mp-cli.js add_subscribe title="..." year="2011" media_type="tv" tmdb_id=42009 `node scripts/mp-cli.js add_subscribe title="..." year="2011" media_type="tv" tmdb_id=42009 season=4`
node scripts/mp-cli.js add_subscribe title="..." year="2011" media_type="tv" tmdb_id=42009 season=4
node scripts/mp-cli.js add_subscribe title="..." year="2024" media_type="tv" tmdb_id=12345 season=1 start_episode=13 Subscribe starting from a specific episode:
``` `node scripts/mp-cli.js add_subscribe title="..." year="2024" media_type="tv" tmdb_id=12345 season=1 start_episode=13`
### Manage Downloads ### Manage Downloads
```bash List download tasks and get hash for further operations:
node scripts/mp-cli.js query_download_tasks status=downloading # list tasks, get hash for deletion `node scripts/mp-cli.js query_download_tasks status=downloading`
node scripts/mp-cli.js delete_download hash=<hash> # confirm with user first (irreversible)
node scripts/mp-cli.js delete_download hash=<hash> delete_files=true # also remove files Delete a download task (confirm with user first — irreversible):
``` `node scripts/mp-cli.js delete_download hash=<hash>`
Delete a download task and also remove its files (confirm with user first — irreversible):
`node scripts/mp-cli.js delete_download hash=<hash> delete_files=true`
### Manage Subscriptions ### Manage Subscriptions
```bash List active subscriptions:
node scripts/mp-cli.js query_subscribes status=R # list active `node scripts/mp-cli.js query_subscribes status=R`
node scripts/mp-cli.js update_subscribe subscribe_id=123 resolution="1080p" # update filters
node scripts/mp-cli.js search_subscribe subscribe_id=123 # search missing episodes — confirm first Update subscription filters:
node scripts/mp-cli.js delete_subscribe subscribe_id=123 # remove — confirm first `node scripts/mp-cli.js update_subscribe subscribe_id=123 resolution="1080p"`
```
Trigger a search for missing episodes (confirm with user first):
`node scripts/mp-cli.js search_subscribe subscribe_id=123`
Remove a subscription (confirm with user first):
`node scripts/mp-cli.js delete_subscribe subscribe_id=123`
### Check Library and Subscriptions ### Check Library and Subscriptions
Run before any download or subscription to avoid duplicates: Run before any download or subscription to avoid duplicates.
```bash Check if the media already exists in the library:
node scripts/mp-cli.js query_library_exists tmdb_id=123456 media_type="movie" `node scripts/mp-cli.js query_library_exists tmdb_id=123456 media_type="movie"`
node scripts/mp-cli.js query_subscribes tmdb_id=123456
```
If already in library or already subscribed, stop and report the finding to the user. Do not proceed with download or subscription until the user explicitly confirms they still want to continue. Otherwise continue directly. Check if the media is already subscribed:
`node scripts/mp-cli.js query_subscribes tmdb_id=123456`
### Season Validation ### Season Validation
@@ -157,24 +161,21 @@ Mandatory when user specifies a season. Productions sometimes release a show in
#### 1. Verify season exists #### 1. Verify season exists
```bash Fetch media detail to check available seasons:
node scripts/mp-cli.js query_media_detail tmdb_id=<id> media_type="tv" `node scripts/mp-cli.js query_media_detail tmdb_id=<id> media_type="tv"`
```
Check `season_info` against the user's requested season: Compare `season_info` with the user's requested season:
1. If the season exists in `season_info` → use that season number directly and return to the calling workflow.
- **Season exists:** use that season number directly, proceed to torrent search. 2. If the season does not exist → the user's "season" likely maps to a later episode range within an existing TMDB season. Note the latest (highest-numbered) season from `season_info`, then continue to next step.
- **Season does not exist:** the user's "season" likely maps to a later episode range within an existing TMDB season. Note the latest (highest-numbered) season from `season_info`, then continue to step 2.
#### 2. Identify the correct episode range #### 2. Identify the correct episode range
Take the latest season number from step 1's `season_info` and pass it as the `season=` parameter: Fetch episode schedule for the latest season from `season_info`:
`node scripts/mp-cli.js query_episode_schedule tmdb_id=<id> season=<latest_season_number>`
```bash
node scripts/mp-cli.js query_episode_schedule tmdb_id=<id> season=<latest_season_from_season_info>
```
Use `air_date` to find a block of recently-aired episodes that likely corresponds to what the user calls the missing season. Look for a gap in `air_date` between episodes — the gap indicates a part break, and the episodes after the gap are what the user likely refers to as the next "season". For example, if TMDB Season 1 has episodes 124 and there is a multi-month gap between episode 12 and 13, then episodes 1324 correspond to the user's "Season 2". If no such gap exists, tell user content is unavailable. Otherwise confirm the episode range with user. Use `air_date` to find a block of recently-aired episodes that likely corresponds to what the user calls the missing season. Look for a gap in `air_date` between episodes — the gap indicates a part break, and the episodes after the gap are what the user likely refers to as the next "season". For example, if TMDB Season 1 has episodes 124 and there is a multi-month gap between episode 12 and 13, then episodes 1324 correspond to the user's "Season 2". If no such gap exists, tell user content is unavailable. Otherwise confirm the episode range with user.
## Error handling ## Error handling
**Missing configuration:** Ask the user for the backend host and API key. Once provided, run `node scripts/mp-cli.js -h <HOST> -k <KEY>` (no command) to save the config persistently — subsequent commands will use it automatically.
Missing configuration: Ask the user for the backend host and API key. Once provided, save the config persistently — subsequent commands will use it automatically:
`node scripts/mp-cli.js -h <HOST> -k <KEY>`