Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Readarr Integration #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions butlarr/config/services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import CONFIG
from ..services.radarr import Radarr
from ..services.sonarr import Sonarr
from ..services.readarr import Readarr

APIS = CONFIG["apis"]
SERVICES = []
Expand All @@ -26,5 +27,13 @@
api_key=api_config["api_key"]
)
)
elif service_type == "Readarr":
SERVICES.append(
Readarr(
commands=commands,
api_host=api_config["api_host"],
api_key=api_config["api_key"]
)
)
else:
assert False, "Unsupported service type!"
21 changes: 5 additions & 16 deletions butlarr/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ArrVariants(Enum):
UNSUPPORTED = None
RADARR = "movie"
SONARR = "series"
READARR = "book"


class ArrService(TelegramHandler):
Expand Down Expand Up @@ -71,20 +72,20 @@ def request(self, endpoint: str, *, action=Action.GET, params={}, fallback=None)
return r.json()
return r

def detect_api(self, api_host):
def detect_api(self, api_host, version="v3"):
status = None
# Detect version and api_url
try:
self.api_url = f"{api_host.rstrip('/')}/api/v3"
self.api_url = f"{api_host.rstrip('/')}/api/{version}"
status = self.request("system/status")
if not status:
self.api_url = f"{api_host.rstrip('/')}/api"
status = self.request("system/status")
assert not status, "By default only v3 ArrServices are supported"
assert not status, f"By default only a {version} service is supported"
finally:
if status is None:
logger.error(
"Could not reach compatible api. Is the service down? Is your API key correct?"
f"Could not reach compatible api at {api_host}. Is the service down? Is your API key correct?"
)
exit(1)
assert (
Expand Down Expand Up @@ -150,12 +151,6 @@ def add(
self,
*,
item=None,
root_folder_path: str = "",
quality_profile_id: str = "",
language_profile_id: str = "",
min_availability="released",
tags: List[str] = [],
monitored=True,
options={},
):
assert item, "Missing required arg! You need to provide a item!"
Expand All @@ -165,12 +160,6 @@ def add(
action=Action.POST,
params={
**item,
"qualityProfileId": quality_profile_id,
"languageProfileId": language_profile_id,
"rootFolderPath": root_folder_path,
"tags": tags,
"monitored": monitored,
"minimumAvailability": min_availability,
**options,
},
)
Expand Down
12 changes: 8 additions & 4 deletions butlarr/services/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,14 @@ async def clbk_update(self, update, context, args, state):
async def clbk_add(self, update, context, args, state):
result = self.add(
item=state.items[state.index],
quality_profile_id=state.quality_profile.get("id"),
root_folder_path=state.root_folder.get("path"),
tags=state.tags,
options={"addOptions": {"searchForMovie": args[1] == "search"}},
options={
"minimumAvailability": "released",
"monitored": True,
"qualityProfileId": state.quality_profile.get("id"),
"rootFolderPath": state.quality_profile.get("id"),
"tags": state.tags,
"addOptions": {"searchForMovie": args[1] == "search"},
},
)
if not result:
return Response(caption="Seems like something went wrong...")
Expand Down
Loading