public List <Series> GetSeries(string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/series", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); try { var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5) }); var series = policy.Execute(() => Api.ExecuteJson <List <Series> >(request, baseUrl)); // Remove the 'specials from the object' foreach (var s in series) { var seasonToRemove = s.seasons.FirstOrDefault(x => x.seasonNumber == 0); if (seasonToRemove != null) { s.seasons.Remove(seasonToRemove); } } return(series); } catch (Exception e) { Log.Error(e, "There has been an API exception when getting the Sonarr Series"); return(null); } }
public SonarrSeriesSearchResult SearchForSeries(int seriesId, string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/Command", Method = Method.POST }; request.AddHeader("X-Api-Key", apiKey); var body = new SonarrSearchCommand { name = "SeriesSearch", seriesId = seriesId }; request.AddJsonBody(body); try { var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling SearchForSeries for Sonarr, Retrying {0}", timespan)); return(policy.Execute(() => Api.ExecuteJson <SonarrSeriesSearchResult>(request, baseUrl))); } catch (Exception e) { Log.Error(e, "There has been an API exception when put the Sonarr SearchForSeries"); return(null); } }
public Series GetSeries(string seriesId, string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/series/{seriesId}", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); request.AddUrlSegment("seriesId", seriesId); try { var policy = RetryHandler.RetryAndWaitPolicy( (exception, timespan) => Log.Error(exception, "Exception when calling GetSeries by ID for Sonarr, Retrying {0}", timespan)); var series = policy.Execute(() => Api.ExecuteJson <Series>(request, baseUrl)); // Remove the specials season var toRemove = series.seasons.FirstOrDefault(x => x.seasonNumber == 0); if (toRemove != null) { series.seasons.Remove(toRemove); } return(series); } catch (Exception e) { Log.Error(e, "There has been an API exception when getting the Sonarr Series by ID"); return(null); } }
public PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount) { var request = new RestRequest { Method = Method.GET, Resource = "/library/sections/{section}/all" }; request.AddQueryParameter("type", 4.ToString()); AddLimitHeaders(ref request, startPage, returnCount); request.AddUrlSegment("section", section); AddHeaders(ref request, authToken, false); try { var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexSearch>(request, host), (exception, timespan) => Log.Error(exception, "Exception when calling GetAllEpisodes for Plex, Retrying {0}", timespan)); return(lib); } catch (Exception e) { Log.Error(e, "There has been a API Exception when attempting to get GetAllEpisodes"); return(new PlexSearch()); } }
public EmbyUser LogIn(string username, string password, string apiKey, Uri baseUri) { var request = new RestRequest { Resource = "emby/users/authenticatebyname", Method = Method.POST }; var body = new { username, password = StringHasher.GetSha1Hash(password).ToLower(), passwordMd5 = StringHasher.CalcuateMd5Hash(password) }; request.AddJsonBody(body); request.AddHeader("X-Emby-Authorization", $"MediaBrowser Client=\"Ombi\", Device=\"Ombi\", DeviceId=\"{AssemblyHelper.GetProductVersion()}\", Version=\"{AssemblyHelper.GetAssemblyVersion()}\""); AddHeaders(request, apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling LogInfor Emby, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(1) }); var obj = policy.Execute(() => Api.Execute(request, baseUri)); if (obj.StatusCode == HttpStatusCode.Unauthorized) { return(null); } return(JsonConvert.DeserializeObject <EmbyUserLogin>(obj.Content)?.User); }
public PlexRecentlyAddedModel RecentlyAdded(string authToken, Uri plexFullHost, string sectionId) { var request = new RestRequest { Method = Method.GET, Resource = "library/sections/{sectionId}/recentlyAdded" }; request.AddUrlSegment("sectionId", sectionId); AddHeaders(ref request, authToken, true); AddLimitHeaders(ref request, 0, 25); try { var lib = RetryHandler.Execute(() => Api.ExecuteJson <PlexRecentlyAddedModel>(request, plexFullHost), (exception, timespan) => Log.Error(exception, "Exception when calling PlexRecentlyAddedModel for Plex, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) }); return(lib); } catch (Exception e) { Log.Error(e, "There has been a API Exception when attempting to get the Plex RecentlyAddedModel"); return(new PlexRecentlyAddedModel()); } }
public PlexSeasonMetadata GetSeasons(string authToken, Uri plexFullHost, string ratingKey) { var request = new RestRequest { Method = Method.GET, Resource = "library/metadata/{ratingKey}/children" }; request.AddUrlSegment("ratingKey", ratingKey); AddHeaders(ref request, authToken, false); try { var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexSeasonMetadata>(request, plexFullHost), (exception, timespan) => Log.Error(exception, "Exception when calling GetMetadata for Plex, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) }); return(lib); } catch (Exception e) { Log.Error(e, "There has been a API Exception when attempting to get the Plex GetMetadata"); return(new PlexSeasonMetadata()); } }
public PlexEpisodeMetadata GetEpisodeMetaData(string authToken, Uri host, string ratingKey) { //192.168.1.69:32400/library/metadata/3662/allLeaves // The metadata ratingkey should be in the Cache // Search for it and then call the above with the Directory.RatingKey // THEN! We need the episode metadata using result.Vide.Key ("/library/metadata/3664") // We then have the GUID which contains the TVDB ID plus the season and episode number: guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en" var request = new RestRequest { Method = Method.GET, Resource = "/library/metadata/{ratingKey}" }; request.AddUrlSegment("ratingKey", ratingKey); AddHeaders(ref request, authToken, false); try { var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexEpisodeMetadata>(request, host), (exception, timespan) => Log.Error(exception, "Exception when calling GetEpisodeMetaData for Plex, Retrying {0}", timespan)); return(lib); } catch (Exception e) { Log.Error(e, "There has been a API Exception when attempting to get GetEpisodeMetaData"); return(new PlexEpisodeMetadata()); } }
public PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId) { var request = new RestRequest { Method = Method.GET, Resource = "library/sections/{libraryId}/all" }; request.AddUrlSegment("libraryId", libraryId); AddHeaders(ref request, authToken, false); try { var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexSearch> (request, plexFullHost), (exception, timespan) => Log.Error(exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan), new TimeSpan[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) }); return(lib); } catch (Exception e) { Log.Error(e, "There has been a API Exception when attempting to get the Plex Library"); return(new PlexSearch()); } }
public CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status) { var request = new RestRequest { Resource = "/api/{apikey}/movie.list?status={status}", OnBeforeDeserialization = (x => { x.Content = x.Content.Replace("[]", "{}"); }) }; request.AddUrlSegment("apikey", apiKey); request.AddUrlSegment("status", string.Join(",", status)); try { var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoMovies>(request, baseUrl), (exception, timespan) => Log.Error(exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) }); return(obj); } catch (Exception e) // Request error is already logged in the ApiRequest class { Log.Error("Error when attempting to GetMovies."); Log.Error(e); return(new CouchPotatoMovies()); } }
public SickRagePing Ping(string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=sb.ping", Method = Method.GET }; var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling Ping for SR, Retrying {0}", timespan), null); request.AddUrlSegment("apiKey", apiKey); var obj = policy.Execute(() => Api.ExecuteJson <SickRagePing>(request, baseUrl)); return(obj); }
public PlexStatus GetStatus(string authToken, Uri uri) { var request = new RestRequest { Method = Method.GET, }; AddHeaders(ref request, authToken, false); var users = RetryHandler.Execute(() => Api.ExecuteXml <PlexStatus> (request, uri), (exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for Plex, Retrying {0}", timespan), null); return(users); }
public PlexAccount GetAccount(string authToken) { var request = new RestRequest { Method = Method.GET, }; AddHeaders(ref request, authToken, false); var account = RetryHandler.Execute(() => Api.ExecuteXml <PlexAccount> (request, new Uri(GetAccountUri)), (exception, timespan) => Log.Error(exception, "Exception when calling GetAccount for Plex, Retrying {0}", timespan), null); return(account); }
public CouchPotatoProfiles GetProfiles(Uri url, string apiKey) { var request = new RestRequest { Resource = "api/{apikey}/profile.list/", Method = Method.GET }; request.AddUrlSegment("apikey", apiKey); var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoProfiles>(request, url), (exception, timespan) => Log.Error(exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan), null); return(obj); }
public PlexServer GetServer(string authToken) { var request = new RestRequest { Method = Method.GET, }; AddHeaders(ref request, authToken, false); var servers = RetryHandler.Execute(() => Api.ExecuteXml <PlexServer>(request, new Uri(ServerUri)), (exception, timespan) => Log.Error(exception, "Exception when calling GetServer for Plex, Retrying {0}", timespan)); return(servers); }
public CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password) { var request = new RestRequest { Resource = "getkey/?u={username}&p={password}", Method = Method.GET }; request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username)); request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password)); var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoApiKey>(request, baseUrl), (exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null); return(obj); }
public List <SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/rootfolder", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Radarr, Retrying {0}", timespan), new TimeSpan[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2) }); var obj = policy.Execute(() => Api.ExecuteJson <List <SonarrRootFolder> >(request, baseUrl)); return(obj); }
/// <summary> /// Gets the users. /// </summary> /// <param name="authToken">The authentication token.</param> /// <param name="searchTerm">The search term.</param> /// <param name="plexFullHost">The full plex host.</param> /// <returns></returns> public PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost) { var request = new RestRequest { Method = Method.GET, Resource = "search?query={searchTerm}" }; request.AddUrlSegment("searchTerm", searchTerm); AddHeaders(ref request, authToken, false); var search = RetryHandler.Execute(() => Api.ExecuteXml <PlexSearch> (request, plexFullHost), (exception, timespan) => Log.Error(exception, "Exception when calling SearchContent for Plex, Retrying {0}", timespan), null); return(search); }
public List <RadarrMovieResponse> GetMovies(string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/movie", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan), new TimeSpan[] { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) }); var obj = policy.Execute(() => Api.Execute(request, baseUrl)); return(JsonConvert.DeserializeObject <List <RadarrMovieResponse> >(obj.Content)); }
/// <summary> /// Returns all users from the Emby Instance /// </summary> /// <param name="baseUri"></param> /// <param name="apiKey"></param> public List <EmbyUser> GetUsers(Uri baseUri, string apiKey) { var request = new RestRequest { Resource = "emby/users", Method = Method.GET }; AddHeaders(request, apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetUsers for Emby, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(1), }); var obj = policy.Execute(() => Api.ExecuteJson <List <EmbyUser> >(request, baseUri)); return(obj); }
public SystemStatus SystemStatus(string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/system/status", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan), new TimeSpan[] { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) }); var obj = policy.Execute(() => Api.ExecuteJson <SystemStatus>(request, baseUrl)); return(obj); }
public EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "emby/System/Info", Method = Method.GET }; AddHeaders(request, apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSystemInformation for Emby, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5) }); var obj = policy.Execute(() => Api.ExecuteJson <EmbySystemInfo>(request, baseUrl)); return(obj); }
public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileId = default(string)) { RestRequest request; request = string.IsNullOrEmpty(profileId) ? new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}" } : new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}&profile_id={profileId}" }; if (!string.IsNullOrEmpty(profileId)) { request.AddUrlSegment("profileId", profileId); } request.AddUrlSegment("apikey", apiKey); request.AddUrlSegment("imdbid", imdbid); request.AddUrlSegment("title", title); var obj = RetryHandler.Execute(() => Api.ExecuteJson <JObject>(request, baseUrl), (exception, timespan) => Log.Error(exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(2) }); if (obj.Count > 0) { try { var result = (bool)obj["success"]; return(result); } catch (Exception e) { Log.Fatal(e); return(false); } } return(false); }
//https://ci.appveyor.com/api/projects/tidusjar/requestplex/history?recordsNumber=10&branch=eap public AppveyorProjects GetProjectHistory(string branchName, int records = 10) { var request = new RestRequest { Resource = "projects/tidusjar/requestplex/history?recordsNumber={records}&branch={branch}", Method = Method.GET }; request.AddUrlSegment("records", records.ToString()); request.AddUrlSegment("branch", branchName); AddHeaders(request); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetProjectHistory for Appveyor, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(1), }); var obj = policy.Execute(() => Api.ExecuteJson <AppveyorProjects>(request, new Uri(AppveyorApiUrl))); return(obj); }
public EmbyItemContainer <EmbyLibrary> ViewLibrary(string apiKey, string userId, Uri baseUri) { var request = new RestRequest { Resource = "emby/users/{userId}/items", Method = Method.GET }; request.AddUrlSegment("userId", userId); AddHeaders(request, apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling ViewLibrary for Emby, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5) }); var obj = policy.Execute(() => Api.ExecuteJson <EmbyItemContainer <EmbyLibrary> >(request, baseUri)); return(obj); }
/// <summary> /// Gets the status. /// </summary> /// <param name="url">The URL.</param> /// <param name="apiKey">The API key.</param> /// <returns></returns> public CouchPotatoStatus GetStatus(Uri url, string apiKey) { var request = new RestRequest { Resource = "api/{apikey}/app.available/", Method = Method.GET }; request.AddUrlSegment("apikey", apiKey); var obj = RetryHandler.Execute <CouchPotatoStatus>(() => Api.Execute <CouchPotatoStatus>(request, url), (exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan), new TimeSpan[] { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) }); return(obj); }
public EmbyItemContainer <EmbyMovieInformation> GetCollection(string mediaId, string apiKey, string userId, Uri baseUrl) { var request = new RestRequest { Resource = "emby/users/{userId}/items?parentId={mediaId}", Method = Method.GET }; request.AddUrlSegment("userId", userId); request.AddUrlSegment("mediaId", mediaId); AddHeaders(request, apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetCollections for Emby, Retrying {0}", timespan), new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5) }); return(policy.Execute(() => Api.ExecuteJson <EmbyItemContainer <EmbyMovieInformation> >(request, baseUrl))); }
public SonarrEpisodes UpdateEpisode(SonarrEpisodes episodeInfo, string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/Episode", Method = Method.PUT }; request.AddHeader("X-Api-Key", apiKey); request.AddJsonBody(episodeInfo); try { var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling UpdateEpisode for Sonarr, Retrying {0}", timespan)); return(policy.Execute(() => Api.ExecuteJson <SonarrEpisodes>(request, baseUrl))); } catch (Exception e) { Log.Error(e, "There has been an API exception when put the Sonarr UpdateEpisode"); return(null); } }
/// <summary> /// Returns the episode with the matching id. /// </summary> /// <param name="episodeId">The episode identifier.</param> /// <param name="apiKey">The API key.</param> /// <param name="baseUrl">The base URL.</param> /// <returns></returns> public SonarrEpisode GetEpisode(string episodeId, string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/Episode/{episodeId}", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); request.AddUrlSegment("episodeId", episodeId); try { var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetEpisode by ID for Sonarr, Retrying {0}", timespan)); return(policy.Execute(() => Api.ExecuteJson <SonarrEpisode>(request, baseUrl))); } catch (Exception e) { Log.Error(e, "There has been an API exception when getting the Sonarr GetEpisode by ID"); return(null); } }
/// <summary> /// Returns all episodes for the given series. /// </summary> /// <param name="seriesId">The series identifier.</param> /// <param name="apiKey">The API key.</param> /// <param name="baseUrl">The base URL.</param> /// <returns></returns> public IEnumerable <SonarrEpisodes> GetEpisodes(string seriesId, string apiKey, Uri baseUrl) { var request = new RestRequest { Resource = "/api/Episode", Method = Method.GET }; request.AddHeader("X-Api-Key", apiKey); request.AddQueryParameter("seriesId", seriesId); try { var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetEpisodes for Sonarr, Retrying {0}", timespan)); return(policy.Execute(() => Api.ExecuteJson <List <SonarrEpisodes> >(request, baseUrl))); } catch (Exception e) { Log.Error(e, "There has been an API exception when getting the Sonarr GetEpisodes"); return(null); } }