Skip to content

Commit

Permalink
[sources] sachisource: share aiohttp session
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Jan 30, 2024
1 parent 4ca5b92 commit a7443b1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sachi

Sachi is a series and movie TUI renamer made with [Textual](https://github.com/textualize/textual/) which aims to replace FileBot.
Sachi is a TV Series and Movie TUI renamer made with [Textual](https://github.com/textualize/textual/).

## Getting Started

Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "sachi"
version = "0.1.0-dev"
description = ""
description = "Terminal media files renamer (FileBot alternative)"
authors = ["NextFire <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand All @@ -12,17 +12,17 @@ sachi = "sachi:cli_app"

[tool.poetry.dependencies]
python = "~3.12"
typer = {extras = ["all"], version = "^0.9.0"}
typer = { version = "^0.9.0", extras = ["all"] }
textual = "^0.47.1"
tomlkit = "^0.12.3"
pydantic = "^2.5.3"
aiohttp = {extras = ["speedups"], version = "^3.9.2"}
aiohttp = { version = "^3.9.2", extras = ["speedups"] }
yarl = "^1.9.4"
backoff = "^2.2.1"
jinja2 = "^3.1.3"
pymediainfo = "^6.1.0"
guessit = "^3.8.0"
setuptools = {version = "^69.0.3", markers = "python_version >= '3.12'"} # required for guessit
setuptools = { version = "^69.0.3", markers = "python_version >= '3.12'" } # guessit

[tool.poetry.group.dev.dependencies]
pyright = "^1.1.348"
Expand Down
8 changes: 2 additions & 6 deletions sachi/screens/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,12 @@ async def search(self, event: Input.Submitted):
return

self.sachi_source = select.value.get_instance()
async with self.sachi_source:
parents = await self.sachi_source.search(event.value)
parents = await self.sachi_source.search(event.value)
self.sachi_parent = await self.app.push_screen_wait(
ParentSelectionModal(parents)
)

async with self.sachi_source:
self.sachi_episodes = await self.sachi_source.get_episodes(
self.sachi_parent
)
self.sachi_episodes = await self.sachi_source.get_episodes(self.sachi_parent)

sel_list = self.query_one(SelectionList[int])
sel_list.clear_options()
Expand Down
9 changes: 7 additions & 2 deletions sachi/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from sachi.sources.base import SachiSource
from typing import TYPE_CHECKING

from sachi.sources.tvdb import TVDBSource

SOURCE_CLASSES: list[type[SachiSource]] = [
if TYPE_CHECKING:
from sachi.sources.base import SachiSource


SOURCE_CLASSES: list[type["SachiSource"]] = [
TVDBSource,
]
12 changes: 3 additions & 9 deletions sachi/sources/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import abstractmethod
from contextlib import AbstractAsyncContextManager
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import StrEnum
from typing import Self
Expand Down Expand Up @@ -28,17 +27,12 @@ class SachiEpisodeModel[RefIdType]:
name: str | None = None


class SachiSource[RefIdType](AbstractAsyncContextManager):
class SachiSource[RefIdType](ABC):
media_type: MediaType
service: str
_instance: Self | None = None

async def __aenter__(self) -> Self:
self.session = aiohttp.ClientSession(raise_for_status=True)
return self

async def __aexit__(self, *args, **kwargs):
await self.session.close()
session = aiohttp.ClientSession(raise_for_status=True)

@abstractmethod
async def search(self, query: str) -> list[SachiParentModel[RefIdType]]:
Expand Down

0 comments on commit a7443b1

Please sign in to comment.