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

Fix json constructor #85

Merged
Merged
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
50 changes: 35 additions & 15 deletions pyarr/radarr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class RadarrAPI(RequestAPI):
"""

def _construct_movie_json(
self, db_id, quality_profile_id, root_dir, monitored=True, search_for_movie=True
self,
db_id,
quality_profile_id,
root_dir,
monitored=True,
search_for_movie=True,
tmdb=True,
):
"""Searches for movie on tmdb and returns Movie json to add.

Expand All @@ -19,26 +25,30 @@ def _construct_movie_json(
root_dir (str): location of the root DIR
monitored (bool, optional): should the movie be monitored. Defaults to True.
search_for_movie (bool, optional): Should we search for the movie. Defaults to True.
tmdb (bool, optional): Use TMDB IDs. Set to False to use IMDB. Defaults to True.

Raises:
Exception: [description]

Returns:
JSON: Movie JSON for adding a movie to radarr
"""
s_dict = self.lookup_movie(db_id)
if tmdb:
movie = self.lookup_movie_by_tmdb_id(db_id)[0]
else:
movie = self.lookup_movie_by_imdb_id(db_id)[0]

if not s_dict:
if not movie:
raise Exception("Movie Doesn't Exist")

movie_json = {
"title": s_dict[0]["title"],
"title": movie["title"],
"rootFolderPath": root_dir,
"qualityProfileId": quality_profile_id,
"year": s_dict[0]["year"],
"tmdbId": s_dict[0]["tmdbId"],
"images": s_dict[0]["images"],
"titleSlug": s_dict[0]["titleSlug"],
"year": movie["year"],
"tmdbId": movie["tmdbId"],
"images": movie["images"],
"titleSlug": movie["titleSlug"],
"monitored": monitored,
"addOptions": {"searchForMovie": search_for_movie},
}
Expand Down Expand Up @@ -81,18 +91,13 @@ def add_movie(
root_dir (str): location of the root DIR
monitored (bool, optional): should the movie be monitored. Defaults to True.
search_for_movie (bool, optional): Should we search for the movie. Defaults to True.
tmdb (bool, optional): Use IMDB IDs. Defaults to True.
tmdb (bool, optional): Use TMDB IDs. Set to False to use IMDB. Defaults to True.

Returns:
JSON: 200 Ok, 401 Unauthorized
"""
if tmdb:
term = f"tmdb:{str(db_id)}"
else:
term = f"imdb:{str(db_id)}"

movie_json = self._construct_movie_json(
term, quality_profile_id, root_dir, monitored, search_for_movie
db_id, quality_profile_id, root_dir, monitored, search_for_movie, tmdb
)

path = "/api/v3/movie"
Expand Down Expand Up @@ -177,6 +182,21 @@ def lookup_movie_by_tmdb_id(self, id_):
res = self.request_get(path, params=params)
return res

# GET /movie/lookup
def lookup_movie_by_imdb_id(self, id_):
"""Search for movie by IMDB ID

Args:
id_ (str): IMDB ID

Returns:
JSON: List of movies found
"""
params = {"term": f"imdb:{id_}"}
path = "/api/v3/movie/lookup"
res = self.request_get(path, params=params)
return res

# PUT /movie/editor
def upd_movies(self, data):
"""The Updates operation allows to edit properties of multiple movies at once
Expand Down
17 changes: 8 additions & 9 deletions pyarr/sonarr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ def _construct_series_json(
Returns:
JSON: Array
"""
res = self.lookup_series(tvdb_id)
s_dict = res[0]
if not monitored and s_dict.get("seasons"):
for season in s_dict["seasons"]:
series = self.lookup_series_by_tvdb_id(tvdb_id)[0]
if not monitored and series.get("seasons"):
for season in series["seasons"]:
season["monitored"] = False

series_json = {
"title": s_dict["title"],
"seasons": s_dict["seasons"],
"path": root_dir + s_dict["title"],
"title": series["title"],
"seasons": series["seasons"],
"path": root_dir + series["title"],
"qualityProfileId": quality_profile_id,
"seasonFolder": season_folder,
"monitored": monitored,
"tvdbId": tvdb_id,
"images": s_dict["images"],
"titleSlug": s_dict["titleSlug"],
"images": series["images"],
"titleSlug": series["titleSlug"],
"addOptions": {
"ignoreEpisodesWithFiles": ignore_episodes_with_files,
"ignoreEpisodesWithoutFiles": ignore_episodes_without_files,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyarr"
version = "2.0.4"
version = "2.0.5"
description = "A Sonarr and Radarr API Wrapper"
authors = ["Steven Marks <[email protected]>"]
license = "MIT"
Expand Down