diff --git a/backend/src/torrent/router.py b/backend/src/torrent/router.py index 900c9fb..aa7d504 100644 --- a/backend/src/torrent/router.py +++ b/backend/src/torrent/router.py @@ -16,7 +16,7 @@ def get_torrent(service: TorrentServiceDependency, torrent_id: TorrentId): @router.get("/", status_code=status.HTTP_200_OK, dependencies=[Depends(current_active_user)], response_model=list[Torrent]) -def get_all_torrents(service: TorrentServiceDependency, ): +def get_all_torrents(service: TorrentServiceDependency): return service.get_all_torrents() diff --git a/backend/src/tv/models.py b/backend/src/tv/models.py index d721649..a734932 100644 --- a/backend/src/tv/models.py +++ b/backend/src/tv/models.py @@ -74,3 +74,6 @@ class SeasonRequest(Base): season_id: Mapped[UUID] = mapped_column(ForeignKey(column="season.id", ondelete="CASCADE"), ) wanted_quality: Mapped[Quality] min_quality: Mapped[Quality] + requested_by: Mapped[UUID | None] = mapped_column(ForeignKey(column="user.id", ondelete="SET NULL"), ) + authorized: Mapped[bool] = mapped_column(default=False) + authorized_by: Mapped[UUID | None] = mapped_column(ForeignKey(column="user.id", ondelete="SET NULL"), ) diff --git a/backend/src/tv/router.py b/backend/src/tv/router.py index ce54b9c..f17a087 100644 --- a/backend/src/tv/router.py +++ b/backend/src/tv/router.py @@ -63,7 +63,12 @@ def get_shows_with_torrents(db: DbSessionDependency): @router.get("/shows/{show_id}", dependencies=[Depends(current_active_user)], response_model=PublicShow) def get_a_show(db: DbSessionDependency, show_id: ShowId): - return tv.service.get_show_by_id(db=db, show_id=show_id) + return tv.service.get_public_show_by_id(db=db, show_id=show_id) + + +@router.get("/shows/{show_id}/torrents", dependencies=[Depends(current_active_user)], response_model=RichShowTorrent) +def get_a_shows_torrents(db: DbSessionDependency, show_id: ShowId): + return tv.service.get_torrents_for_show(db=db, show=tv.service.get_show_by_id(db=db, show_id=show_id)) @router.get("/shows/{show_id}/{season_number}/files", status_code=status.HTTP_200_OK, @@ -107,7 +112,7 @@ def unrequest_season(db: DbSessionDependency, request: SeasonRequest): # -------------------------------- # 1 is the default for season_number because it returns multi season torrents -@router.get("/torrents", status_code=status.HTTP_200_OK, dependencies=[Depends(current_active_user)], +@router.get("/torrents", status_code=status.HTTP_200_OK, dependencies=[Depends(current_superuser)], response_model=list[PublicIndexerQueryResult]) def get_torrents_for_a_season(db: DbSessionDependency, show_id: ShowId, season_number: int = 1, search_query_override: str = None): diff --git a/backend/src/tv/service.py b/backend/src/tv/service.py index 3251180..005683b 100644 --- a/backend/src/tv/service.py +++ b/backend/src/tv/service.py @@ -50,6 +50,7 @@ def get_public_season_files_by_season_number(db: Session, season_number: SeasonN season = tv.repository.get_season_by_number(db=db, season_number=season_number, show_id=show_id) return get_public_season_files_by_season_id(db=db, season_id=season.id) + def check_if_show_exists(db: Session, external_id: int = None, metadata_provider: str = None, @@ -102,7 +103,7 @@ def search_for_show(query: str, metadata_provider: str, db: Session) -> list[Met return results -def get_show_by_id(db: Session, show_id: ShowId) -> PublicShow: +def get_public_show_by_id(db: Session, show_id: ShowId) -> PublicShow: show = tv.repository.get_show(show_id=show_id, db=db) seasons = [PublicSeason.model_validate(season) for season in show.seasons] for season in seasons: @@ -112,6 +113,9 @@ def get_show_by_id(db: Session, show_id: ShowId) -> PublicShow: return public_show +def get_show_by_id(db: Session, show_id: ShowId) -> Show: + return tv.repository.get_show(show_id=show_id, db=db) + def is_season_downloaded(db: Session, season_id: SeasonId) -> bool: season_files = get_season_files_by_season_id(db=db, season_id=season_id) for season_file in season_files: @@ -144,35 +148,36 @@ def get_all_requested_seasons(db: Session) -> list[SeasonRequest]: return tv.repository.get_season_requests(db=db) +def get_torrents_for_show(db: Session, show: Show) -> RichShowTorrent: + show_torrents = tv.repository.get_torrents_by_show_id(db=db, show_id=show.id) + rich_season_torrents = [] + for show_torrent in show_torrents: + seasons = tv.repository.get_seasons_by_torrent_id(db=db, torrent_id=show_torrent.id) + season_files = get_seasons_files_of_torrent(db=db, torrent_id=show_torrent.id) + file_path_suffix = season_files[0].file_path_suffix + season_torrent = RichSeasonTorrent(torrent_id=show_torrent.id, torrent_title=show_torrent.title, + status=show_torrent.status, quality=show_torrent.quality, + imported=show_torrent.imported, seasons=seasons, + file_path_suffix=file_path_suffix + ) + rich_season_torrents.append(season_torrent) + return RichShowTorrent(show_id=show.id, name=show.name, year=show.year, + metadata_provider=show.metadata_provider, torrents=rich_season_torrents) + + def get_all_shows_with_torrents(db: Session) -> list[RichShowTorrent]: shows = tv.repository.get_all_shows_with_torrents(db=db) - result = [] - for show in shows: - show_torrents = tv.repository.get_torrents_by_show_id(db=db, show_id=show.id) - rich_season_torrents = [] - for torrent in show_torrents: - seasons = tv.repository.get_seasons_by_torrent_id(db=db, torrent_id=torrent.id) - season_files = get_seasons_files_of_torrent(db=db, torrent_id=torrent.id) - file_path_suffix = season_files[0].file_path_suffix - season_torrent = RichSeasonTorrent(torrent_id=torrent.id, torrent_title=torrent.title, - status=torrent.status, quality=torrent.quality, - imported=torrent.imported, seasons=seasons, - file_path_suffix=file_path_suffix - ) - rich_season_torrents.append(season_torrent) - result.append(RichShowTorrent(show_id=show.id, name=show.name, year=show.year, - metadata_provider=show.metadata_provider, torrents=rich_season_torrents)) - return result + return [get_torrents_for_show(show=show, db=db) for show in shows] def download_torrent(db: Session, public_indexer_result_id: IndexerQueryResultId, show_id: ShowId, override_show_file_path_suffix: str = "") -> Torrent: indexer_result = indexer.service.get_indexer_query_result(db=db, result_id=public_indexer_result_id) - torrent = TorrentService(db=db).download(indexer_result=indexer_result) + show_torrent = TorrentService(db=db).download(indexer_result=indexer_result) for season_number in indexer_result.season: season = tv.repository.get_season_by_number(db=db, season_number=season_number, show_id=show_id) - season_file = SeasonFile(season_id=season.id, quality=indexer_result.quality, torrent_id=torrent.id, + season_file = SeasonFile(season_id=season.id, quality=indexer_result.quality, torrent_id=show_torrent.id, file_path_suffix=override_show_file_path_suffix) add_season_file(db=db, season_file=season_file) - return torrent + return show_torrent diff --git a/web/src/app.html b/web/src/app.html index 0a61570..da99290 100644 --- a/web/src/app.html +++ b/web/src/app.html @@ -7,6 +7,8 @@ %sveltekit.head%
-