Skip to content

Commit

Permalink
print/discord notifications and blackhole watcher startup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
westsurname authored May 30, 2024
1 parent 5314ca5 commit a426485
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 126 deletions.
24 changes: 24 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@ SONARR_HOST=<sonarr_host>
SONARR_API_KEY=<sonarr_api_key>
SONARR_ROOT_FOLDER=<sonarr_root_folder>

SONARR_HOST_4K=<sonarr_host_4k>
SONARR_API_KEY_4K=<sonarr_api_key_4k>
SONARR_ROOT_FOLDER_4K=<sonarr_root_folder_4k>

SONARR_HOST_ANIME=<sonarr_host_anime>
SONARR_API_KEY_ANIME=<sonarr_api_key_anime>
SONARR_ROOT_FOLDER_ANIME=<sonarr_root_folder_anime>

SONARR_HOST_MUX=<sonarr_host_mux>
SONARR_API_KEY_MUX=<sonarr_api_key_mux>
SONARR_ROOT_FOLDER_MUX=<sonarr_root_folder_mux>

RADARR_HOST=<radarr_host>
RADARR_API_KEY=<radarr_api_key>
RADARR_ROOT_FOLDER=<radarr_root_folder>

RADARR_HOST_4K=<radarr_host_4k>
RADARR_API_KEY_4K=<radarr_api_key_4k>
RADARR_ROOT_FOLDER_4K=<radarr_root_folder_4k>

RADARR_HOST_ANIME=<radarr_host_anime>
RADARR_API_KEY_ANIME=<radarr_api_key_anime>
RADARR_ROOT_FOLDER_ANIME=<radarr_root_folder_anime>

RADARR_HOST_MUX=<radarr_host_mux>
RADARR_API_KEY_MUX=<radarr_api_key_mux>
RADARR_ROOT_FOLDER_MUX=<radarr_root_folder_mux>

TAUTULLI_HOST=<tautulli_host>
TAUTULLI_API_KEY=<tautulli_api_key>

Expand Down
10 changes: 4 additions & 6 deletions blackhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ def print(*values: object):
items = [item for item in history if item['data'].get('torrentInfoHash', '').casefold() == torrentHash.casefold() or cleanFileName(item['sourceTitle'].casefold()) == torrent.file.fileInfo.filenameWithoutExt.casefold()]

if not items:
raise Exception("No history items found to cancel")

message = "No history items found to mark as failed. Arr will not attempt to grab an alternative."
print(message)
discordError(message, torrent.file.fileInfo.filenameWithoutExt)
for item in items:
# TODO: See if we can fail without blacklisting as cached items constantly changes
arr.failHistoryItem(item['id'])
Expand Down Expand Up @@ -372,8 +373,5 @@ async def on_created(isRadarr):
discordError(f"Error processing", e)
print("Exit 'on_created'")

def start(isRadarr):
asyncio.run(on_created(isRadarr))

if __name__ == "__main__":
start(isRadarr=sys.argv[1] == 'radarr')
asyncio.run(on_created(isRadarr=sys.argv[1] == 'radarr'))
54 changes: 32 additions & 22 deletions blackhole_watcher.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
import asyncio
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from blackhole import start, getPath
from blackhole import on_created, getPath

class BlackholeHandler(FileSystemEventHandler):
def __init__(self, is_radarr):
super().__init__()
self.is_radarr = is_radarr
self.path_name = getPath(is_radarr, create=True)

def on_created(self, event=None):
if not event or (not event.is_directory and event.src_path.lower().endswith((".torrent", ".magnet"))):
start(self.is_radarr)
def on_created(self, event):
if not event.is_directory and event.src_path.lower().endswith((".torrent", ".magnet")):
asyncio.run(on_created(self.is_radarr))

if __name__ == "__main__":
print("Watching blackhole")
async def on_created(self):
await on_created(self.is_radarr)

async def main():
print("Watching blackhole")

radarr_handler = BlackholeHandler(is_radarr=True)
sonarr_handler = BlackholeHandler(is_radarr=False)
radarr_handler = BlackholeHandler(is_radarr=True)
sonarr_handler = BlackholeHandler(is_radarr=False)

radarr_handler.on_created()
sonarr_handler.on_created()
radarr_observer = Observer()
radarr_observer.schedule(radarr_handler, radarr_handler.path_name)

radarr_observer = Observer()
radarr_observer.schedule(radarr_handler, radarr_handler.path_name)
sonarr_observer = Observer()
sonarr_observer.schedule(sonarr_handler, sonarr_handler.path_name)

sonarr_observer = Observer()
sonarr_observer.schedule(sonarr_handler, sonarr_handler.path_name)
try:
radarr_observer.start()
sonarr_observer.start()

await asyncio.gather(
radarr_handler.on_created(),
sonarr_handler.on_created()
)
except KeyboardInterrupt:
radarr_observer.stop()
sonarr_observer.stop()

try:
radarr_observer.start()
sonarr_observer.start()
except KeyboardInterrupt:
radarr_observer.stop()
sonarr_observer.stop()
radarr_observer.join()
sonarr_observer.join()

radarr_observer.join()
sonarr_observer.join()

if __name__ == "__main__":
asyncio.run(main())
183 changes: 94 additions & 89 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ x-blackhole: &blackhole
context: .
dockerfile: Dockerfile.blackhole
image: ghcr.io/westsurname/scripts/blackhole:latest
pull_policy: always
user: "${PUID:-}${PGID:+:${PGID}}"
env_file:
- .env
Expand All @@ -13,6 +14,7 @@ x-repair: &repair
context: .
dockerfile: Dockerfile.scripts
image: ghcr.io/westsurname/scripts/scripts:latest
pull_policy: always
command: python repair.py --no-confirm
env_file:
- .env
Expand All @@ -25,121 +27,122 @@ services:
environment:
- BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
profiles: [blackhole, blackhole_all, all]

# blackhole_4k:
# <<: *blackhole
# container_name: blackhole_4k_service
# environment:
# - SONARR_HOST=${SONARR_HOST_4K}
# - SONARR_API_KEY=${SONARR_API_KEY_4K}
# - RADARR_HOST=${RADARR_HOST_4K}
# - RADARR_API_KEY=${RADARR_API_KEY_4K}
# - BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
# volumes:
# - ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH} 4k:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
# - ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH} 4k:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
# profiles: [blackhole_4k, blackhole_all, all]
blackhole_4k:
<<: *blackhole
container_name: blackhole_4k_service
environment:
- SONARR_HOST=${SONARR_HOST_4K}
- SONARR_API_KEY=${SONARR_API_KEY_4K}
- RADARR_HOST=${RADARR_HOST_4K}
- RADARR_API_KEY=${RADARR_API_KEY_4K}
- BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH} 4k:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH} 4k:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
profiles: [blackhole_4k, blackhole_all, all]

# blackhole_anime:
# <<: *blackhole
# container_name: blackhole_anime_service
# environment:
# - SONARR_HOST=${SONARR_HOST_ANIME}
# - SONARR_API_KEY=${SONARR_API_KEY_ANIME}
# - RADARR_HOST=${RADARR_HOST_ANIME}
# - RADARR_API_KEY=${RADARR_API_KEY_ANIME}
# - BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
# volumes:
# - ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH} anime:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
# - ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH} anime:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
# profiles: [blackhole_anime, blackhole_all, all]
blackhole_anime:
<<: *blackhole
container_name: blackhole_anime_service
environment:
- SONARR_HOST=${SONARR_HOST_ANIME}
- SONARR_API_KEY=${SONARR_API_KEY_ANIME}
- RADARR_HOST=${RADARR_HOST_ANIME}
- RADARR_API_KEY=${RADARR_API_KEY_ANIME}
- BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH} anime:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH} anime:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
profiles: [blackhole_anime, blackhole_all, all]

# blackhole_mux:
# <<: *blackhole
# container_name: blackhole_mux_service
# environment:
# - SONARR_HOST=${SONARR_HOST_MUX}
# - SONARR_API_KEY=${SONARR_API_KEY_MUX}
# - RADARR_HOST=${RADARR_HOST_MUX}
# - RADARR_API_KEY=${RADARR_API_KEY_MUX}
# - BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
# volumes:
# - ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH} mux:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
# - ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH} mux:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
# profiles: [blackhole_mux, blackhole_all, all]
blackhole_mux:
<<: *blackhole
container_name: blackhole_mux_service
environment:
- SONARR_HOST=${SONARR_HOST_MUX}
- SONARR_API_KEY=${SONARR_API_KEY_MUX}
- RADARR_HOST=${RADARR_HOST_MUX}
- RADARR_API_KEY=${RADARR_API_KEY_MUX}
- BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH} mux:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_SONARR_PATH}
- ${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH} mux:/${BLACKHOLE_BASE_WATCH_PATH}/${BLACKHOLE_RADARR_PATH}
profiles: [blackhole_mux, blackhole_all, all]

repair_service:
<<: *repair
container_name: repair_service
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${SONARR_ROOT_FOLDER}:${SONARR_ROOT_FOLDER}
- ${RADARR_ROOT_FOLDER}:${RADARR_ROOT_FOLDER}
profiles: [repair, repair_all, all]

# repair_4k:
# <<: *repair
# container_name: repair_4k_service
# environment:
# - SONARR_HOST=${SONARR_HOST_4K}
# - SONARR_API_KEY=${SONARR_API_KEY_4K}
# - RADARR_HOST=${RADARR_HOST_4K}
# - RADARR_API_KEY=${RADARR_API_KEY_4K}
# volumes:
# - ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${SONARR_ROOT_FOLDER_4K}:${SONARR_ROOT_FOLDER}
# - ${RADARR_ROOT_FOLDER_4K}:${RADARR_ROOT_FOLDER}
# profiles: [repair_4k, repair_all, all]
repair_4k:
<<: *repair
container_name: repair_4k_service
environment:
- SONARR_HOST=${SONARR_HOST_4K}
- SONARR_API_KEY=${SONARR_API_KEY_4K}
- RADARR_HOST=${RADARR_HOST_4K}
- RADARR_API_KEY=${RADARR_API_KEY_4K}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${SONARR_ROOT_FOLDER_4K}:${SONARR_ROOT_FOLDER}
- ${RADARR_ROOT_FOLDER_4K}:${RADARR_ROOT_FOLDER}
profiles: [repair_4k, repair_all, all]

# repair_anime:
# <<: *repair
# container_name: repair_anime_service
# environment:
# - SONARR_HOST=${SONARR_HOST_ANIME}
# - SONARR_API_KEY=${SONARR_API_KEY_ANIME}
# - RADARR_HOST=${RADARR_HOST_ANIME}
# - RADARR_API_KEY=${RADARR_API_KEY_ANIME}
# volumes:
# - ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${SONARR_ROOT_FOLDER_ANIME}:${SONARR_ROOT_FOLDER}
# - ${RADARR_ROOT_FOLDER_ANIME}:${RADARR_ROOT_FOLDER}
# profiles: [repair_anime, repair_all, all]
repair_anime:
<<: *repair
container_name: repair_anime_service
environment:
- SONARR_HOST=${SONARR_HOST_ANIME}
- SONARR_API_KEY=${SONARR_API_KEY_ANIME}
- RADARR_HOST=${RADARR_HOST_ANIME}
- RADARR_API_KEY=${RADARR_API_KEY_ANIME}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${SONARR_ROOT_FOLDER_ANIME}:${SONARR_ROOT_FOLDER}
- ${RADARR_ROOT_FOLDER_ANIME}:${RADARR_ROOT_FOLDER}
profiles: [repair_anime, repair_all, all]

# repair_mux:
# <<: *repair
# container_name: repair_mux_service
# environment:
# - SONARR_HOST=${SONARR_HOST_MUX}
# - SONARR_API_KEY=${SONARR_API_KEY_MUX}
# - RADARR_HOST=${RADARR_HOST_MUX}
# - RADARR_API_KEY=${RADARR_API_KEY_MUX}
# volumes:
# - ${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}:${REALDEBRID_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
# - ${SONARR_ROOT_FOLDER_MUX}:${SONARR_ROOT_FOLDER}
# - ${RADARR_ROOT_FOLDER_MUX}:${RADARR_ROOT_FOLDER}
# profiles: [repair_mux, repair_all, all]
repair_mux:
<<: *repair
container_name: repair_mux_service
environment:
- SONARR_HOST=${SONARR_HOST_MUX}
- SONARR_API_KEY=${SONARR_API_KEY_MUX}
- RADARR_HOST=${RADARR_HOST_MUX}
- RADARR_API_KEY=${RADARR_API_KEY_MUX}
volumes:
- ${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}:${REALDEBRID_MOUNT_TORRENTS_PATH:-${BLACKHOLE_RD_MOUNT_TORRENTS_PATH:-/dev/null}}
- ${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}:${TORBOX_MOUNT_TORRENTS_PATH:-/dev/null}
- ${SONARR_ROOT_FOLDER_MUX}:${SONARR_ROOT_FOLDER}
- ${RADARR_ROOT_FOLDER_MUX}:${RADARR_ROOT_FOLDER}
profiles: [repair_mux, repair_all, all]

watchlist:
build:
context: .
dockerfile: Dockerfile.watchlist
container_name: watchlist_service
image: ghcr.io/westsurname/scripts/watchlist:latest
pull_policy: always
volumes:
- ./shared/tokens.json:/app/shared/tokens.json
env_file:
Expand All @@ -153,6 +156,7 @@ services:
dockerfile: Dockerfile.plex_authentication
container_name: plex_authentication_service
image: ghcr.io/westsurname/scripts/plex_authentication:latest
pull_policy: always
volumes:
- ./shared/tokens.json:/app/shared/tokens.json
ports:
Expand All @@ -170,6 +174,7 @@ services:
dockerfile: Dockerfile.plex_request
container_name: plex_request_service
image: ghcr.io/westsurname/scripts/plex_request:latest
pull_policy: always
volumes:
- ./shared/tokens.json:/app/shared/tokens.json
ports:
Expand Down
Loading

0 comments on commit a426485

Please sign in to comment.