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 <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 <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;
                }
            }));
        }
Beispiel #4
0
        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;
                }
            }));
        }