Skip to content

Commit

Permalink
chore: sorted imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Sep 21, 2024
1 parent dca7f48 commit 6cb5c1f
Show file tree
Hide file tree
Showing 53 changed files with 228 additions and 161 deletions.
9 changes: 3 additions & 6 deletions src/controllers/default.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import time

import program.db.db_functions as DB
import requests
from fastapi import APIRouter, HTTPException, Request
from loguru import logger
from sqlalchemy import func, select

from program.content.trakt import TraktContent
from program.db.db import db
from program.media.item import Episode, MediaItem, Movie, Season, Show
from program.media.state import States
from program.scrapers import Scraping
from program.settings.manager import settings_manager
from sqlalchemy import func, select
from loguru import logger

router = APIRouter(
responses={404: {"description": "Not found"}},
Expand Down
15 changes: 10 additions & 5 deletions src/controllers/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

import Levenshtein
from fastapi import APIRouter, HTTPException, Request
from sqlalchemy import func, select
from sqlalchemy.exc import NoResultFound

from program.content import Overseerr
from program.db.db import db
from program.db.db_functions import clear_streams, get_media_items_by_ids, delete_media_item, reset_media_item, get_parent_items_by_ids
from program.media.item import MediaItem, Season
from program.db.db_functions import (
clear_streams,
delete_media_item,
get_media_items_by_ids,
get_parent_items_by_ids,
reset_media_item,
)
from program.media.item import MediaItem
from program.media.state import States
from sqlalchemy import delete, func, select
from sqlalchemy.orm import joinedload
from sqlalchemy.exc import NoResultFound
from program.symlink import Symlinker
from utils.logger import logger

Expand Down
14 changes: 11 additions & 3 deletions src/controllers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from typing import Any, Dict, List

from fastapi import APIRouter, HTTPException
from program.settings.manager import settings_manager
from pydantic import BaseModel, ValidationError
from RTN.models import SettingsModel

from program.settings.manager import settings_manager


class SetSettings(BaseModel):
Expand All @@ -23,8 +25,14 @@ async def get_settings_schema():
"""
Get the JSON schema for the settings.
"""
schema = settings_manager.schema
return schema
return settings_manager.schema

@router.get("/ranking")
async def get_ranking_schema():
"""
Get the JSON schema for the ranking.
"""
return SettingsModel.model_json_schema()

@router.get("/load")
async def load_settings():
Expand Down
1 change: 1 addition & 0 deletions src/controllers/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urlencode

from fastapi import APIRouter, Depends

from program.indexers.tmdb import tmdb

router = APIRouter(
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import pydantic
from fastapi import APIRouter, Request
from requests import RequestException

from program.content.overseerr import Overseerr
from program.db.db_functions import _ensure_item_exists_in_db
from program.indexers.trakt import get_imdbid_from_tmdb, get_imdbid_from_tvdb
from program.media.item import MediaItem
from requests import RequestException
from utils.logger import logger
from program.db.db_functions import _ensure_item_exists_in_db

from .models.overseerr import OverseerrWebhook

Expand Down
3 changes: 3 additions & 0 deletions src/controllers/ws.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from fastapi import WebSocket

from utils.websockets import manager

from .default import router


@router.websocket("/")
async def websocket_endpoint(websocket: WebSocket):
await manager.connect(websocket)
Expand Down
12 changes: 6 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import traceback

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request

from controllers.default import router as default_router
from controllers.items import router as items_router
from controllers.ws import router as ws_router

from controllers.settings import router as settings_router
from controllers.tmdb import router as tmdb_router
from controllers.webhooks import router as webhooks_router
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from controllers.ws import router as ws_router
from program import Program
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from program.settings.models import get_version
from utils.cli import handle_args
from utils.logger import logger
Expand Down
5 changes: 3 additions & 2 deletions src/program/content/listrr.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Listrr content module"""
from typing import Generator

from requests.exceptions import HTTPError

from program.db.db_functions import _filter_existing_items
from program.indexers.trakt import get_imdbid_from_tmdb
from program.media.item import MediaItem
from program.settings.manager import settings_manager
from requests.exceptions import HTTPError
from utils.logger import logger
from utils.request import get, ping
from program.db.db_functions import _filter_existing_items


class Listrr:
Expand Down
2 changes: 1 addition & 1 deletion src/program/content/mdblist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from typing import Generator

from program.db.db_functions import _filter_existing_items
from program.media.item import MediaItem
from program.settings.manager import settings_manager
from utils.logger import logger
from utils.ratelimiter import RateLimiter, RateLimitExceeded
from utils.request import get, ping
from program.db.db_functions import _filter_existing_items


class Mdblist:
Expand Down
7 changes: 4 additions & 3 deletions src/program/content/overseerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from typing import Union

from requests.exceptions import ConnectionError, RetryError
from urllib3.exceptions import MaxRetryError, NewConnectionError

from program.db.db_functions import _filter_existing_items
from program.indexers.trakt import get_imdbid_from_tmdb
from program.media.item import MediaItem
from program.settings.manager import settings_manager
from requests.exceptions import ConnectionError, RetryError
from urllib3.exceptions import MaxRetryError, NewConnectionError
from utils.logger import logger
from utils.request import delete, get, ping, post
from program.db.db_functions import _filter_existing_items


class Overseerr:
Expand Down
8 changes: 4 additions & 4 deletions src/program/content/plex_watchlist.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Plex Watchlist Module"""
from typing import Generator, Union

from plexapi.myplex import MyPlexAccount
from requests import HTTPError, Session

from program.db.db_functions import _filter_existing_items
from program.media.item import Episode, MediaItem, Movie, Season, Show
from program.settings.manager import settings_manager
from requests import HTTPError
from utils.logger import logger
from utils.request import get, ping
from plexapi.myplex import MyPlexAccount
from requests import Session
from program.db.db_functions import _filter_existing_items


class PlexWatchlist:
Expand Down
5 changes: 3 additions & 2 deletions src/program/content/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from typing import Union
from urllib.parse import urlencode

from requests import RequestException

from program.db.db_functions import _filter_existing_items
from program.media.item import MediaItem
from program.settings.manager import settings_manager
from requests import RequestException
from utils.logger import logger
from utils.ratelimiter import RateLimiter
from utils.request import get, post
from program.db.db_functions import _filter_existing_items


class TraktContent:
Expand Down
2 changes: 1 addition & 1 deletion src/program/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from alembic.autogenerate import compare_metadata
from alembic.runtime.migration import MigrationContext
from sqla_wrapper import Alembic, SQLAlchemy
from sqlalchemy import text

from program.settings.manager import settings_manager
from sqla_wrapper import Alembic, SQLAlchemy
from utils import data_dir_path
from utils.logger import logger

Expand Down
27 changes: 14 additions & 13 deletions src/program/db/db_functions.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import os
import shutil
from typing import List, TYPE_CHECKING
from typing import TYPE_CHECKING, List

import alembic
from sqlalchemy import delete, exists, func, insert, select, text, union_all
from sqlalchemy.orm import Session, aliased, joinedload

from program.media.stream import Stream, StreamRelation, StreamBlacklistRelation
from sqlalchemy import delete, func, select, text, union_all, exists, insert
from sqlalchemy.orm import joinedload, aliased, Session
from utils.logger import logger
from utils import alembic_dir
from program.libraries.symlink import fix_broken_symlinks
from program.media.stream import Stream, StreamBlacklistRelation, StreamRelation
from program.settings.manager import settings_manager
from .db import db, alembic
from utils import alembic_dir
from utils.logger import logger

from .db import alembic, db

if TYPE_CHECKING:
from program.media.item import MediaItem

def get_media_items_by_ids(media_item_ids: list[int]):
"""Retrieve multiple MediaItems by a list of MediaItem _ids using the _get_item_from_db method."""
from program.media.item import Movie, Show, Season, Episode, MediaItem
from program.media.item import Episode, MediaItem, Movie, Season, Show
items = []

with db.Session() as session:
Expand Down Expand Up @@ -221,7 +222,7 @@ def load_streams_in_pages(session: Session, media_item_id: int, page_number: int
yield stream_id, infohash, stream

def _get_item_ids(session, item):
from program.media.item import Season, Episode
from program.media.item import Episode, Season
if item.type == "show":
show_id = item._id

Expand Down Expand Up @@ -281,7 +282,7 @@ def _get_item_type_from_db(item: "MediaItem") -> str:
return session.execute(select(MediaItem.type).where(MediaItem._id==item._id)).scalar_one()

def _store_item(item: "MediaItem"):
from program.media.item import Movie, Show, Season, Episode
from program.media.item import Episode, Movie, Season, Show
if isinstance(item, (Movie, Show, Season, Episode)) and item._id is not None:
with db.Session() as session:
item.store_state()
Expand All @@ -298,7 +299,7 @@ def _imdb_exists_in_db(imdb_id: str) -> bool:
return session.execute(select(func.count(MediaItem._id)).where(MediaItem.imdb_id == imdb_id)).scalar_one() != 0

def _get_item_from_db(session, item: "MediaItem"):
from program.media.item import MediaItem, Movie, Show, Season, Episode
from program.media.item import Episode, MediaItem, Movie, Season, Show
if not _ensure_item_exists_in_db(item):
return None
session.expire_on_commit = False
Expand Down Expand Up @@ -335,7 +336,7 @@ def _get_item_from_db(session, item: "MediaItem"):
return None

def _check_for_and_run_insertion_required(session, item: "MediaItem") -> bool:
from program.media.item import Movie, Show, Season, Episode
from program.media.item import Episode, Movie, Season, Show
if not _ensure_item_exists_in_db(item) and isinstance(item, (Show, Movie, Season, Episode)):
item.store_state()
session.add(item)
Expand All @@ -345,7 +346,7 @@ def _check_for_and_run_insertion_required(session, item: "MediaItem") -> bool:
return False

def _run_thread_with_db_item(fn, service, program, input_item: "MediaItem" = None):
from program.media.item import MediaItem, Movie, Show, Season, Episode
from program.media.item import Episode, MediaItem, Movie, Season, Show
if input_item:
with db.Session() as session:
if isinstance(input_item, (Movie, Show, Season, Episode)):
Expand Down
7 changes: 4 additions & 3 deletions src/program/downloaders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from concurrent.futures import CancelledError, ThreadPoolExecutor, as_completed

from program.media.item import MediaItem
from utils.logger import logger
from program.settings.manager import settings_manager
from utils.logger import logger

from .alldebrid import AllDebridDownloader
from .realdebrid import RealDebridDownloader
from .torbox import TorBoxDownloader
from .shared import get_needed_media
from concurrent.futures import CancelledError, ThreadPoolExecutor, as_completed
from .torbox import TorBoxDownloader


class Downloader:
Expand Down
8 changes: 4 additions & 4 deletions src/program/downloaders/alldebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from types import SimpleNamespace
from typing import Generator, List

from requests import ConnectTimeout
from RTN.exceptions import GarbageTorrent
from RTN.extras import extract_episodes
from RTN.parser import parse
from sqlalchemy.orm import lazyload

from program.db.db import db
Expand All @@ -14,10 +18,6 @@
from program.media.state import States
from program.media.stream import Stream
from program.settings.manager import settings_manager
from requests import ConnectTimeout
from RTN.exceptions import GarbageTorrent
from RTN.parser import parse
from RTN.extras import extract_episodes
from utils.logger import logger
from utils.ratelimiter import RateLimiter
from utils.request import get, ping, post
Expand Down
11 changes: 7 additions & 4 deletions src/program/downloaders/realdebrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from datetime import datetime

from loguru import logger
from requests import ConnectTimeout
from program.media.item import MediaItem
from utils.ratelimiter import RateLimiter
from .shared import FileFinder, VIDEO_EXTENSIONS

import utils.request as request
from loguru import logger
from program.media.item import MediaItem
from program.settings.manager import settings_manager as settings
from utils.ratelimiter import RateLimiter

from .shared import VIDEO_EXTENSIONS, FileFinder

BASE_URL = "https://api.real-debrid.com/rest/1.0"

Expand Down
1 change: 0 additions & 1 deletion src/program/downloaders/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from program.media.state import States
from program.settings.manager import settings_manager


DEFAULT_VIDEO_EXTENSIONS = ["mp4", "mkv", "avi"]
ALLOWED_VIDEO_EXTENSIONS = ["mp4", "mkv", "avi", "mov", "wmv", "flv", "m4v", "webm", "mpg", "mpeg", "m2ts", "ts"]

Expand Down
9 changes: 5 additions & 4 deletions src/program/downloaders/torbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
from posixpath import splitext
from typing import Generator

from requests import ConnectTimeout
from RTN import parse
from RTN.exceptions import GarbageTorrent

from program.db.db import db
from program.db.db_functions import load_streams_in_pages, get_stream_count
from program.db.db_functions import get_stream_count, load_streams_in_pages
from program.media.item import MediaItem
from program.media.state import States
from program.media.stream import Stream
from program.settings.manager import settings_manager
from requests import ConnectTimeout
from RTN import parse
from RTN.exceptions import GarbageTorrent
from utils.logger import logger
from utils.request import get, post

Expand Down
Loading

0 comments on commit 6cb5c1f

Please sign in to comment.