Skip to content

Commit

Permalink
feat/radarr support (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
hollanbm authored May 28, 2024
1 parent 9762722 commit 8733465
Show file tree
Hide file tree
Showing 21 changed files with 784 additions and 280 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python": {
"terminal": {
"activateEnvironment": false
},
"analysis": {
"autoFormatStrings": true,
"defaultInterpreterPath": "${containerWorkspaceFolder}/.venv/bin/python",
Expand All @@ -64,7 +67,7 @@
"unittestEnabled": false,
"pytestEnabled": true,
"pytestArgs": [
"tests"
"--no-cov"
]
}
},
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/buildImage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
Expand All @@ -62,3 +62,4 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
}
}
]
}
}
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# sonarr-series-scanner
# Renamarr (previously sonarr-series-scanner)

With the addition of radarr support, I've decided to rename this project to Renamarr

## Quick Start

Expand All @@ -13,26 +15,27 @@

coming soon

## Requirements

* [Python 3.12](https://www.python.org/downloads/release/python-3123/)
* [pipx](https://pipx.pypa.io/stable/installation/)
* [poetry](https://python-poetry.org/docs/#installation)
* [Sonarr](https://sonarr.tv/)
* This script is intended to be used alongside the `Episode Title Required` setting
* Settings -> Media Management -> Episode Title Required -> `Always`
## How it works

### The problem
### Renamarr

It is relatively common for the TVDB to be updated the day of, or even after airing. Sonarr refreshes its TVDB cache every 12 hours.
This job uses the [Sonarr API](https://sonarr.tv/docs/api/)/[Radarr API](https://radarr.video/docs/api/) to do the following

Unfortunately, this can prevent import for up to 12 hours in extreme circumstances.
* Iterate over all items (Movies or Series)
* Checks if any items need to be renamed
* Radarr [get_api_v3_rename](https://radarr.video/docs/api/#/RenameMovie/get_api_v3_rename)
* Sonarr [get_api_v3_rename](https://sonarr.tv/docs/api/#/RenameEpisode/get_api_v3_rename)
* Triggers a rename on any item that need be renamed
* Series renames are batched up, for one rename call per series
* Movie renames are initiated per movie.
* Example, 1 movie, 2 files. There will be 2 rename API calls

To solve this, I created this app
#### Analyze Files
This config option is useful if you have audio/video codec information as part of your mediaformat, and you are transcoding files after import. This will initiate a rescan of the files in your library, so that the mediainfo will be udpated. Then renamarr will come through and detect changes, and rename the files

## How it works

### Series Scanner
### Series Scanner (Sonarr Only)
This job uses the [Sonarr API](https://sonarr.tv/docs/api/) to do the following

* Iterate over continuing [series](https://sonarr.tv/docs/api/#/Series/get_api_v3_series)
Expand All @@ -45,17 +48,6 @@ This job uses the [Sonarr API](https://sonarr.tv/docs/api/) to do the following

This should prevent too many API calls to the TVDB, refreshing individual series, hourly

### Existing Renamer

This job uses the [Sonarr API](https://sonarr.tv/docs/api/) to do the following

* Iterate over all [series](https://sonarr.tv/docs/api/#/Series/get_api_v3_series)
* Checks if any episodes need to be [renamed](https://sonarr.tv/docs/api/#/RenameEpisode/get_api_v3_rename)
* Triggers a rename on any episodes that need be renamed (per series)

#### Analyze Files
This config option is useful if you have audio/video codec information as part of your mediaformat, and you are transcoding files after import to sonarr. This will initiate a rescan of the files in your library, so that the mediainfo will be udpated. Then the renamer will come through and detect changes, and rename the files

### Usage

The application run immediately on startup, and then continue to schedule jobs every hour (+- 5 minutes) after the first execution.
Expand All @@ -71,11 +63,21 @@ The application run immediately on startup, and then continue to schedule jobs e
| `sonarr[].series_scanner.enabled` | boolean | No | False | enables/disables series_scanner functionality |
| `sonarr[].series_scanner.hourly_job` | boolean | No | False | disables hourly job. App will exit after first execution |
| `sonarr[].series_scanner.hours_before_air` | integer | No | 4 | The number of hours before an episode has aired, to trigger a rescan when title is TBA |
| `sonarr[].existing_renamer.enabled` | boolean | No | False | enables/disables existing_renamer functionality |
| `sonarr[].existing_renamer.hourly_job` | boolean | No | False | disables hourly job. App will exit after first execution |
| `sonarr[].existing_renamer.analyze_files` | boolean | No | False | This will initiate a rescan of the files in your library. This is helpful if you are transcoding files, and the audio/video codecs have changed. |
| `sonarr[].renamarr.enabled` | boolean | No | False | enables/disables renamarr functionality |
| `sonarr[].renamarr.hourly_job` | boolean | No | False | disables hourly job. App will exit after first execution |
| `sonarr[].renamarr.analyze_files` | boolean | No | False | This will initiate a rescan of the files in your library. This is helpful if you are transcoding files, and the audio/video codecs have changed. |
| `radarr[].renamarr.enabled` | boolean | No | False | enables/disables renamarr functionality |
| `radarr[].renamarr.hourly_job` | boolean | No | False | disables hourly job. App will exit after first execution |
| `radarr[].renamarr.analyze_files` | boolean | No | False | This will initiate a rescan of the files in your library. This is helpful if you are transcoding files, and the audio/video codecs have changed. |

### Local Setup

#### Requirements

* [Python 3.12](https://www.python.org/downloads/release/python-3123/)
* [pipx](https://pipx.pypa.io/stable/installation/)
* [poetry](https://python-poetry.org/docs/#installation)

#### devcontainer

There is a [devcontainer](https://containers.dev/) provided; it is optional but recommended.
Expand Down
19 changes: 17 additions & 2 deletions docker/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sonarr:
series_scanner:
enabled: True
hourly_job: True
existing_renamer:
renamarr:
enabled: False
hourly_job: False
analyze_files: False
Expand All @@ -16,6 +16,21 @@ sonarr:
enabled: False
hourly_job: True
hours_before_air: 1 # optional, defaults to 4
existing_renamer:
renamarr:
enabled: True
hourly_job: True
radarr:
- name: radarr
url: https://radarr.tld:7878
api_key: not-a-real-api-key
renamarr:
enabled: True
hourly_job: False
analyze_files: False
- name: radarr-4k
url: https://radarr-4k.tld:7878
api_key: not-a-real-api-key
renamarr:
enabled: True
hourly_job: True
analyze_files: True
6 changes: 3 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
series_scanner:
container_name: series_scanner
image: ghcr.io/hollanbm/sonarr-series-scanner:latest
renamarr:
container_name: renamarr
image: ghcr.io/hollanbm/renamarr:latest
restart: unless-stopped
volumes:
- ./config.yml:/config/config.yml:ro
Loading

0 comments on commit 8733465

Please sign in to comment.