public async Task <IEnumerable <ProgramInfo> > GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetProgramsAsync, call canceled or timed out - returning empty list."); return(new List <ProgramInfo>()); } GetEventsResponseHandler currGetEventsResponseHandler = new GetEventsResponseHandler(startDateUtc, endDateUtc, _logger, cancellationToken); HTSMessage queryEvents = new HTSMessage(); queryEvents.Method = "getEvents"; queryEvents.putField("channelId", Convert.ToInt32(channelId)); _htsConnectionHandler.SendMessage(queryEvents, currGetEventsResponseHandler); _logger.Info("[TVHclient] GetProgramsAsync, ask TVH for events of channel '" + channelId + "'."); TaskWithTimeoutRunner <IEnumerable <ProgramInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <ProgramInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <ProgramInfo> > twtRes = await twtr.RunWithTimeout(currGetEventsResponseHandler.GetEvents(cancellationToken, channelId)); if (twtRes.HasTimeout) { _logger.Info("[TVHclient] GetProgramsAsync, timeout during call for events of channel '" + channelId + "'."); return(new List <ProgramInfo>()); } return(twtRes.Result); }
public async Task <IEnumerable <ProgramInfo> > GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogDebug("[TVHclient] LiveTvService.GetProgramsAsync: call cancelled or timed out - returning empty list"); return(new List <ProgramInfo>()); } GetEventsResponseHandler currGetEventsResponseHandler = new GetEventsResponseHandler(startDateUtc, endDateUtc, _logger, cancellationToken); HTSMessage queryEvents = new HTSMessage(); queryEvents.Method = "getEvents"; queryEvents.putField("channelId", Convert.ToInt32(channelId)); queryEvents.putField("maxTime", ((DateTimeOffset)endDateUtc).ToUnixTimeSeconds()); _htsConnectionHandler.SendMessage(queryEvents, currGetEventsResponseHandler); _logger.LogDebug("[TVHclient] LiveTvService.GetProgramsAsync: ask TVH for events of channel '{chanid}'", channelId); TaskWithTimeoutRunner <IEnumerable <ProgramInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <ProgramInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <ProgramInfo> > twtRes = await twtr.RunWithTimeout(currGetEventsResponseHandler.GetEvents(cancellationToken, channelId)); if (twtRes.HasTimeout) { _logger.LogDebug("[TVHclient] LiveTvService.GetProgramsAsync: timeout reached while calling for events of channel '{chanid}'", channelId); return(new List <ProgramInfo>()); } return(twtRes.Result); }
public async Task <IEnumerable <ChannelInfo> > GetChannelsAsync(CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogInformation("[TVHclient] GetChannelsAsync, call canceled or timed out - returning empty list."); return(new List <ChannelInfo>()); } TaskWithTimeoutRunner <IEnumerable <ChannelInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <ChannelInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <ChannelInfo> > twtRes = await twtr.RunWithTimeout(_htsConnectionHandler.BuildChannelInfos(cancellationToken)); if (twtRes.HasTimeout) { return(new List <ChannelInfo>()); } var list = twtRes.Result.ToList(); foreach (var channel in list) { if (string.IsNullOrEmpty(channel.ImageUrl)) { channel.ImageUrl = _htsConnectionHandler.GetChannelImageUrl(channel.Id); } } return(list); }
/// <summary> /// Create a new recording /// </summary> /// <param name="info">The TimerInfo</param> /// <param name="cancellationToken">The cancellationToken</param> /// <returns></returns> public async Task CreateTimerAsync(TimerInfo info, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] CreateTimerAsync, call canceled or timed out."); return; } HTSMessage createTimerMessage = new HTSMessage(); createTimerMessage.Method = "addDvrEntry"; createTimerMessage.putField("channelId", info.ChannelId); createTimerMessage.putField("start", DateTimeHelper.getUnixUTCTimeFromUtcDateTime(info.StartDate)); createTimerMessage.putField("stop", DateTimeHelper.getUnixUTCTimeFromUtcDateTime(info.EndDate)); createTimerMessage.putField("startExtra", (long)(info.PrePaddingSeconds / 60)); createTimerMessage.putField("stopExtra", (long)(info.PostPaddingSeconds / 60)); createTimerMessage.putField("priority", _priority); // info.Priority delivers always 0 - no GUI createTimerMessage.putField("configName", _profile); createTimerMessage.putField("description", info.Overview); createTimerMessage.putField("title", info.Name); createTimerMessage.putField("creator", Plugin.Instance.Configuration.Username); //HTSMessage createTimerResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(createTimerMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(createTimerMessage, lbrh); return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't create timer because of timeout"); } else { HTSMessage createTimerResponse = twtRes.Result; Boolean success = createTimerResponse.getInt("success", 0) == 1; if (!success) { _logger.Error("[TVHclient] Can't create timer: '" + createTimerResponse.getString("error") + "'"); } } }
/// <summary> /// Update a single Timer /// </summary> /// <param name="info">The program info</param> /// <param name="cancellationToken">The CancellationToken</param> /// <returns></returns> public async Task UpdateTimerAsync(TimerInfo info, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] UpdateTimerAsync, call canceled or timed out."); return; } HTSMessage updateTimerMessage = new HTSMessage(); updateTimerMessage.Method = "updateDvrEntry"; updateTimerMessage.putField("id", info.Id); updateTimerMessage.putField("startExtra", (long)(info.PrePaddingSeconds / 60)); updateTimerMessage.putField("stopExtra", (long)(info.PostPaddingSeconds / 60)); //HTSMessage updateTimerResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(updateTimerMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(updateTimerMessage, lbrh); return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't update timer because of timeout"); } else { HTSMessage updateTimerResponse = twtRes.Result; Boolean success = updateTimerResponse.getInt("success", 0) == 1; if (!success) { _logger.Error("[TVHclient] Can't update timer: '" + updateTimerResponse.getString("error") + "'"); } } }
public async Task <LiveTvServiceStatusInfo> GetStatusInfoAsync(CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetStatusInfoAsync, call canceled or timed out."); return(new LiveTvServiceStatusInfo { Status = LiveTvServiceStatus.Unavailable }); } string serverName = _htsConnection.getServername(); string serverVersion = _htsConnection.getServerversion(); int serverProtokollVersion = _htsConnection.getServerProtocolVersion(); string diskSpace = _htsConnection.getDiskspace(); string serverVersionMessage = "<p>" + serverName + " " + serverVersion + "</p>" + "<p>HTSP protokoll version: " + serverProtokollVersion + "</p>" + "<p>Free diskspace: " + diskSpace + "</p>"; //List<LiveTvTunerInfo> tvTunerInfos = await _tunerDataHelper.buildTunerInfos(cancellationToken); TaskWithTimeoutRunner <List <LiveTvTunerInfo> > twtr = new TaskWithTimeoutRunner <List <LiveTvTunerInfo> >(TIMEOUT); TaskWithTimeoutResult <List <LiveTvTunerInfo> > twtRes = await twtr.RunWithTimeout(_tunerDataHelper.buildTunerInfos(cancellationToken)); List <LiveTvTunerInfo> tvTunerInfos; if (twtRes.HasTimeout) { tvTunerInfos = new List <LiveTvTunerInfo>(); } else { tvTunerInfos = twtRes.Result; } return(new LiveTvServiceStatusInfo { Version = serverVersionMessage, Tuners = tvTunerInfos, Status = LiveTvServiceStatus.Ok, }); }
public async Task UpdateTimerAsync(TimerInfo info, CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogDebug("[TVHclient] LiveTvService.UpdateTimerAsync: call cancelled or timed out"); return; } HTSMessage updateTimerMessage = new HTSMessage(); updateTimerMessage.Method = "updateDvrEntry"; updateTimerMessage.putField("id", info.Id); updateTimerMessage.putField("startExtra", (long)(info.PrePaddingSeconds / 60)); updateTimerMessage.putField("stopExtra", (long)(info.PostPaddingSeconds / 60)); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnectionHandler.SendMessage(updateTimerMessage, lbrh); LastRecordingChange = DateTime.UtcNow; return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.LogError("[TVHclient] LiveTvService.UpdateTimerAsync: can't update timer because the timeout was reached"); } else { HTSMessage updateTimerResponse = twtRes.Result; Boolean success = updateTimerResponse.getInt("success", 0) == 1; if (!success) { if (updateTimerResponse.containsField("error")) { _logger.LogError("[TVHclient] LiveTvService.UpdateTimerAsync: can't update timer: '{why}'", updateTimerResponse.getString("error")); } else if (updateTimerResponse.containsField("noaccess")) { _logger.LogError("[TVHclient] LiveTvService.UpdateTimerAsync: can't update timer: '{why}'", updateTimerResponse.getString("noaccess")); } } } }
/// <summary> /// Cancel the Series Timer /// </summary> /// <param name="timerId">The Timer Id</param> /// <param name="cancellationToken">The CancellationToken</param> /// <returns></returns> public async Task CancelSeriesTimerAsync(string timerId, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] CancelSeriesTimerAsync, call canceled or timed out."); return; } HTSMessage deleteAutorecMessage = new HTSMessage(); deleteAutorecMessage.Method = "deleteAutorecEntry"; deleteAutorecMessage.putField("id", timerId); //HTSMessage deleteAutorecResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(deleteAutorecMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(deleteAutorecMessage, lbrh); return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't delete recording because of timeout"); } else { HTSMessage deleteAutorecResponse = twtRes.Result; Boolean success = deleteAutorecResponse.getInt("success", 0) == 1; if (!success) { _logger.Error("[TVHclient] Can't cancel timer: '" + deleteAutorecResponse.getString("error") + "'"); } } }
public async Task CancelTimerAsync(string timerId, CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] CancelTimerAsync, call canceled or timed out."); return; } HTSMessage cancelTimerMessage = new HTSMessage(); cancelTimerMessage.Method = "cancelDvrEntry"; cancelTimerMessage.putField("id", timerId); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnectionHandler.SendMessage(cancelTimerMessage, lbrh); LastRecordingChange = DateTimeOffset.UtcNow; return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't cancel timer because of timeout"); } else { HTSMessage cancelTimerResponse = twtRes.Result; Boolean success = cancelTimerResponse.getInt("success", 0) == 1; if (!success) { if (cancelTimerResponse.containsField("error")) { _logger.Error("[TVHclient] Can't cancel timer: '" + cancelTimerResponse.getString("error") + "'"); } else if (cancelTimerResponse.containsField("noaccess")) { _logger.Error("[TVHclient] Can't cancel timer: '" + cancelTimerResponse.getString("noaccess") + "'"); } } } }
public async Task DeleteRecordingAsync(string recordingId, CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogInformation("[TVHclient] DeleteRecordingAsync, call canceled or timed out."); return; } HTSMessage deleteRecordingMessage = new HTSMessage(); deleteRecordingMessage.Method = "deleteDvrEntry"; deleteRecordingMessage.putField("id", recordingId); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnectionHandler.SendMessage(deleteRecordingMessage, lbrh); LastRecordingChange = DateTime.UtcNow; return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.LogError("[TVHclient] Can't delete recording because of timeout"); } else { HTSMessage deleteRecordingResponse = twtRes.Result; Boolean success = deleteRecordingResponse.getInt("success", 0) == 1; if (!success) { if (deleteRecordingResponse.containsField("error")) { _logger.LogError("[TVHclient] Can't delete recording: '{why}'", deleteRecordingResponse.getString("error")); } else if (deleteRecordingResponse.containsField("noaccess")) { _logger.LogError("[TVHclient] Can't delete recording: '{why}'", deleteRecordingResponse.getString("noaccess")); } } } }
public async Task <IEnumerable <SeriesTimerInfo> > GetSeriesTimersAsync(CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogInformation("[TVHclient] GetSeriesTimersAsync, call canceled ot timed out - returning empty list."); return(new List <SeriesTimerInfo>()); } TaskWithTimeoutRunner <IEnumerable <SeriesTimerInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <SeriesTimerInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <SeriesTimerInfo> > twtRes = await twtr.RunWithTimeout(_htsConnectionHandler.BuildAutorecInfos(cancellationToken)); if (twtRes.HasTimeout) { return(new List <SeriesTimerInfo>()); } return(twtRes.Result); }
public async Task <IEnumerable <TimerInfo> > GetTimersAsync(CancellationToken cancellationToken) { // retrieve the 'Pending' recordings"); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetTimersAsync, call canceled or timed out - returning empty list."); return(new List <TimerInfo>()); } TaskWithTimeoutRunner <IEnumerable <TimerInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <TimerInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <TimerInfo> > twtRes = await twtr.RunWithTimeout(_htsConnectionHandler.BuildPendingTimersInfos(cancellationToken)); if (twtRes.HasTimeout) { return(new List <TimerInfo>()); } return(twtRes.Result); }
public async Task <IEnumerable <MyRecordingInfo> > GetAllRecordingsAsync(CancellationToken cancellationToken) { // retrieve all 'Pending', 'Inprogress' and 'Completed' recordings // we don't deliver the 'Pending' recordings int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogInformation("[TVHclient] GetRecordingsAsync, call canceled or timed out - returning empty list."); return(new List <MyRecordingInfo>()); } TaskWithTimeoutRunner <IEnumerable <MyRecordingInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <MyRecordingInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <MyRecordingInfo> > twtRes = await twtr.RunWithTimeout(_htsConnectionHandler.BuildDvrInfos(cancellationToken)); if (twtRes.HasTimeout) { return(new List <MyRecordingInfo>()); } return(twtRes.Result); }
public async Task<LiveTvServiceStatusInfo> GetStatusInfoAsync(CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetStatusInfoAsync, call canceled or timed out."); return new LiveTvServiceStatusInfo { Status = LiveTvServiceStatus.Unavailable }; } string serverName = _htsConnection.getServername(); string serverVersion = _htsConnection.getServerversion(); int serverProtokollVersion = _htsConnection.getServerProtocolVersion(); string diskSpace = _htsConnection.getDiskspace(); string serverVersionMessage = "<p>" + serverName + " " + serverVersion + "</p>" + "<p>HTSP protokoll version: " + serverProtokollVersion + "</p>" + "<p>Free diskspace: " + diskSpace + "</p>"; //List<LiveTvTunerInfo> tvTunerInfos = await _tunerDataHelper.buildTunerInfos(cancellationToken); TaskWithTimeoutRunner<List<LiveTvTunerInfo>> twtr = new TaskWithTimeoutRunner<List<LiveTvTunerInfo>>(TIMEOUT); TaskWithTimeoutResult<List<LiveTvTunerInfo>> twtRes = await twtr.RunWithTimeout(_tunerDataHelper.buildTunerInfos(cancellationToken)); List<LiveTvTunerInfo> tvTunerInfos; if (twtRes.HasTimeout) { tvTunerInfos = new List<LiveTvTunerInfo>(); } else { tvTunerInfos = twtRes.Result; } return new LiveTvServiceStatusInfo { Version = serverVersionMessage, Tuners = tvTunerInfos, Status = LiveTvServiceStatus.Ok, }; }
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetProgramsAsync, call canceled or timed out - returning empty list."); return new List<ProgramInfo>(); } GetEventsResponseHandler currGetEventsResponseHandler = new GetEventsResponseHandler(startDateUtc, endDateUtc, _logger, cancellationToken); HTSMessage queryEvents = new HTSMessage(); queryEvents.Method = "getEvents"; queryEvents.putField("channelId", Convert.ToInt32(channelId)); _htsConnection.sendMessage(queryEvents, currGetEventsResponseHandler); //IEnumerable<ProgramInfo> pi = await currGetEventsResponseHandler.GetEvents(cancellationToken); //return pi; TaskWithTimeoutRunner<IEnumerable<ProgramInfo>> twtr = new TaskWithTimeoutRunner<IEnumerable<ProgramInfo>>(TIMEOUT); TaskWithTimeoutResult<IEnumerable<ProgramInfo>> twtRes = await twtr.RunWithTimeout(currGetEventsResponseHandler.GetEvents(cancellationToken)); if (twtRes.HasTimeout) { return new List<ProgramInfo>(); } return twtRes.Result; }
public async Task<MediaSourceInfo> GetRecordingStream(string recordingId, string mediaSourceId, CancellationToken cancellationToken) { ensureConnection(); HTSMessage getTicketMessage = new HTSMessage(); getTicketMessage.Method = "getTicket"; getTicketMessage.putField("dvrId", recordingId); //HTSMessage getTicketResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(getTicketMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner<HTSMessage> twtr = new TaskWithTimeoutRunner<HTSMessage>(TIMEOUT); TaskWithTimeoutResult<HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew<HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(getTicketMessage, lbrh); return lbrh.getResponse(); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't delete recording because of timeout"); } else { HTSMessage getTicketResponse = twtRes.Result; if (_subscriptionId == int.MaxValue) { _subscriptionId = 0; } int currSubscriptionId = _subscriptionId++; return new MediaSourceInfo { Id = "" + currSubscriptionId, Path = _httpBaseUrl + getTicketResponse.getString("path") + "?ticket=" + getTicketResponse.getString("ticket"), Protocol = MediaProtocol.Http, MediaStreams = new List<MediaStream> { new MediaStream { Type = MediaStreamType.Video, // Set the index to -1 because we don't know the exact index of the video stream within the container Index = -1, // Set to true if unknown to enable deinterlacing IsInterlaced = true }, new MediaStream { Type = MediaStreamType.Audio, // Set the index to -1 because we don't know the exact index of the audio stream within the container Index = -1 } } }; } throw new TimeoutException(); }
/// <summary> /// Cancel the Series Timer /// </summary> /// <param name="timerId">The Timer Id</param> /// <param name="cancellationToken">The CancellationToken</param> /// <returns></returns> public async Task CancelSeriesTimerAsync(string timerId, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] CancelSeriesTimerAsync, call canceled or timed out."); return; } HTSMessage deleteAutorecMessage = new HTSMessage(); deleteAutorecMessage.Method = "deleteAutorecEntry"; deleteAutorecMessage.putField("id", timerId); //HTSMessage deleteAutorecResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(deleteAutorecMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner<HTSMessage> twtr = new TaskWithTimeoutRunner<HTSMessage>(TIMEOUT); TaskWithTimeoutResult<HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew<HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(deleteAutorecMessage, lbrh); return lbrh.getResponse(); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't delete recording because of timeout"); } else { HTSMessage deleteAutorecResponse = twtRes.Result; Boolean success = deleteAutorecResponse.getInt("success", 0) == 1; if (!success) { _logger.Error("[TVHclient] Can't cancel timer: '" + deleteAutorecResponse.getString("error") + "'"); } } }
/// <summary> /// Update a single Timer /// </summary> /// <param name="info">The program info</param> /// <param name="cancellationToken">The CancellationToken</param> /// <returns></returns> public async Task UpdateTimerAsync(TimerInfo info, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] UpdateTimerAsync, call canceled or timed out."); return; } HTSMessage updateTimerMessage = new HTSMessage(); updateTimerMessage.Method = "updateDvrEntry"; updateTimerMessage.putField("id", info.Id); updateTimerMessage.putField("startExtra", (long)(info.PrePaddingSeconds / 60)); updateTimerMessage.putField("stopExtra", (long)(info.PostPaddingSeconds / 60)); //HTSMessage updateTimerResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(updateTimerMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner<HTSMessage> twtr = new TaskWithTimeoutRunner<HTSMessage>(TIMEOUT); TaskWithTimeoutResult<HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew<HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(updateTimerMessage, lbrh); return lbrh.getResponse(); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't update timer because of timeout"); } else { HTSMessage updateTimerResponse = twtRes.Result; Boolean success = updateTimerResponse.getInt("success", 0) == 1; if (!success) { _logger.Error("[TVHclient] Can't update timer: '" + updateTimerResponse.getString("error") + "'"); } } }
/// <summary> /// Create a new recording /// </summary> /// <param name="info">The TimerInfo</param> /// <param name="cancellationToken">The cancellationToken</param> /// <returns></returns> public async Task CreateTimerAsync(TimerInfo info, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] CreateTimerAsync, call canceled or timed out."); return; } HTSMessage createTimerMessage = new HTSMessage(); createTimerMessage.Method = "addDvrEntry"; createTimerMessage.putField("channelId", info.ChannelId); createTimerMessage.putField("start", DateTimeHelper.getUnixUTCTimeFromUtcDateTime(info.StartDate)); createTimerMessage.putField("stop", DateTimeHelper.getUnixUTCTimeFromUtcDateTime(info.EndDate)); createTimerMessage.putField("startExtra", (long)(info.PrePaddingSeconds / 60)); createTimerMessage.putField("stopExtra", (long)(info.PostPaddingSeconds / 60)); createTimerMessage.putField("priority", _priority); // info.Priority delivers always 0 - no GUI createTimerMessage.putField("configName", _profile); createTimerMessage.putField("description", info.Overview); createTimerMessage.putField("title", info.Name); createTimerMessage.putField("creator", Plugin.Instance.Configuration.Username); //HTSMessage createTimerResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(createTimerMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner<HTSMessage> twtr = new TaskWithTimeoutRunner<HTSMessage>(TIMEOUT); TaskWithTimeoutResult<HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew<HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(createTimerMessage, lbrh); return lbrh.getResponse(); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't create timer because of timeout"); } else { HTSMessage createTimerResponse = twtRes.Result; Boolean success = createTimerResponse.getInt("success", 0) == 1; if (!success) { _logger.Error("[TVHclient] Can't create timer: '" + createTimerResponse.getString("error") + "'"); } } }
/// <summary> /// Gets the Recordings async /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{IEnumerable{RecordingInfo}}</returns> public async Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(CancellationToken cancellationToken) { // retrieve all 'Pending', 'Inprogress' and 'Completed' recordings // we don't deliver the 'Pending' recordings ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetRecordingsAsync, call canceled or timed out - returning empty list."); return new List<RecordingInfo>(); } //IEnumerable<RecordingInfo> data = await _dvrDataHelper.buildDvrInfos(cancellationToken); //return data; TaskWithTimeoutRunner<IEnumerable<RecordingInfo>> twtr = new TaskWithTimeoutRunner<IEnumerable<RecordingInfo>>(TIMEOUT); TaskWithTimeoutResult<IEnumerable<RecordingInfo>> twtRes = await twtr.RunWithTimeout(_dvrDataHelper.buildDvrInfos(cancellationToken)); if (twtRes.HasTimeout) { return new List<RecordingInfo>(); } return twtRes.Result; }
public async Task <MediaSourceInfo> GetChannelStream(string channelId, string mediaSourceId, CancellationToken cancellationToken) { HTSMessage getTicketMessage = new HTSMessage(); getTicketMessage.Method = "getTicket"; getTicketMessage.putField("channelId", channelId); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnectionHandler.SendMessage(getTicketMessage, lbrh); return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Timeout obtaining playback authentication ticket from TVH"); } else { HTSMessage getTicketResponse = twtRes.Result; if (_subscriptionId == int.MaxValue) { _subscriptionId = 0; } int currSubscriptionId = _subscriptionId++; if (_htsConnectionHandler.GetEnableSubsMaudios()) { _logger.Info("[TVHclient] Support for live TV subtitles and multiple audio tracks is enabled."); MediaSourceInfo livetvasset = new MediaSourceInfo(); livetvasset.Id = "" + currSubscriptionId; // Use HTTP basic auth instead of TVH ticketing system for authentication to allow the users to switch subs or audio tracks at any time livetvasset.Path = _htsConnectionHandler.GetHttpBaseUrl() + getTicketResponse.getString("path"); livetvasset.Protocol = MediaProtocol.Http; // Probe the asset stream to determine available sub-streams string livetvasset_probeUrl = "" + livetvasset.Path; string livetvasset_source = "LiveTV"; // Probe the asset stream to determine available sub-streams await ProbeStream(livetvasset, livetvasset_probeUrl, livetvasset_source, cancellationToken); return(livetvasset); } else { return(new MediaSourceInfo { Id = "" + currSubscriptionId, Path = _htsConnectionHandler.GetHttpBaseUrl() + getTicketResponse.getString("path") + "?ticket=" + getTicketResponse.getString("ticket"), Protocol = MediaProtocol.Http, MediaStreams = new List <MediaStream> { new MediaStream { Type = MediaStreamType.Video, // Set the index to -1 because we don't know the exact index of the video stream within the container Index = -1, // Set to true if unknown to enable deinterlacing IsInterlaced = true }, new MediaStream { Type = MediaStreamType.Audio, // Set the index to -1 because we don't know the exact index of the audio stream within the container Index = -1 } } }); } } throw new TimeoutException(""); }
public async Task <MediaSourceInfo> GetRecordingStream(string recordingId, string mediaSourceId, CancellationToken cancellationToken) { ensureConnection(); HTSMessage getTicketMessage = new HTSMessage(); getTicketMessage.Method = "getTicket"; getTicketMessage.putField("dvrId", recordingId); //HTSMessage getTicketResponse = await Task.Factory.StartNew<HTSMessage>(() => //{ // LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); // _htsConnection.sendMessage(getTicketMessage, lbrh); // return lbrh.getResponse(); //}); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnection.sendMessage(getTicketMessage, lbrh); return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Can't delete recording because of timeout"); } else { HTSMessage getTicketResponse = twtRes.Result; if (_subscriptionId == int.MaxValue) { _subscriptionId = 0; } int currSubscriptionId = _subscriptionId++; return(new MediaSourceInfo { Id = "" + currSubscriptionId, Path = _httpBaseUrl + getTicketResponse.getString("path") + "?ticket=" + getTicketResponse.getString("ticket"), Protocol = MediaProtocol.Http, MediaStreams = new List <MediaStream> { new MediaStream { Type = MediaStreamType.Video, // Set the index to -1 because we don't know the exact index of the video stream within the container Index = -1, // Set to true if unknown to enable deinterlacing IsInterlaced = true }, new MediaStream { Type = MediaStreamType.Audio, // Set the index to -1 because we don't know the exact index of the audio stream within the container Index = -1 } } }); } throw new TimeoutException(); }
public async Task<MediaSourceInfo> GetRecordingStream(string recordingId, string mediaSourceId, CancellationToken cancellationToken) { HTSMessage getTicketMessage = new HTSMessage(); getTicketMessage.Method = "getTicket"; getTicketMessage.putField("dvrId", recordingId); TaskWithTimeoutRunner<HTSMessage> twtr = new TaskWithTimeoutRunner<HTSMessage>(TIMEOUT); TaskWithTimeoutResult<HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew<HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnectionHandler.SendMessage(getTicketMessage, lbrh); return lbrh.getResponse(); })); if (twtRes.HasTimeout) { _logger.Error("[TVHclient] Timeout obtaining playback authentication ticket from TVH"); } else { HTSMessage getTicketResponse = twtRes.Result; if (_subscriptionId == int.MaxValue) { _subscriptionId = 0; } int currSubscriptionId = _subscriptionId++; if (_htsConnectionHandler.GetEnableSubsMaudios()) { _logger.Info("[TVHclient] Support for live TV subtitles and multiple audio tracks is enabled."); MediaSourceInfo recordingasset = new MediaSourceInfo(); recordingasset.Id = "" + currSubscriptionId; // Use HTTP basic auth instead of TVH ticketing system for authentication to allow the users to switch subs or audio tracks at any time recordingasset.Path = _htsConnectionHandler.GetHttpBaseUrl() + getTicketResponse.getString("path"); recordingasset.Protocol = MediaProtocol.Http; // Set asset source and type for stream probing and logging string recordingasset_probeUrl = "" + recordingasset.Path; string recordingasset_source = "Recording"; // Probe the asset stream to determine available sub-streams await ProbeStream(recordingasset, recordingasset_probeUrl, recordingasset_source, cancellationToken); // If enabled, force video deinterlacing for recordings if (_htsConnectionHandler.GetForceDeinterlace()) { _logger.Info("[TVHclient] Force video deinterlacing for all channels and recordings is enabled."); foreach (MediaStream i in recordingasset.MediaStreams) { if (i.Type == MediaStreamType.Video && i.IsInterlaced == false) { i.IsInterlaced = true; } } } return recordingasset; } else { return new MediaSourceInfo { Id = "" + currSubscriptionId, Path = _htsConnectionHandler.GetHttpBaseUrl() + getTicketResponse.getString("path") + "?ticket=" + getTicketResponse.getString("ticket"), Protocol = MediaProtocol.Http, MediaStreams = new List<MediaStream> { new MediaStream { Type = MediaStreamType.Video, // Set the index to -1 because we don't know the exact index of the video stream within the container Index = -1, // Set to true if unknown to enable deinterlacing IsInterlaced = true }, new MediaStream { Type = MediaStreamType.Audio, // Set the index to -1 because we don't know the exact index of the audio stream within the container Index = -1 } } }; } } throw new TimeoutException(); }
public async Task <MediaSourceInfo> GetRecordingStream(string recordingId, string mediaSourceId, CancellationToken cancellationToken) { HTSMessage getTicketMessage = new HTSMessage(); getTicketMessage.Method = "getTicket"; getTicketMessage.putField("dvrId", recordingId); TaskWithTimeoutRunner <HTSMessage> twtr = new TaskWithTimeoutRunner <HTSMessage>(TIMEOUT); TaskWithTimeoutResult <HTSMessage> twtRes = await twtr.RunWithTimeout(Task.Factory.StartNew <HTSMessage>(() => { LoopBackResponseHandler lbrh = new LoopBackResponseHandler(); _htsConnectionHandler.SendMessage(getTicketMessage, lbrh); return(lbrh.getResponse()); })); if (twtRes.HasTimeout) { _logger.LogError("[TVHclient] Timeout obtaining playback authentication ticket from TVH"); } else { HTSMessage getTicketResponse = twtRes.Result; if (_subscriptionId == int.MaxValue) { _subscriptionId = 0; } int currSubscriptionId = _subscriptionId++; if (_htsConnectionHandler.GetEnableSubsMaudios()) { _logger.LogInformation("[TVHclient] Support for live TV subtitles and multiple audio tracks is enabled."); MediaSourceInfo recordingasset = new MediaSourceInfo(); recordingasset.Id = "" + currSubscriptionId; // Use HTTP basic auth instead of TVH ticketing system for authentication to allow the users to switch subs or audio tracks at any time recordingasset.Path = _htsConnectionHandler.GetHttpBaseUrl() + getTicketResponse.getString("path"); recordingasset.Protocol = MediaProtocol.Http; // Set asset source and type for stream probing and logging string recordingasset_probeUrl = "" + recordingasset.Path; // If enabled, force video deinterlacing for recordings if (_htsConnectionHandler.GetForceDeinterlace()) { _logger.LogInformation("[TVHclient] Force video deinterlacing for all channels and recordings is enabled."); foreach (MediaStream i in recordingasset.MediaStreams) { if (i.Type == MediaStreamType.Video && i.IsInterlaced == false) { i.IsInterlaced = true; } } } return(recordingasset); } else { return(new MediaSourceInfo { Id = "" + currSubscriptionId, Path = _htsConnectionHandler.GetHttpBaseUrl() + getTicketResponse.getString("path") + "?ticket=" + getTicketResponse.getString("ticket"), Protocol = MediaProtocol.Http, MediaStreams = new List <MediaStream> { new MediaStream { Type = MediaStreamType.Video, // Set the index to -1 because we don't know the exact index of the video stream within the container Index = -1, // Set to true if unknown to enable deinterlacing IsInterlaced = true }, new MediaStream { Type = MediaStreamType.Audio, // Set the index to -1 because we don't know the exact index of the audio stream within the container Index = -1 } } }); } } throw new TimeoutException(); }
/// <summary> /// Get the recurrent recordings /// </summary> /// <param name="cancellationToken">The CancellationToken</param> /// <returns></returns> public async Task<IEnumerable<SeriesTimerInfo>> GetSeriesTimersAsync(CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetSeriesTimersAsync, call canceled ot timed out - returning empty list."); return new List<SeriesTimerInfo>(); } //IEnumerable<SeriesTimerInfo> data = await _autorecDataHelper.buildAutorecInfos(cancellationToken); //return data; TaskWithTimeoutRunner<IEnumerable<SeriesTimerInfo>> twtr = new TaskWithTimeoutRunner<IEnumerable<SeriesTimerInfo>>(TIMEOUT); TaskWithTimeoutResult<IEnumerable<SeriesTimerInfo>> twtRes = await twtr.RunWithTimeout(_autorecDataHelper.buildAutorecInfos(cancellationToken)); if (twtRes.HasTimeout) { return new List<SeriesTimerInfo>(); } return twtRes.Result; }
public async Task<IEnumerable<TimerInfo>> GetTimersAsync(CancellationToken cancellationToken) { // retrieve the 'Pending' recordings"); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetTimersAsync, call canceled or timed out - returning empty list."); return new List<TimerInfo>(); } TaskWithTimeoutRunner<IEnumerable<TimerInfo>> twtr = new TaskWithTimeoutRunner<IEnumerable<TimerInfo>>(TIMEOUT); TaskWithTimeoutResult<IEnumerable<TimerInfo>> twtRes = await twtr.RunWithTimeout(_htsConnectionHandler.BuildPendingTimersInfos(cancellationToken)); if (twtRes.HasTimeout) { return new List<TimerInfo>(); } return twtRes.Result; }