matty87a 6 Posted June 7, 2019 Share Posted June 7, 2019 Hi, Sorry if this has been covered but I can't find anything in the swagger UI or on my check through the forum. Is it possible to trigger the Refresh Guide task via API? Link to comment Share on other sites More sharing options...
emveepee 112 Posted June 7, 2019 Share Posted June 7, 2019 (edited) I wrote a C# utility to update the Emby guide after a NextPVR guide refresh and there was no single API call although Luke mentioned he might add one. 1) Loop through the scheduled tasks "http://{0}:{1}/emby/ScheduledTasks?IsHidden=false&api_key={2}" to get the Task ID for the "Refresh Guide" category 2) Execute "http://{0}:{1}/emby/ScheduledTasks/Running/{2}?api_key={3}" to refresh the guide. {2} is the task ID Martin Edited June 7, 2019 by emveepee Link to comment Share on other sites More sharing options...
Luke 37065 Posted June 7, 2019 Share Posted June 7, 2019 Yea if it would be easier i can make a dedicated method. Link to comment Share on other sites More sharing options...
BillOatman 500 Posted June 8, 2019 Share Posted June 8, 2019 I wrote a C# utility to update the Emby guide after a NextPVR guide refresh and there was no single API call although Luke mentioned he might add one. 1) Loop through the scheduled tasks "http://{0}:{1}/emby/ScheduledTasks?IsHidden=false&api_key={2}" to get the Task ID for the "Refresh Guide" category 2) Execute "http://{0}:{1}/emby/ScheduledTasks/Running/{2}?api_key={3}" to refresh the guide. {2} is the task ID Martin Does yours still work? I wrote one that does the same thing that I was using a while back that uses the dot net sdk and it worked great. But the sdk broke a while back with one of the recent server updates. @@Luke mentioned it needed updating. Has it been updated? Link to comment Share on other sites More sharing options...
emveepee 112 Posted June 8, 2019 Share Posted June 8, 2019 Does yours still work? I wrote one that does the same thing that I was using a while back that uses the dot net sdk and it worked great. But the sdk broke a while back with one of the recent server updates. @@Luke mentioned it needed updating. Has it been updated? I don't use it but just checked and yes it is still working here are the logs 2019-06-08 11:06:27.966 Info HttpServer: HTTP Response 200 to ::1. Time: 1ms. http://localhost:8096/emby/ScheduledTasks?IsHidden=false 2019-06-08 11:06:28.117 Info HttpServer: HTTP POST http://localhost:8096/emby/ScheduledTasks/Running/9492d30c70f7f1bec3757c9d0a4feb45. UserAgent: EmbyReload:1.0.0.0 2019-06-08 11:06:28.119 Info TaskManager: Executing Refresh Guide 2019-06-08 11:06:28.119 Info HttpServer: HTTP Response 204 to ::1. Time: 2ms. http://localhost:8096/emby/ScheduledTasks/Running/9492d30c70f7f1bec3757c9d0a4feb45 Martin 1 Link to comment Share on other sites More sharing options...
BillOatman 500 Posted June 10, 2019 Share Posted June 10, 2019 I don't use it but just checked and yes it is still working here are the logs 2019-06-08 11:06:27.966 Info HttpServer: HTTP Response 200 to ::1. Time: 1ms. http://localhost:8096/emby/ScheduledTasks?IsHidden=false 2019-06-08 11:06:28.117 Info HttpServer: HTTP POST http://localhost:8096/emby/ScheduledTasks/Running/9492d30c70f7f1bec3757c9d0a4feb45. UserAgent: EmbyReload:1.0.0.0 2019-06-08 11:06:28.119 Info TaskManager: Executing Refresh Guide 2019-06-08 11:06:28.119 Info HttpServer: HTTP Response 204 to ::1. Time: 2ms. http://localhost:8096/emby/ScheduledTasks/Running/9492d30c70f7f1bec3757c9d0a4feb45 Martin Would you mind sharing that code/solution? I'd love to get something working again. Link to comment Share on other sites More sharing options...
matty87a 6 Posted June 10, 2019 Author Share Posted June 10, 2019 Thanks for the hints! A simple GET to https://SERVER:PORT/ScheduledTasks?api_key=KEY returns all the tasks and their ID's Link to comment Share on other sites More sharing options...
emveepee 112 Posted June 10, 2019 Share Posted June 10, 2019 (edited) Would you mind sharing that code/solution? I'd love to get something working again. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using System.IO; using System.Net; using System.Net.Http; using NUtility; using System.Net.NetworkInformation; public class Trigger { public string Type { get; set; } public long TimeOfDayTicks { get; set; } public long MaxRuntimeTicks { get; set; } public long? IntervalTicks { get; set; } } public class LastExecutionResult { public DateTime StartTimeUtc { get; set; } public DateTime EndTimeUtc { get; set; } public string Status { get; set; } public string Name { get; set; } public string Key { get; set; } public string Id { get; set; } } public class TaskObject { public string Name { get; set; } public string State { get; set; } public string Id { get; set; } public List<Trigger> Triggers { get; set; } public string Description { get; set; } public string Category { get; set; } public bool IsHidden { get; set; } public string Key { get; set; } public LastExecutionResult LastExecutionResult { get; set; } } namespace EmbyReload { class Program { private const string Format = "http://{0}:{1}/emby/ScheduledTasks?IsHidden=false&api_key={2}"; static void Main(string[] args) { System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); string agent = "EmbyReload:" + asm.GetName().Version; Console.WriteLine(agent); Uri uriResult; string host = "localhost"; string port = "8096"; if (args.Length == 2) { host = args[1]; } else if (args.Length == 3) { host = args[1]; port = args[2]; } else if (args.Length != 1) { Console.WriteLine("EmbyReload API_KEY {server} {port}"); return; } Logger.SetLogFileName("logs/EmbyReload.log"); Logger.Debug(agent); string uriName = string.Format(Format, host, port, args[0]); Logger.Debug(string.Format(Format, host, port, "hidden")); bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (!result) { Logger.Error("Invalid URI parameters"); return; } try { Logger.Debug("Getting tasks"); WebClient webClient = new WebClient(); webClient.Headers.Add("user-agent", agent); Stream stream = webClient.OpenRead(uriResult); StreamReader sr = new StreamReader(stream); String request = sr.ReadToEnd(); List<TaskObject> taskObjects = null; Logger.Debug("Found tasks"); taskObjects = JsonConvert.DeserializeObject<List<TaskObject>>(request); foreach (TaskObject task in taskObjects) { if (task.Key == "RefreshGuide") { if (task.State == "Idle") { bool waitForDaily = false; foreach (Trigger trigger in task.Triggers) { Console.WriteLine(trigger.Type); if (trigger.Type == "DailyTrigger") { DateTime triggerTime = new DateTime(trigger.TimeOfDayTicks); Logger.Debug("Daily update scheduled for " + triggerTime.ToString("HH:mm")); TimeSpan ts = triggerTime.TimeOfDay - DateTime.Now.TimeOfDay; if (ts.TotalSeconds > 0 && ts.TotalMinutes < 15) { Logger.Debug("Guide refreshing soon, no forced update"); waitForDaily = true; break; } } } if (waitForDaily == false) { Logger.Debug("Refresh guide starting"); uriName = string.Format("http://{0}:{1}/emby/ScheduledTasks/Running/{2}?api_key={3}", host, port, task.Id, args[0]); result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; webClient = new WebClient(); webClient.Headers.Add("user-agent", agent); webClient.UploadString(uriResult, ""); webClient.Dispose(); Logger.Debug("Refresh guide activated"); } break; } else { Logger.Debug("Refresh guide skipped " + task.State); } break; } } } catch (WebException wex) { Logger.Error(wex.Message); Console.WriteLine(wex.Message); } catch (Exception err) { Logger.Error(err.Message); } Logger.Debug("Exit"); } } } Just take out the NUtility and Logger message and it should work Martin Edited June 10, 2019 by emveepee 1 Link to comment Share on other sites More sharing options...
chef 3745 Posted June 10, 2019 Share Posted June 10, 2019 Link to comment Share on other sites More sharing options...
BillOatman 500 Posted June 10, 2019 Share Posted June 10, 2019 Just take out the NUtility and Logger message and it should work Martin Worked perfectly, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now