public void add(HTSMessage message) { _tunerDataHelper.addTunerInfo(message); lock (_data) { if (_data.ContainsKey(message.getInt("channelId"))) { int channelID = message.getInt("channelId"); HTSMessage storedMessage = _data[channelID]; if (storedMessage != null) { foreach (KeyValuePair <string, object> entry in message) { if (storedMessage.containsField(entry.Key)) { storedMessage.removeField(entry.Key); } storedMessage.putField(entry.Key, entry.Value); } } else { _logger.Error("[TVHclient] ChannelDataHelper: update for channelID '" + channelID + "' but no initial data found!"); } } else { if (message.containsField("channelNumber") && message.getInt("channelNumber") > 0) // use only channels with number > 0 { _data.Add(message.getInt("channelId"), message); } } } }
public void Add(HTSMessage message) { if (_tunerDataHelper != null) { // TVHeadend don't send the information we need // _tunerDataHelper.addTunerInfo(message); } lock (_data) { try { int channelID = message.getInt("channelId"); if (_data.ContainsKey(channelID)) { HTSMessage storedMessage = _data[channelID]; if (storedMessage != null) { foreach (KeyValuePair <string, object> entry in message) { if (storedMessage.containsField(entry.Key)) { storedMessage.removeField(entry.Key); } storedMessage.putField(entry.Key, entry.Value); } } else { _logger.LogError("[TVHclient] ChannelDataHelper: update for channelID '{id}' but no initial data found!", channelID); } } else { if (message.containsField("channelNumber") && message.getInt("channelNumber") > 0) // use only channels with number > 0 { _data.Add(channelID, message); } } } catch (Exception ex) { _logger.LogError(ex, "[TVHclient] ChannelDataHelper.Add caught exception. HTSMessage: {m} ", message); } } }
/// <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") + "'"); } } }
public void addTunerInfo(HTSMessage tunerMessage) { lock (_data) { string channelID = "" + tunerMessage.getInt("channelId"); if (_data.ContainsKey(channelID)) { _data.Remove(channelID); } _data.Add(channelID, tunerMessage); } }
public void Add(HTSMessage message) { try { int channelID = message.getInt("channelId"); if (_data.TryGetValue(channelID, out HTSMessage storedMessage)) { if (storedMessage != null) { foreach (KeyValuePair <string, object> entry in message) { if (storedMessage.containsField(entry.Key)) { storedMessage.removeField(entry.Key); } storedMessage.putField(entry.Key, entry.Value); } } else { _logger.Error("[TVHclient] ChannelDataHelper: update for channelID '" + channelID + "' but no initial data found!"); } } else { if (message.containsField("channelNumber") && message.getInt("channelNumber") > 0) // use only channels with number > 0 { _data.TryAdd(channelID, message); } } } catch (Exception ex) { _logger.Error("[TVHclient] ChannelDataHelper.Add caught exception: " + ex.Message + "\nHTSmessage=" + message); } }
/// <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 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 Task <IEnumerable <RecordingInfo> > buildDvrInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <RecordingInfo> >(() => { lock (_data) { List <RecordingInfo> result = new List <RecordingInfo>(); foreach (KeyValuePair <string, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] DvrDataHelper.buildDvrInfos, call canceled - returning part list."); return result; } HTSMessage m = entry.Value; RecordingInfo ri = new RecordingInfo(); try { if (m.containsField("id")) { ri.Id = "" + m.getInt("id"); } } catch (InvalidCastException) { } try { if (m.containsField("channel")) { ri.ChannelId = "" + m.getInt("channel"); } } catch (InvalidCastException) { } try { if (m.containsField("start")) { long unixUtc = m.getLong("start"); ri.StartDate = _initialDateTimeUTC.AddSeconds(unixUtc).ToUniversalTime(); } } catch (InvalidCastException) { } try { if (m.containsField("stop")) { long unixUtc = m.getLong("stop"); ri.EndDate = _initialDateTimeUTC.AddSeconds(unixUtc).ToUniversalTime(); } } catch (InvalidCastException) { } try { if (m.containsField("title")) { ri.Name = m.getString("title"); } } catch (InvalidCastException) { } try { if (m.containsField("description")) { ri.Overview = m.getString("description"); } } catch (InvalidCastException) { } try { if (m.containsField("summary")) { ri.EpisodeTitle = m.getString("summary"); } } catch (InvalidCastException) { } ri.HasImage = false; // public string ImagePath { get; set; } // public string ImageUrl { get; set; } try { if (m.containsField("state")) { string state = m.getString("state"); switch (state) { case "completed": ri.Status = RecordingStatus.Completed; break; case "scheduled": ri.Status = RecordingStatus.Scheduled; continue; //break; case "missed": ri.Status = RecordingStatus.Error; break; case "recording": ri.Status = RecordingStatus.InProgress; break; default: _logger.Fatal("[TVHclient] DvrDataHelper.buildDvrInfos: state '" + state + "' not handled!"); continue; //break; } } } catch (InvalidCastException) { } // Path must not be set to force emby use of the LiveTvService methods!!!! //if (m.containsField("path")) //{ // ri.Path = m.getString("path"); //} try { if (m.containsField("autorecId")) { ri.SeriesTimerId = m.getString("autorecId"); } } catch (InvalidCastException) { } try { if (m.containsField("eventId")) { ri.ProgramId = "" + m.getInt("eventId"); } } catch (InvalidCastException) { } /* * public ProgramAudio? Audio { get; set; } * public ChannelType ChannelType { get; set; } * public float? CommunityRating { get; set; } * public List<string> Genres { get; set; } * public bool? IsHD { get; set; } * public bool IsKids { get; set; } * public bool IsLive { get; set; } * public bool IsMovie { get; set; } * public bool IsNews { get; set; } * public bool IsPremiere { get; set; } * public bool IsRepeat { get; set; } * public bool IsSeries { get; set; } * public bool IsSports { get; set; } * public string OfficialRating { get; set; } * public DateTime? OriginalAirDate { get; set; } * public string Url { get; set; } */ result.Add(ri); } return result; } })); }
public Task <IEnumerable <TimerInfo> > buildPendingTimersInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <TimerInfo> >(() => { lock (_data) { List <TimerInfo> result = new List <TimerInfo>(); foreach (KeyValuePair <string, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] DvrDataHelper.buildDvrInfos, call canceled - returning part list."); return result; } HTSMessage m = entry.Value; TimerInfo ti = new TimerInfo(); try { if (m.containsField("id")) { ti.Id = "" + m.getInt("id"); } } catch (InvalidCastException) { } try { if (m.containsField("channel")) { ti.ChannelId = "" + m.getInt("channel"); } } catch (InvalidCastException) { } try { if (m.containsField("start")) { long unixUtc = m.getLong("start"); ti.StartDate = _initialDateTimeUTC.AddSeconds(unixUtc).ToUniversalTime(); } } catch (InvalidCastException) { } try { if (m.containsField("stop")) { long unixUtc = m.getLong("stop"); ti.EndDate = _initialDateTimeUTC.AddSeconds(unixUtc).ToUniversalTime(); } } catch (InvalidCastException) { } try { if (m.containsField("title")) { ti.Name = m.getString("title"); } } catch (InvalidCastException) { } try { if (m.containsField("description")) { ti.Overview = m.getString("description"); } } catch (InvalidCastException) { } try { if (m.containsField("state")) { string state = m.getString("state"); switch (state) { case "scheduled": ti.Status = RecordingStatus.Scheduled; break; default: // only scheduled timers need to be delivered continue; } } } catch (InvalidCastException) { } try { if (m.containsField("startExtra")) { ti.PrePaddingSeconds = (int)m.getLong("startExtra") * 60; ti.IsPrePaddingRequired = true; } } catch (InvalidCastException) { } try { if (m.containsField("stopExtra")) { ti.PostPaddingSeconds = (int)m.getLong("stopExtra") * 60; ti.IsPostPaddingRequired = true; } } catch (InvalidCastException) { } try { if (m.containsField("priority")) { ti.Priority = m.getInt("priority"); } } catch (InvalidCastException) { } try { if (m.containsField("autorecId")) { ti.SeriesTimerId = m.getString("autorecId"); } } catch (InvalidCastException) { } try { if (m.containsField("eventId")) { ti.ProgramId = "" + m.getInt("eventId"); } } catch (InvalidCastException) { } result.Add(ti); } return result; } })); }
public Task <IEnumerable <SeriesTimerInfo> > buildAutorecInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <SeriesTimerInfo> >(() => { lock (_data) { List <SeriesTimerInfo> result = new List <SeriesTimerInfo>(); foreach (KeyValuePair <string, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] DvrDataHelper.buildDvrInfos, call canceled - returning part list."); return result; } HTSMessage m = entry.Value; SeriesTimerInfo sti = new SeriesTimerInfo(); try { if (m.containsField("id")) { sti.Id = m.getString("id"); } } catch (InvalidCastException) { } try { if (m.containsField("daysOfWeek")) { int daysOfWeek = m.getInt("daysOfWeek"); sti.Days = getDayOfWeekListFromInt(daysOfWeek); } } catch (InvalidCastException) { } sti.StartDate = DateTime.Now.ToUniversalTime(); try { if (m.containsField("retention")) { int retentionInDays = m.getInt("retention"); if (DateTime.MaxValue.AddDays(-retentionInDays) < DateTime.Now) { _logger.Error("[TVHclient] Change during 'EndDate' calculation: set retention value from '" + retentionInDays + "' to '365' days"); sti.EndDate = DateTime.Now.AddDays(365).ToUniversalTime(); } else { sti.EndDate = DateTime.Now.AddDays(retentionInDays).ToUniversalTime(); } } } catch (Exception e) { _logger.Error("[TVHclient] Exception during 'EndDate' calculation: " + e.Message + "\n" + e + "\n" + m.ToString()); } try { if (m.containsField("channel")) { sti.ChannelId = "" + m.getInt("channel"); } } catch (InvalidCastException) { } try { if (m.containsField("startExtra")) { sti.PrePaddingSeconds = (int)m.getLong("startExtra") * 60; sti.IsPrePaddingRequired = true; } } catch (InvalidCastException) { } try { if (m.containsField("stopExtra")) { sti.PostPaddingSeconds = (int)m.getLong("stopExtra") * 60; sti.IsPostPaddingRequired = true; } } catch (InvalidCastException) { } try { if (m.containsField("title")) { sti.Name = m.getString("title"); } } catch (InvalidCastException) { } try { if (m.containsField("description")) { sti.Overview = m.getString("description"); } } catch (InvalidCastException) { } try { if (m.containsField("priority")) { sti.Priority = m.getInt("priority"); } } catch (InvalidCastException) { } try { if (m.containsField("title")) { sti.SeriesId = m.getString("title"); } } catch (InvalidCastException) { } /* * public string ProgramId { get; set; } * public bool RecordAnyChannel { get; set; } * public bool RecordAnyTime { get; set; } * public bool RecordNewOnly { get; set; } */ result.Add(sti); } return result; } })); }
public Task <IEnumerable <ChannelInfo> > buildChannelInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <ChannelInfo> >(() => { lock (_data) { List <ChannelInfo> result = new List <ChannelInfo>(); foreach (KeyValuePair <int, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos, call canceled - returning part list."); return result; } HTSMessage m = entry.Value; ChannelInfo ci = new ChannelInfo(); ci.Id = "" + entry.Key; ci.ImagePath = ""; if (m.containsField("channelIcon")) { string channelIcon = m.getString("channelIcon"); Uri uriResult; bool uriCheckResult = Uri.TryCreate(channelIcon, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (uriCheckResult) { ci.ImageUrl = channelIcon; } else if (channelIcon.ToLower().StartsWith("picon://")) { ci.HasImage = true; _piconData.Add(ci.Id, channelIcon); } else { _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos: channelIcon '" + channelIcon + "' can not be handled properly for channelID '" + ci.Id + "'!"); } } if (m.containsField("channelName")) { string name = m.getString("channelName"); if (string.IsNullOrEmpty(name)) { continue; } ci.Name = m.getString("channelName"); } if (m.containsField("channelNumber")) { int chNo = m.getInt("channelNumber"); ci.Number = "" + chNo; } Boolean serviceFound = false; if (m.containsField("services")) { IList tunerInfoList = m.getList("services"); if (tunerInfoList != null && tunerInfoList.Count > 0) { HTSMessage firstServiceInList = (HTSMessage)tunerInfoList[0]; if (firstServiceInList.containsField("type")) { string type = firstServiceInList.getString("type").ToLower(); switch (type) { case "radio": ci.ChannelType = ChannelType.Radio; serviceFound = true; break; case "sdtv": case "hdtv": ci.ChannelType = ChannelType.TV; serviceFound = true; break; case "other": switch (_channelType4Other.ToLower()) { case "tv": _logger.Info("[TVHclient] ChannelDataHelper: map service type 'Other' to 'TV'."); ci.ChannelType = ChannelType.TV; serviceFound = true; break; case "radio": _logger.Info("[TVHclient] ChannelDataHelper: map service type 'Other' to 'Radio'."); ci.ChannelType = ChannelType.Radio; serviceFound = true; break; default: _logger.Error("[TVHclient] ChannelDataHelper: don't map service type 'Other' - will be ignored."); break; } break; default: _logger.Error("[TVHclient] ChannelDataHelper: unkown service type '" + type + "' - will be ignored."); break; } } } } if (!serviceFound) { _logger.Error("[TVHclient] ChannelDataHelper: unable to detect service-type from service list:" + m.ToString()); continue; } result.Add(ci); } return result; } })); }
public Task <IEnumerable <MyRecordingInfo> > buildDvrInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <MyRecordingInfo> >(() => { lock (_data) { List <MyRecordingInfo> result = new List <MyRecordingInfo>(); foreach (KeyValuePair <string, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.LogDebug("[TVHclient] DvrDataHelper.buildDvrInfos: call cancelled - returning partial list"); return result; } HTSMessage m = entry.Value; MyRecordingInfo ri = new MyRecordingInfo(); try { if (m.containsField("error")) { // When TVHeadend recordings are removed, their info can // still be kept around with a status of "completed". // The only way to identify them is from the error string // which is set to "File missing". Use that to not show // non-existing deleted recordings. if (m.getString("error").Contains("missing")) { continue; } } } catch (InvalidCastException) { } try { if (m.containsField("id")) { ri.Id = "" + m.getInt("id"); } } catch (InvalidCastException) { } try { if (m.containsField("path")) { ri.Path = "" + m.getString("path"); } } catch (InvalidCastException) { } try { if (m.containsField("url")) { ri.Url = "" + m.getString("url"); } } catch (InvalidCastException) { } try { if (m.containsField("channel")) { ri.ChannelId = "" + m.getInt("channel"); } } catch (InvalidCastException) { } try { if (m.containsField("start")) { long unixUtc = m.getLong("start"); ri.StartDate = _initialDateTimeUTC.AddSeconds(unixUtc).ToUniversalTime(); } } catch (InvalidCastException) { } try { if (m.containsField("stop")) { long unixUtc = m.getLong("stop"); ri.EndDate = _initialDateTimeUTC.AddSeconds(unixUtc).ToUniversalTime(); } } catch (InvalidCastException) { } try { if (m.containsField("title")) { ri.Name = m.getString("title"); } } catch (InvalidCastException) { } try { if (m.containsField("description")) { ri.Overview = m.getString("description"); } } catch (InvalidCastException) { } try { if (m.containsField("summary")) { ri.EpisodeTitle = m.getString("summary"); } } catch (InvalidCastException) { } ri.HasImage = false; // public string ImagePath { get; set; } // public string ImageUrl { get; set; } try { if (m.containsField("state")) { string state = m.getString("state"); switch (state) { case "completed": ri.Status = RecordingStatus.Completed; break; case "scheduled": ri.Status = RecordingStatus.New; continue; //break; case "missed": ri.Status = RecordingStatus.Error; break; case "recording": ri.Status = RecordingStatus.InProgress; break; default: _logger.LogCritical("[TVHclient] DvrDataHelper.buildDvrInfos: state '{state}' not handled", state); continue; //break; } } } catch (InvalidCastException) { } // Path must not be set to force emby use of the LiveTvService methods!!!! //if (m.containsField("path")) //{ // ri.Path = m.getString("path"); //} try { if (m.containsField("autorecId")) { ri.SeriesTimerId = m.getString("autorecId"); } } catch (InvalidCastException) { } try { if (m.containsField("eventId")) { ri.ProgramId = "" + m.getInt("eventId"); } } catch (InvalidCastException) { } /* * public ProgramAudio? Audio { get; set; } * public ChannelType ChannelType { get; set; } * public float? CommunityRating { get; set; } * public List<string> Genres { get; set; } * public bool? IsHD { get; set; } * public bool IsKids { get; set; } * public bool IsLive { get; set; } * public bool IsMovie { get; set; } * public bool IsNews { get; set; } * public bool IsPremiere { get; set; } * public bool IsRepeat { get; set; } * public bool IsSeries { get; set; } * public bool IsSports { get; set; } * public string OfficialRating { get; set; } * public DateTime? OriginalAirDate { get; set; } * public string Url { get; set; } */ result.Add(ri); } return result; } })); }
public Task <IEnumerable <ChannelInfo> > BuildChannelInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <ChannelInfo> >(() => { lock (_data) { List <ChannelInfo> result = new List <ChannelInfo>(); foreach (KeyValuePair <int, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.LogInformation("[TVHclient] ChannelDataHelper.buildChannelInfos, call canceled - returning part list."); return result; } HTSMessage m = entry.Value; try { ChannelInfo ci = new ChannelInfo(); ci.Id = "" + entry.Key; ci.ImagePath = ""; if (m.containsField("channelIcon")) { string channelIcon = m.getString("channelIcon"); Uri uriResult; bool uriCheckResult = Uri.TryCreate(channelIcon, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (uriCheckResult) { ci.ImageUrl = channelIcon; } else { ci.HasImage = true; if (!_piconData.ContainsKey(ci.Id)) { _piconData.Add(ci.Id, channelIcon); } } } if (m.containsField("channelName")) { string name = m.getString("channelName"); if (string.IsNullOrEmpty(name)) { continue; } ci.Name = m.getString("channelName"); } if (m.containsField("channelNumber")) { int channelNumber = m.getInt("channelNumber"); ci.Number = "" + channelNumber; if (m.containsField("channelNumberMinor")) { int channelNumberMinor = m.getInt("channelNumberMinor"); ci.Number = ci.Number + "." + channelNumberMinor; } } Boolean serviceFound = false; if (m.containsField("services")) { IList tunerInfoList = m.getList("services"); if (tunerInfoList != null && tunerInfoList.Count > 0) { HTSMessage firstServiceInList = (HTSMessage)tunerInfoList[0]; if (firstServiceInList.containsField("type")) { string type = firstServiceInList.getString("type").ToLower(); switch (type) { case "radio": ci.ChannelType = ChannelType.Radio; serviceFound = true; break; case "sdtv": case "hdtv": case "uhdtv": ci.ChannelType = ChannelType.TV; serviceFound = true; break; case "other": switch (_channelType4Other.ToLower()) { case "tv": _logger.LogInformation("[TVHclient] ChannelDataHelper: map service tag 'Other' to 'TV'."); ci.ChannelType = ChannelType.TV; serviceFound = true; break; case "radio": _logger.LogInformation("[TVHclient] ChannelDataHelper: map service tag 'Other' to 'Radio'."); ci.ChannelType = ChannelType.Radio; serviceFound = true; break; default: _logger.LogInformation("[TVHclient] ChannelDataHelper: don't map service tag 'Other' - will be ignored."); break; } break; default: _logger.LogInformation("[TVHclient] ChannelDataHelper: unkown service tag '{tag}' - will be ignored.", type); break; } } } } if (!serviceFound) { _logger.LogInformation("[TVHclient] ChannelDataHelper: unable to detect service-type (tvheadend tag!!!) from service list: {m}", m.ToString()); continue; } _logger.LogInformation("[TVHclient] ChannelDataHelper: Adding channel: {m}", m.ToString()); result.Add(ci); } catch (Exception ex) { _logger.LogError(ex, "[TVHclient] ChannelDataHelper.BuildChannelInfos caught exception. HTSmessage: {m}", m); } } return result; } })); }
public List <ChannelInfo> BuildChannelInfos(string baseHttpUrlWithAuth) { var result = new List <ChannelInfo>(); var allChannels = _data.ToArray(); foreach (KeyValuePair <int, HTSMessage> entry in allChannels) { HTSMessage m = entry.Value; try { var ci = new ChannelInfo(); ci.Id = entry.Key.ToString(CultureInfo.InvariantCulture); if (m.containsField("channelIcon")) { string channelIcon = m.getString("channelIcon"); Uri uriResult; bool uriCheckResult = Uri.TryCreate(channelIcon, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (uriCheckResult) { ci.ImageUrl = channelIcon; } else { ci.ImageUrl = baseHttpUrlWithAuth.TrimEnd('/') + "/" + channelIcon; } } if (m.containsField("channelName")) { string name = m.getString("channelName"); if (string.IsNullOrEmpty(name)) { continue; } ci.Name = m.getString("channelName"); } if (m.containsField("channelNumber")) { int channelNumber = m.getInt("channelNumber"); ci.Number = "" + channelNumber; if (m.containsField("channelNumberMinor")) { int channelNumberMinor = m.getInt("channelNumberMinor"); ci.Number = ci.Number + "." + channelNumberMinor; } } Boolean serviceFound = false; if (m.containsField("services")) { IList tunerInfoList = m.getList("services"); if (tunerInfoList != null && tunerInfoList.Count > 0) { HTSMessage firstServiceInList = (HTSMessage)tunerInfoList[0]; if (firstServiceInList.containsField("type")) { string type = firstServiceInList.getString("type").ToLower(); switch (type) { case "radio": ci.ChannelType = ChannelType.Radio; serviceFound = true; break; case "sdtv": case "hdtv": case "uhdtv": case "fhdtv": ci.ChannelType = ChannelType.TV; serviceFound = true; break; default: _logger.Info("[TVHclient] ChannelDataHelper: unkown service tag '" + type + "' - will be ignored."); break; } } } } if (!serviceFound) { _logger.Info("[TVHclient] ChannelDataHelper: unable to detect service-type (tvheadend tag!!!) from service list:" + m.ToString()); continue; } _logger.Info("[TVHclient] ChannelDataHelper: Adding channel \n" + m.ToString()); result.Add(ci); } catch (Exception ex) { _logger.Error("[TVHclient] ChannelDataHelper.BuildChannelInfos caught exception: " + ex.Message + "\nHTSmessage=" + m); } } return(result); }
public Task <IEnumerable <ChannelInfo> > buildChannelInfos(CancellationToken cancellationToken) { return(Task.Factory.StartNew <IEnumerable <ChannelInfo> >(() => { lock (_data) { List <ChannelInfo> result = new List <ChannelInfo>(); foreach (KeyValuePair <int, HTSMessage> entry in _data) { if (cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos, call canceled - returning part list."); return result; } HTSMessage m = entry.Value; ChannelInfo ci = new ChannelInfo(); ci.Id = "" + entry.Key; ci.ImagePath = ""; if (m.containsField("channelIcon")) { string channelIcon = m.getString("channelIcon"); Uri uriResult; bool uriCheckResult = Uri.TryCreate(channelIcon, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (uriCheckResult) { ci.ImageUrl = channelIcon; } else { _logger.Info("[TVHclient] ChannelDataHelper.buildChannelInfos: channelIcon '" + channelIcon + "' is not a valid HTTP URL!"); } } if (m.containsField("channelName")) { string name = m.getString("channelName"); if (string.IsNullOrEmpty(name)) { continue; } ci.Name = m.getString("channelName"); } if (m.containsField("channelNumber")) { int chNo = m.getInt("channelNumber"); ci.Number = "" + chNo; } if (m.containsField("services")) { IList tunerInfoList = m.getList("services"); HTSMessage firstServiceInList = (HTSMessage)tunerInfoList[0]; if (firstServiceInList.containsField("type")) { string type = firstServiceInList.getString("type"); switch (type) { case "Radio": ci.ChannelType = ChannelType.Radio; //continue; break; case "SDTV": case "HDTV": ci.ChannelType = ChannelType.TV; break; default: _logger.Error("[TVHclient] ChannelDataHelper: unkown service type '" + type + "'."); break; } } } else { _logger.Error("[TVHclient] ChannelDataHelper: unable to detect service-type from service list:" + m.ToString()); continue; } result.Add(ci); } return result; } })); }