Skip to content

Commit

Permalink
State machine improvements (#94)
Browse files Browse the repository at this point in the history
* A new look at state machine

* Include basic unittests for items controller

* lets not ignore test folders now

* Add extra details to /items. Minor tweaks here and there. Extra logging.

* Raise plex timeout to 60, same as pd. Move extra data to extended dict.

* Add Orionoid Scraper

* Fixed stream data

* Fix frontend CORS

* Apply black formatting to Orionoid

* realdebrid and state fixes

* Add support for multiple scrapers, disabled orionoid for now...

* Fix frontend after state changes

* Add missing files

* Workaround for quick shutdown, fixed ongoing season logic

* Couple minor tweaks. Orionoid still disabled for now.

---------

Co-authored-by: Gaisberg <None>
Co-authored-by: Spoked <Spoked@localhost>
  • Loading branch information
Gaisberg and Spoked authored Dec 28, 2023
1 parent de4c319 commit 2161e4f
Show file tree
Hide file tree
Showing 24 changed files with 1,462 additions and 1,226 deletions.
1 change: 0 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ __pycache__
settings.json
*.log
data
test*

# User-specific stuff
.idea/**/workspace.xml
Expand Down
3 changes: 1 addition & 2 deletions backend/controllers/default.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from fastapi import APIRouter, Request
from utils.settings import settings_manager
import requests
from program.debrid.realdebrid import get_user
from program.realdebrid import get_user


router = APIRouter(
Expand Down
4 changes: 2 additions & 2 deletions backend/controllers/items.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import APIRouter, HTTPException, Request
from program.media import MediaItemState
from program.media.state import MediaItemStates


router = APIRouter(
Expand All @@ -13,7 +13,7 @@
async def get_states(request: Request):
return {
"success": True,
"states": [state.name for state in MediaItemState],
"states": [state.name for state in MediaItemStates],
}


Expand Down
46 changes: 24 additions & 22 deletions backend/program/__init__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
"""Program main module"""
import os
import threading
import time
from typing import Optional
from pydantic import BaseModel, HttpUrl, Field
from program.symlink import Symlinker
from program.media.container import MediaItemContainer
from utils.logger import logger, get_data_path
from utils.settings import settings_manager
from program.media import MediaItemContainer
from program.libraries.plex import Library as Plex
from program.debrid.realdebrid import Debrid as RealDebrid
from program.plex import Plex
from program.plex import PlexConfig
from program.content import Content
from program.scrapers import Scraping
from utils.utils import Pickly


# Pydantic models for configuration
class PlexConfig(BaseModel):
user: str
token: str
address: HttpUrl
watchlist: Optional[HttpUrl] = None
import concurrent.futures


class MdblistConfig(BaseModel):
lists: list[str] = Field(default_factory=list)
api_key: str
api_key: Optional[str]
update_interval: int = 80


class OverseerrConfig(BaseModel):
url: HttpUrl
api_key: str
url: Optional[HttpUrl]
api_key: Optional[str]


class RealDebridConfig(BaseModel):
api_key: str
api_key: Optional[str]


class TorrentioConfig(BaseModel):
Expand All @@ -53,11 +43,13 @@ class Settings(BaseModel):
realdebrid: RealDebridConfig


class Program:
class Program(threading.Thread):
"""Program class"""

def __init__(self):
logger.info("Iceberg initializing...")
super().__init__(name="Iceberg")
self.running = False
self.settings = settings_manager.get_all()
self.media_items = MediaItemContainer(items=[])
self.data_path = get_data_path()
Expand All @@ -66,17 +58,27 @@ def __init__(self):
self.threads = [
Content(self.media_items), # Content must be first
Plex(self.media_items),
RealDebrid(self.media_items),
Symlinker(self.media_items),
Scraping(self.media_items),
]
logger.info("Iceberg initialized!")

def run(self):
while self.running:
with concurrent.futures.ThreadPoolExecutor(
max_workers=10, thread_name_prefix="Worker"
) as executor:
for item in self.media_items:
executor.submit(item.perform_action)
time.sleep(2)

def start(self):
self.running = True
super().start()
for thread in self.threads:
thread.start()

def stop(self):
for thread in self.threads:
thread.stop()
self.pickly.stop()
self.running = False
super().join()
3 changes: 1 addition & 2 deletions backend/program/content/mdblist.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Mdblist content module"""
import json
from utils.settings import settings_manager
from utils.logger import logger
from utils.request import RateLimitExceeded, RateLimiter, get, ping
from program.media import MediaItemContainer
from program.media.container import MediaItemContainer
from program.updaters.trakt import Updater as Trakt


Expand Down
2 changes: 1 addition & 1 deletion backend/program/content/overseerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from utils.settings import settings_manager
from utils.logger import logger
from utils.request import get, ping
from program.media import MediaItemContainer
from program.media.container import MediaItemContainer
from program.updaters.trakt import Updater as Trakt


Expand Down
6 changes: 3 additions & 3 deletions backend/program/content/plex_watchlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from utils.request import get, ping
from utils.logger import logger
from utils.settings import settings_manager as settings
from program.media import MediaItemContainer
from program.media.container import MediaItemContainer
from program.updaters.trakt import Updater as Trakt
import json

Expand All @@ -18,7 +18,7 @@ def __init__(self, media_items: MediaItemContainer):
self.previous_added_items_count = 0
if not self.watchlist_url or not self._validate_settings():
logger.info(
"Plex watchlist RSS URL is not configured and will not be used."
"Plex Watchlist is not configured and will not be used."
)
return
self.updater = Trakt()
Expand All @@ -28,7 +28,7 @@ def _validate_settings(self):
try:
response = ping(
self.watchlist_url,
timeout=5,
timeout=10,
)
return response.ok
except ConnectTimeout:
Expand Down
Loading

0 comments on commit 2161e4f

Please sign in to comment.