Skip to content

Commit

Permalink
Merge pull request #54 from Archmonger/master
Browse files Browse the repository at this point in the history
v0.9.4
  • Loading branch information
marksie1988 authored Sep 29, 2020
2 parents c83a04d + d7e2d8a commit b742a15
Show file tree
Hide file tree
Showing 12 changed files with 583 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
black:
name: Check PyArr formatting with Balck
name: Check PyArr formatting with Black
runs-on: ubuntu-latest
steps:
- name: Getting your configuration from GitHub
Expand Down
102 changes: 43 additions & 59 deletions PyArr/radarr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,63 +67,25 @@ def getCommand(self, *args):
res = self.request_get(path)
return res.json()

def __setCommand(self, data):
"""Private Command Method
def setCommand(self, **kwargs):
"""Performs any of the predetermined Radarr command routines.
Args:
data (dict): data payload to send to /api/command
Returns:
json response
"""
print(data)
path = "/api/command"
res = self.request_post(path, data)
return res.json()

def refreshMovie(self, *args):
"""RefreshMovie refreshes movie information and rescans disk.
Args:
Optional - movieId (int)
Returns:
json response
Kwargs:
Required - name (string).
"""
data = {}
if len(args) == 1:
data.update({"name": "RefreshMovie", "movieId": args[0]})
else:
data.update({"name": "RefreshMovie"})
return self.__setCommand(data)
Options available: RefreshMovie, RescanMovie, MoviesSearch, DownloadedMoviesScan, RssSync, RenameFiles, RenameMovie, CutOffUnmetMoviesSearch, NetImportSync, missingMoviesSearch
def rescanMovie(self, *args):
"""RescanMovie scans disk for any downloaded movie for all or specified movie.
Args:
Optional - movieId (int)
Additional Parameters may be required or optional...
See https://github.com/Radarr/Radarr/wiki/API:Command
Returns:
json response
json response
"""
data = {}
if len(args) == 1:
data.update({"name": "RescanMovie", "movieId": args[0]})
else:
data.update({"name": "RescanMovie"})
return self.__setCommand(data)

def syncRss(self):
"""Instruct Sonarr to perform an RSS sync with all enabled indexers
Args:
none
Returns:
json response
path = "/api/command"

"""
data = {"name": "RssSync"}
return self.__setCommand(data)
data = kwargs
res = self.request_post(path, data)
return res.json()

def getDiskSpace(self):
"""GetDiskSpace retrieves info about the disk space on the server.
Expand Down Expand Up @@ -155,6 +117,19 @@ def getMovie(self, *args):
res = self.request_get(path)
return res.json()

def updMovie(self, data):
"""Update an existing movie.
Args:
data (dictionary containing an object obtained by getMovie())
Returns:
json response
"""

path = "/api/movie"
res = self.request_put(path, data)
return res.json()

def lookupMovie(self, term):
"""lookupMovie serches for movie
Expand Down Expand Up @@ -187,45 +162,54 @@ def getQualityProfiles(self):
res = self.request_get(path)
return res.json()

def constructMovieJson(self, dbId, qualityProfileId):
def constructMovieJson(
self, dbId, qualityProfileId, rootDir, monitored=True, searchForMovie=True
):
"""Searches for movie on tmdb and returns Movie json to add
Args:
Required - dbID, <imdb or tmdb id>
Required - qualityProfileId (int)
Required - rootDir (string)
Optional - monitored (boolean)
Optional - searchForMovie (boolean)
Return:
JsonArray
"""
s_dict = self.lookupMovie(dbId)

root = self.getRoot()[0]["path"]
movie_json = {
"title": s_dict["title"],
"path": root + s_dict["title"],
"path": rootDir + s_dict["title"],
"qualityProfileId": qualityProfileId,
"profileId": qualityProfileId,
"year": s_dict["year"],
"tmdbId": s_dict["tmdbId"],
"images": s_dict["images"],
"titleSlug": s_dict["titleSlug"],
"monitored": True,
"addOptions": {"searchForMovie": True},
"monitored": monitored,
"addOptions": {"searchForMovie": searchForMovie},
}
return movie_json

def addMovie(self, dbId, qualityProfileId):
def addMovie(
self, dbId, qualityProfileId, rootDir, monitored=True, searchForMovie=True
):
"""addMovie adds a new movie to collection
Args:
Required - dbid
Required - qualityProfileId
Required - dbid <imdb or tmdb id>
Required - qualityProfileId (int)
Required - rootDir (string)
Returns:
json response
"""
movie_json = self.constructMovieJson(dbId, qualityProfileId)
movie_json = self.constructMovieJson(
dbId, qualityProfileId, rootDir, monitored, searchForMovie
)

path = "/api/movie"
res = self.request_post(path, data=movie_json)
Expand Down
Loading

0 comments on commit b742a15

Please sign in to comment.