Repository navigation
docs: document Import Using Script for Radarr and Sonarr - #477
6801318d8d wants to merge 1 commit into
Conversation
bakerboy448
left a comment
There was a problem hiding this comment.
Checked this against ScriptImportDecider.cs, UpgradeMediaFileService.cs, the *FileMovingService.cs transfer path, ImportApproved*.cs and ProcessProvider.StartAndCapture on Radarr develop and Sonarr main/develop. Most of it is accurate: the arguments, the env var list, the output tokens, the exit-code check, the RenameRequested media info re-read, the | separator, the season pack note, and the StringDictionary explanation.
A few fixes, all small:
- A manual import of a file already inside the movie/series folder skips the script, unless it comes from a queue item.
HardLinkis never passed as the transfer mode.- On upgrades the old files are removed first (Recycling Bin if set), so a failing script leaves no file.
radarr_moviefile_idis always0.- Stderr is parsed for the
[...]tokens too. [MediaFile]has to be inside the movie/series folder.- A failed script shows only "Failed to import" in the queue; the exit code is in the logs.
- Nit: the lowercase note can be one line under Environment variables instead of a warning under Exit code.
Suggestions inline. Frontmatter date doesn't need a bump; recent PRs to these pages (#455, #466) left it alone.
Verdict: Comment. Good to merge once those are in.
|
|
||
| ### Import Using Script | ||
|
|
||
| Radarr runs the script once per imported movie file, for downloads and for manual imports, instead of copying, hardlinking or moving the file itself. |
There was a problem hiding this comment.
A manual import of a file that is already inside the movie folder is passed with newDownload = false and never reaches the script (ManualImportService.cs:419,470, ImportApprovedMovie.cs:131-149). The exception is an import from a queue item, which sets newDownload = true (:474).
| Radarr runs the script once per imported movie file, for downloads and for manual imports, instead of copying, hardlinking or moving the file itself. | |
| Radarr runs the script once per imported movie file, for downloads and for manual imports, instead of copying, hardlinking or moving the file itself. A manual import of a file that is already inside the movie folder does not run the script (unless it is imported from a queue item). |
|
|
||
| ### Import Using Script | ||
|
|
||
| Sonarr runs the script once per imported episode file, for downloads and for manual imports, instead of copying, hardlinking or moving the file itself. The source paths of all the files of a download are worked out before the first call, so a script must not move the other files of a season pack (for example by renaming the download's folder). |
There was a problem hiding this comment.
Same as Radarr: ManualImportService.cs:495,548 on main, queue imports set newDownload = true at :552.
| Sonarr runs the script once per imported episode file, for downloads and for manual imports, instead of copying, hardlinking or moving the file itself. The source paths of all the files of a download are worked out before the first call, so a script must not move the other files of a season pack (for example by renaming the download's folder). | |
| Sonarr runs the script once per imported episode file, for downloads and for manual imports, instead of copying, hardlinking or moving the file itself. A manual import of a file that is already inside the series folder does not run the script (unless it is imported from a queue item). The source paths of all the files of a download are worked out before the first call, so a script must not move the other files of a season pack (for example by renaming the download's folder). |
| | -------- | ------- | | ||
| | `radarr_sourcepath` | Same as `$1` | | ||
| | `radarr_destinationpath` | Same as `$2` | | ||
| | `radarr_transfermode` | What Radarr would have done: `Move`, `Copy`, `HardLink`, `HardLinkOrCopy` | |
There was a problem hiding this comment.
HardLink exists in the enum but nothing passes it. MoveMovieFile sends Move, and CopyMovieFile sends HardLinkOrCopy when hardlinks are enabled and Copy otherwise (MovieFileMovingService.cs:82,95,99).
| | `radarr_transfermode` | What Radarr would have done: `Move`, `Copy`, `HardLink`, `HardLinkOrCopy` | | |
| | `radarr_transfermode` | What Radarr would have done: `Move`, `Copy`, or `HardLinkOrCopy` when Use Hardlinks instead of Copy is enabled | |
| | -------- | ------- | | ||
| | `sonarr_sourcepath` | Same as `$1` | | ||
| | `sonarr_destinationpath` | Same as `$2` | | ||
| | `sonarr_transfermode` | What Sonarr would have done: `Move`, `Copy`, `HardLink`, `HardLinkOrCopy` | |
There was a problem hiding this comment.
Same as Radarr (EpisodeFileMovingService.cs:91,103,107).
| | `sonarr_transfermode` | What Sonarr would have done: `Move`, `Copy`, `HardLink`, `HardLinkOrCopy` | | |
| | `sonarr_transfermode` | What Sonarr would have done: `Move`, `Copy`, or `HardLinkOrCopy` when Use Hardlinks instead of Copy is enabled | |
| | `radarr_movie_id`, `radarr_movie_title`, `radarr_movie_year`, `radarr_movie_path`, `radarr_movie_tmdbid`, `radarr_movie_imdbid`, `radarr_movie_tags` | The movie | | ||
| | `radarr_moviefile_relativepath`, `radarr_moviefile_quality`, `radarr_moviefile_releasegroup`, `radarr_moviefile_scenename` | The file being imported | | ||
| | `radarr_download_client`, `radarr_download_client_type`, `radarr_download_id` | Download client name and type, and the download's id (the torrent hash for torrent clients); empty for imports that are not downloads | | ||
| | `radarr_deletedpaths`, `radarr_deletedrelativepaths` | On upgrades, the replaced files, separated by `\|`; Radarr has already deleted them when the script runs | |
There was a problem hiding this comment.
UpgradeMovieFile removes the old file through _recycleBinProvider.DeleteFile before the mover runs (UpgradeMediaFileService.cs:58-72), so with a Recycling Bin set the file is moved there, not deleted. It also means a script that fails on an upgrade leaves the movie with no file.
| | `radarr_deletedpaths`, `radarr_deletedrelativepaths` | On upgrades, the replaced files, separated by `\|`; Radarr has already deleted them when the script runs | | |
| | `radarr_deletedpaths`, `radarr_deletedrelativepaths` | On upgrades, the replaced files, separated by `\|`. Radarr has already removed them (deleted, or moved to the Recycling Bin if one is set) when the script runs, so a failing script leaves the movie without a file | |
|
|
||
| #### Exit code | ||
|
|
||
| Anything other than `0` fails the import (shown in Activity > Queue and in the logs). |
There was a problem hiding this comment.
Same as Radarr; Sonarr's message is "Failed to import episode".
| Anything other than `0` fails the import (shown in Activity > Queue and in the logs). | |
| Anything other than `0` fails the import of that file. For a download, Activity > Queue only shows "Failed to import episode"; the exit code is only in the logs (Warn level). |
|
|
||
| #### Environment variables | ||
|
|
||
| The most useful ones (the names arrive in **lowercase**, see the warning below): |
There was a problem hiding this comment.
Nit: the Custom Scripts page already uses these lowercase names, so one line here can replace the warning under Exit code.
| The most useful ones (the names arrive in **lowercase**, see the warning below): | |
| The most useful ones. The names arrive in lowercase (`radarr_sourcepath`, not `Radarr_SourcePath`), the same as on [Custom Scripts](/radarr/custom-scripts): |
| > The variable names are lowercase although the source code spells them `Radarr_SourcePath` etc.: Radarr passes them in a .NET `StringDictionary`, which lowercases keys. In a shell script use `$radarr_sourcepath`. | ||
| {.is-warning} |
There was a problem hiding this comment.
Drop the warning here once the note above is in.
| > The variable names are lowercase although the source code spells them `Radarr_SourcePath` etc.: Radarr passes them in a .NET `StringDictionary`, which lowercases keys. In a shell script use `$radarr_sourcepath`. | |
| {.is-warning} |
|
|
||
| #### Environment variables | ||
|
|
||
| The most useful ones (the names arrive in **lowercase**, see the warning below): |
There was a problem hiding this comment.
Same nit as Radarr.
| The most useful ones (the names arrive in **lowercase**, see the warning below): | |
| The most useful ones. The names arrive in lowercase (`sonarr_sourcepath`, not `Sonarr_SourcePath`), the same as on [Custom Scripts](/sonarr/custom-scripts): |
| > The variable names are lowercase although the source code spells them `Sonarr_SourcePath` etc.: Sonarr passes them in a .NET `StringDictionary`, which lowercases keys. In a shell script use `$sonarr_sourcepath`. | ||
| {.is-warning} |
There was a problem hiding this comment.
Drop the warning here once the note above is in.
| > The variable names are lowercase although the source code spells them `Sonarr_SourcePath` etc.: Sonarr passes them in a .NET `StringDictionary`, which lowercases keys. In a shell script use `$sonarr_sourcepath`. | |
| {.is-warning} |
"Import Using Script" (Settings > Media Management > Importing) is documented with one line in Sonarr's page and not at all in Radarr's, so writing a script means reading
ScriptImportDecider.cs. This adds what the script receives and what it can answer, from the Radarr and Sonarr sources:radarr_sourcepath, notRadarr_SourcePathas spelled in the source: they are passed through a .NETStringDictionary, which lowercases keys). I lost some time on this: a hand test with the source spelling worked, the real import failed with "unbound variable";[MoveStatus] MoveComplete|RenameRequested|DeferMove,[MediaFile],[ExtraFile],[PreventExtraImport]) and that printing nothing meansMoveComplete;Checked against
ScriptImportDecider.csandUpgradeMediaFileService.csof both apps (currentdevelop) and tested with Radarr 6.4.4 and Sonarr 4.0.20. The pre-commit hooks pass on both files.