def addToLibrary(tvdbId, path): parameters = {"term": "tvdb:" + str(tvdbId)} req = requests.get(commons.generateApiQuery("sonarr", "series/lookup", parameters)) parsed_json = json.loads(req.text) data = json.dumps(buildData(parsed_json, path)) add = requests.post(commons.generateApiQuery("sonarr", "series"), data=data, headers={'Content-Type': 'application/json'}) if add.status_code == 201: return True else: return False
def addToLibrary(tmdbId, path): parameters = {"tmdbId": str(tmdbId)} req = requests.get( commons.generateApiQuery("radarr", "movie/lookup/tmdb", parameters)) parsed_json = json.loads(req.text) data = json.dumps(buildData(parsed_json, path)) add = requests.post(commons.generateApiQuery("radarr", "movie"), data=data) if add.status_code == 201: return True else: return False
def addToLibrary(tvdbId): parameters = {"term": "tvdb:" + str(tvdbId)} req = requests.get( commons.generateApiQuery('sonarr', 'series/lookup', parameters)) parsed_json = json.loads(req.text) data = json.dumps(buildData(parsed_json)) add = requests.post(commons.generateApiQuery('sonarr', 'series'), data=data) if add.status_code == 201: return True else: return False
def addToLibrary(tmdbId, path, qualityProfileId, tags): parameters = {"tmdbId": str(tmdbId)} req = requests.get( commons.generateApiQuery("radarr", "movie/lookup/tmdb", parameters) ) parsed_json = json.loads(req.text) data = json.dumps(buildData(parsed_json, path, qualityProfileId, tags)) add = requests.post(commons.generateApiQuery("radarr", "movie"), data=data, headers={'Content-Type': 'application/json'}) if add.status_code == 201: return True else: return False
def changeSpeedSabnzbd(update, context): if not checkId(update): if (authentication( update, context) == "added"): # To also stop the beginning command return ConversationHandler.END choice = update.callback_query.data url = generateApiQuery("sabnzbd", "", { 'output': 'json', 'mode': 'config', 'name': 'speedlimit', 'value': choice }) req = requests.get(url) message = None if req.status_code == 200: if choice == SABNZBD_SPEED_LIMIT_100: message = i18n.t("addarr.Sabnzbd.ChangedTo100") elif choice == SABNZBD_SPEED_LIMIT_50: message = i18n.t("addarr.Sabnzbd.ChangedTo50") elif choice == SABNZBD_SPEED_LIMIT_25: message = i18n.t("addarr.Sabnzbd.ChangedTo25") else: message = i18n.t("addarr.Sabnzbd.Error") context.bot.send_message( chat_id=update.effective_message.chat_id, text=message, ) return ConversationHandler.END
def inLibrary(tvdbId): parameters = {} req = requests.get(commons.generateApiQuery("sonarr", "series", parameters)) parsed_json = json.loads(req.text) return next((True for show in parsed_json if show["tvdbId"] == tvdbId), False)
def getRootFolders(): parameters = {} req = requests.get( commons.generateApiQuery("radarr", "Rootfolder", parameters)) parsed_json = json.loads(req.text) logger.debug(f"Found Radarr paths: {parsed_json}") return parsed_json
def lookupSeriesByName(series_name): params = { # Set query parameters 'term': series_name } # Perform Get request from Sonarr API req = requests.get(commons.generateApiQuery('sonarr', 'series/lookup', params)) parsed_json = json.loads(req.text) return parsed_json
def removeFromLibrary(tvdbId): parameters = {"deleteFiles": str(True)} dbId = getDbIdFromImdbId(tvdbId) delete = requests.delete( commons.generateApiQuery("sonarr", f"series/{dbId}", parameters)) if delete.status_code == 200: return True else: return False
def lookupSeriesByTvdbId(tvdb_id): params = { # Set query parameters 'term': 'tvdb:' + str(int(tvdb_id)) } # Perform Get request from Sonarr API req = requests.get(commons.generateApiQuery('sonarr', 'series/lookup', params)) parsed_json = json.loads(req.text) return parsed_json
def search(title): parameters = {"term": title} req = requests.get(commons.generateApiQuery("radarr", "movie/lookup", parameters)) parsed_json = json.loads(req.text) if req.status_code == 200 and parsed_json: return parsed_json else: return False
def inLibrary(tmdbId): parameters = {} req = requests.get(commons.generateApiQuery('radarr', 'movie', parameters)) parsed_json = json.loads(req.text) for movie in parsed_json: if movie['tmdbId'] == tmdbId: return True break return False
def getUpcoming(days): todays_date = datetime.date.today() weeks_end_date = todays_date + datetime.timedelta(days=int(days)) params = { 'start': str(todays_date), 'end': str(weeks_end_date) } req = requests.get(commons.generateApiQuery('sonarr', 'calendar', params)) return json.loads(req.text)
def inLibrary(tvdbId): parameters = {} req = requests.get(commons.generateApiQuery('sonarr', 'series', parameters)) parsed_json = json.loads(req.text) for show in parsed_json: if show['tvdbId'] == tvdbId: return True break return False
def search(title): parameters = {"term": title} req = requests.get( commons.generateApiQuery('sonarr', 'series/lookup', parameters)) parsed_json = json.loads(req.text) if req.status_code == 200: return parsed_json else: return False
def createTag(tag): data_json = { "id": max([t["id"] for t in getTags()])+1, "label": str(tag) } add = requests.post(commons.generateApiQuery("radarr", "tag"), json=data_json, headers={'Content-Type': 'application/json'}) if add.status_code == 200: return True else: return False
def getRootFolders(): parameters = {} req = requests.get(commons.generateApiQuery("sonarr", "Rootfolder", parameters)) parsed_json = json.loads(req.text) # Remove unmappedFolders from rootFolder data--we don't need that for item in [ item for item in parsed_json if item.get("unmappedFolders") is not None ]: item.pop("unmappedFolders") logger.debug(f"Found sonarr paths: {parsed_json}") return parsed_json
def getLanguageProfileId(language): parameters = {} req = requests.get( commons.generateApiQuery("sonarr", "languageProfile", parameters)) parsed_json = json.loads(req.text) languageId = [l["id"] for l in parsed_json if l["name"] == language] if len(languageId) == 0: languageId = [l["id"] for l in parsed_json] logger.debug( "Didn't find a match with languageProfile from the config file. Took instead the first languageId from languageProfile-API response" ) return languageId[0]
def allSeries(): parameters = {} req = requests.get(commons.generateApiQuery("sonarr", "series", parameters)) parsed_json = json.loads(req.text) if req.status_code == 200: data = [] for show in parsed_json: if all(x in show for x in ["title", "year", "monitored", "status"]): data.append({ "title": show["title"], "year": show["year"], "monitored": show["monitored"], "status": show["status"], }) return data else: return False
def all_movies(): parameters = {} req = requests.get(commons.generateApiQuery("radarr", "movie", parameters)) parsed_json = json.loads(req.text) if req.status_code == 200: data = [] for movie in parsed_json: if all( x in movie for x in ["title", "year", "monitored", "status"] ): data.append( { "title": movie["title"], "year": movie["year"], "monitored": movie["monitored"], "status": movie["status"] } ) return data else: return False
def inLibrary(tmdbId): parameters = {} req = requests.get(commons.generateApiQuery("radarr", "movie", parameters)) parsed_json = json.loads(req.text) return next((True for movie in parsed_json if movie["tmdbId"] == tmdbId), False)
def getRootFolders(): parameters = {} req = requests.get(commons.generateApiQuery("radarr", "Rootfolder", parameters)) parsed_json = json.loads(req.text) return parsed_json
def getSeries(): req = requests.get(commons.generateApiQuery('sonarr', 'series')) parsed_json = json.loads(req.text) return parsed_json
def getSeriesById(series_id): req = requests.get(commons.generateApiQuery('sonarr', 'series/' + str(series_id))) parsed_json = json.loads(req.text) return parsed_json
def addSeriesToWatchList(requested_series): response = '' context_list = [] # Check to see if match is already in Sonarr my_shows = getSeries() for series in requested_series: print 'requested_series: ' print series for show in my_shows: if int(series['tvdbId']) == int(show['tvdbId']): response = 'Looks like Sonarr is already watching for ' + series['title'] else: data = { # Generate data query 'tvdbId': int(series['tvdbId']), 'title': series['title'], 'qualityProfileId': 3, 'titleSlug': series['titleSlug'], 'images': series['images'], 'seasons': series['seasons'], 'monitored': True, 'seasonFolder': True, 'path': '/Volumes/Plex Media 1/Plex/TV Shows/' + series['title'] } # Convert to JSON data_json = json.dumps(data) # Submit request to API r = requests.post(commons.generateApiQuery('sonarr', 'series'), data=data_json) parsed_json = json.loads(r.text) # Set user Response response = 'Success! ' + series['title'] + ' has been added to Sonarr.' # Create Rich Notifications slack_message = { 'attachments': [{ 'fallback': response, "pretext": "Message from Comandarr: " + response, 'author_name': 'Sonarr', <<<<<<< HEAD "author_link": generateServerAddress('sonarr') + '/series/' + series['titleSlug'], ======= "author_link": commons.generateServerAddress() + '/series/' + series['titleSlug'], >>>>>>> origin/develop "author_icon": config['sonarr']['resources']['app_logo'], 'title': 'Imported: ' + series['title'], # 'text': series['overview'], 'color': 'good', "fields": [ { "title": "Number of Seasons", "value": str(series['seasonCount']), "short": 'true' }, { "title": "Monitored", "value": str(series['monitored']), "short": 'true' } ], "thumb_url": config['sonarr']['resources']['app_logo'], }] }
def performCmdRescanSeries(): req = requests.get(commons.generateApiQuery('sonarr', 'command')) parsed_json = json.loads(req.text) return parsed_json
def getQualityProfiles(): parameters = {} req = requests.get( commons.generateApiQuery("sonarr", "qualityProfile", parameters)) parsed_json = json.loads(req.text) return parsed_json
def getTags(): parameters = {} req = requests.get(commons.generateApiQuery("sonarr", "tag", parameters)) parsed_json = json.loads(req.text) return parsed_json
def getSeasons(tvdbId): parameters = {"term": "tvdb:" + str(tvdbId)} req = requests.get( commons.generateApiQuery("sonarr", "series/lookup", parameters)) parsed_json = json.loads(req.text) return parsed_json[0]["seasons"]
def getDbIdFromImdbId(tvdbId): req = requests.get(commons.generateApiQuery("sonarr", "series", {})) parsed_json = json.loads(req.text) dbId = [f["id"] for f in parsed_json if f["tvdbId"] == tvdbId] return dbId[0]