Skip to content

Commit

Permalink
changed variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
chkpwd committed Oct 24, 2024
1 parent e13b042 commit 745fbac
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .env.pub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ADDRESS="0.0.0.0"
LISTEN_PORT="7979"
ANIME_NAME="one-piece"
AFL_ANIME_NAME="one-piece"
SONARR_URL="https://sonarr.local"
SONARR_SERIES_ID="187"
SONARR_API_KEY="<your_api_key>"
Expand Down
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The SoFE (Sonarr Anime Filler Excluder) is a Python application designed to coll
- Docker / Docker Compose
- Prometheus server setup for collecting metrics. (Optional)

> [!Note] Make sure to obtain the anime name from [Anime Filler List](https://www.animefillerlist.com/).
![alt text](image.png)

## Installation

The SoFE can be easily run as a container. This section covers pulling the Container Image from the GitHub Container Registry and running it.
Expand All @@ -27,11 +30,16 @@ docker pull ghcr.io/chkpwd/sofe:latest
Run the container:
```sh
docker run --rm -p 7979:7979 \
-e SONARR_SERIES_ID=187 \
-e ANIME_NAME="one-piece" \
-e SONARR_API_KEY="your_api_key" \
-e SONARR_URL="https://sonarr.local" \
-e SONARR_API_KEY="<your_api_key>" \
-e SONARR_SERIES_ID="187" \
-e AFL_ANIME_NAME="one-piece" \
-e PLEX_URL="http://127.0.0.1:32400" \
-e PLEX_TOKEN="<your_plex_token>" \
-e CREATE_PLEX_COLLECTION="True" \
-e MONITOR_NON_FILLER_SONARR_EPISODES="True" \
-e PLEX_ANIME_LIBRARY="<your_plex_anime_library>" \
ghcr.io/chkpwd/sofe:latest
```
Alternatively, create docker-compose.yml file with the following content:
```yaml
version: '3.8'
Expand All @@ -41,17 +49,18 @@ services:
ports:
- "7979:7979"
environment:
SONARR_SERIES_ID: 187
ANIME_NAME: "one-piece"
SONARR_API_KEY: "your_api_key"
SONARR_URL: "https://sonarr.local"
SONARR_API_KEY: "<your_api_key>"
SONARR_SERIES_ID: "187"
AFL_ANIME_NAME: "one-piece"
PLEX_URL: "http://127.0.0.1:32400"
PLEX_TOKEN: "<your_plex_token>"
CREATE_PLEX_COLLECTION: "True"
MONITOR_NON_FILLER_SONARR_EPISODES: "True"
PLEX_ANIME_LIBRARY: "<your_plex_anime_library>"
```
Then run with:
```sh
docker-compose up -d
```
Accessing Data (Not done yet)

With the container running, you can access the exposed metrics by navigating to http://localhost:5000/fillers in your web browser or using a tool like curl:
```sh
curl http://<ip-address>:5000/fillers
```
4 changes: 2 additions & 2 deletions app/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import requests


def get_anime_filler_list(anime_name: str):
def get_anime_filler_list(afl_anime_name: str):
"""Get the anime filler list."""

base_url = f"https://www.animefillerlist.com/shows/{anime_name}/"
base_url = f"https://www.animefillerlist.com/shows/{afl_anime_name}/"
url = f"{base_url}"
data = html.fromstring(requests.get(url).content)
filler_ranges = data.xpath(
Expand Down
3 changes: 2 additions & 1 deletion app/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

plex = PlexServer(baseurl=var.plex_url, token=var.plex_token)


def create_plex_collection(sonarr_episodes: list[int], fillers: list[int] = []):
nonfillers_items: list[Episode] = []
fillers_items: list[Episode] = []

media: ShowSection = plex.library.section(title=var.plex_anime_library)

shows: MediaContainer = media.search(title=var.anime_name)
shows: MediaContainer = media.search(title=var.afl_anime_name)

for show in shows:
plex_episodes: list[Episode] = show.episodes()
Expand Down
28 changes: 12 additions & 16 deletions constants/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Attributes:
listen_address (str): The IP address to listen on. Defaults to 0.0.0.0.
listen_port (int): The port to listen on. Defaults to 7979.
anime_name (str): The name of the anime to fetch filler episodes for.
afl_anime_name (str): The name of the anime to fetch filler episodes for.
sonarr_url (str): The URL of the Sonarr server.
sonarr_series_id (int): The ID of the Sonarr series to update.
sonarr_api_key (str): The API key for the Sonarr server.
Expand All @@ -31,28 +31,24 @@ class UserConfig:
"""Configuration constants for the application."""

def __init__(self):
self.listen_address: str = self._get_env_var(
"ADDRESS", default="0.0.0.0"
)
self.listen_port: int = int(self._get_env_var(
"PORT", default="7979"
))
self.anime_name: str = self._get_env_var("ANIME_NAME", required=True)
self.listen_address: str = self._get_env_var("ADDRESS", default="0.0.0.0")
self.listen_port: int = int(self._get_env_var("PORT", default="7979"))
self.afl_anime_name: str = self._get_env_var("AFL_ANIME_NAME", required=True)
self.sonarr_url: str = self._get_env_var("SONARR_URL", required=True)
self.sonarr_series_id: int = int(self._get_env_var(
"SONARR_SERIES_ID", required=True, default=""
))
self.sonarr_series_id: int = int(
self._get_env_var("SONARR_SERIES_ID", required=True, default="")
)
self.sonarr_api_key: str = self._get_env_var("SONARR_API_KEY", required=True)
self.monitor_non_filler_sonarr_episodes: bool = bool(
self._get_env_var("MONITOR_NON_FILLER_SONARR_EPISODES", default=""
))
self._get_env_var("MONITOR_NON_FILLER_SONARR_EPISODES", default="")
)
self.plex_url: str = self._get_env_var("PLEX_URL")
self.plex_token: str = self._get_env_var(
"PLEX_TOKEN", required=bool(self.plex_url)
)
self.create_plex_collection: bool = bool(self._get_env_var(
"CREATE_PLEX_COLLECTION", default=""
))
self.create_plex_collection: bool = bool(
self._get_env_var("CREATE_PLEX_COLLECTION", default="")
)
self.plex_anime_library: str = self._get_env_var("PLEX_ANIME_LIBRARY")

@staticmethod
Expand Down
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
logging.info("Address is set to '%s'", var.listen_address)
logging.info("Port is set to '%s'", var.listen_port)

fillers_from_api = get_anime_filler_list(var.anime_name)
fillers_from_api = get_anime_filler_list(var.afl_anime_name)
sonarr_episodes_id = get_sonarr_episodes(int(var.sonarr_series_id))

if var.create_plex_collection is True:
create_plex_collection(sonarr_episodes=sonarr_episodes_id, fillers=fillers_from_api)
create_plex_collection(
sonarr_episodes=sonarr_episodes_id, fillers=fillers_from_api
)

for episode in sonarr_episodes_id:
if episode['episode_number'] not in fillers_from_api:
episodes_to_monitor.append(episode.get('id'))
if episode["episode_number"] not in fillers_from_api:
episodes_to_monitor.append(episode.get("id"))

logging.debug("Non-Filler Episodes: %s", episodes_to_monitor)

Expand Down

0 comments on commit 745fbac

Please sign in to comment.