Example #1
0
        public async Task <DateTimeOffset> GetLastUpdate(CancellationToken cancellationToken)
        {
            _logger.LogDebug("[NextPVR] GetLastUpdateTime");
            DateTimeOffset retTime = DateTimeOffset.FromUnixTimeSeconds(0);
            var            baseUrl = Plugin.Instance.Configuration.WebServiceUrl;

            try
            {
                await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
                                         .GetStreamAsync(string.Format("{0}/service?method=recording.lastupdated&ignore_resume=true&sid={1}", baseUrl, Sid));

                retTime = new LastUpdateResponse().GetUpdateTime(stream, _jsonSerializer, _logger);
                if (retTime == DateTimeOffset.FromUnixTimeSeconds(0))
                {
                    LastUpdatedSidDateTime = DateTimeOffset.MinValue;
                    await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);
                }
                else if (LastUpdatedSidDateTime != DateTimeOffset.MinValue)
                {
                    LastUpdatedSidDateTime = DateTime.UtcNow;
                }
            }
            catch (HttpRequestException)
            {
                LastUpdatedSidDateTime = DateTimeOffset.MinValue;
            }

            UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetLastUpdateTime {0}", retTime.ToUnixTimeSeconds()));
            return(retTime);
        }
Example #2
0
        /// <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)
        {
            _logger.LogInformation(string.Format("[NextPVR] Start CreateTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);

            var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;

            UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] TimerSettings CreateTimer: {0} for ChannelId: {1} & Name: {2}", info.ProgramId, info.ChannelId, info.Name));
            await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
                                     .GetStreamAsync(string.Format("{0}/service?method=recording.save&sid={1}&event_id={2}&pre_padding={3}&post_padding={4}", baseUrl, Sid,
                                                                   int.Parse(info.ProgramId, _usCulture),
                                                                   info.PrePaddingSeconds / 60,
                                                                   info.PostPaddingSeconds / 60,
                                                                   info.Id), cancellationToken);

            bool?error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);

            if (error == null || error == true)
            {
                _logger.LogError(string.Format("[NextPVR] Failed to create the timer with programId: {0}", info.ProgramId));
                throw new Exception(string.Format("Failed to create the timer with programId: {0}", info.ProgramId));
            }

            _logger.LogError("[NextPVR] CreateTimer async for programId: {0}", info.ProgramId);
        }
        public DateTimeOffset GetUpdateTime(Stream stream, IJsonSerializer json, ILogger <LiveTvService> logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] LastUpdate Response: {0}", json.SerializeToString(root)));
            return(DateTimeOffset.FromUnixTimeSeconds(root.last_update));
        }
Example #4
0
        /// <summary>
        /// Create a recurrent recording
        /// </summary>
        /// <param name="info">The recurrend program info</param>
        /// <param name="cancellationToken">The CancelationToken</param>
        /// <returns></returns>
        public async Task CreateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken)
        {
            _logger.Info(string.Format("[NextPvr] Start CreateSeriesTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);

            var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;

            var options = new HttpRequestOptions
            {
                CancellationToken = cancellationToken,
                Url = string.Format("{0}/public/ScheduleService/Record?sid={1}", baseUrl, Sid)
            };

            var timerSettings = await GetDefaultScheduleSettings(cancellationToken).ConfigureAwait(false);

            timerSettings.allChannels       = info.RecordAnyChannel;
            timerSettings.onlyNew           = info.RecordNewOnly;
            timerSettings.recurringName     = info.Name;
            timerSettings.recordAnyTimeslot = info.RecordAnyTime;

            timerSettings.recordAnyDay = info.Days.Count == 7;
            timerSettings.daySunday    = info.Days.Contains(DayOfWeek.Sunday);
            timerSettings.dayMonday    = info.Days.Contains(DayOfWeek.Monday);
            timerSettings.dayTuesday   = info.Days.Contains(DayOfWeek.Tuesday);
            timerSettings.dayWednesday = info.Days.Contains(DayOfWeek.Wednesday);
            timerSettings.dayThursday  = info.Days.Contains(DayOfWeek.Thursday);
            timerSettings.dayFriday    = info.Days.Contains(DayOfWeek.Friday);
            timerSettings.daySaturday  = info.Days.Contains(DayOfWeek.Saturday);

            if (!info.RecordAnyChannel)
            {
                timerSettings.ChannelOID = int.Parse(info.ChannelId, _usCulture);
            }

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                timerSettings.epgeventOID = int.Parse(info.ProgramId, _usCulture);
            }

            timerSettings.post_padding_min = info.PostPaddingSeconds / 60;
            timerSettings.pre_padding_min  = info.PrePaddingSeconds / 60;

            var postContent = _jsonSerializer.SerializeToString(timerSettings);

            UtilsHelper.DebugInformation(_logger, string.Format("[NextPvr] TimerSettings CreateSeriesTimer: {0} for ChannelId: {1} & Name: {2}", postContent, info.ChannelId, info.Name));

            options.RequestContent     = postContent;
            options.RequestContentType = "application/json";

            try
            {
                await _httpClient.Post(options).ConfigureAwait((false));
            }
            catch (HttpException ex)
            {
                _logger.Error(string.Format("[NextPvr] CreateSeries async with exception: {0} ", ex.Message));
                throw new LiveTvConflictException();
            }
        }
Example #5
0
        public bool GetDefaultSettings(Stream stream, IJsonSerializer json, ILogger <LiveTvService> logger)
        {
            ScheduleSettings root = GetScheduleSettings(stream, json);

            UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", json.SerializeToString(root)));
            Plugin.Instance.Configuration.PostPaddingSeconds = int.Parse(root.postPadding) * 60;
            Plugin.Instance.Configuration.PrePaddingSeconds  = int.Parse(root.prePadding) * 60;
            Plugin.Instance.Configuration.ShowRepeat         = root.showNewInGuide;
            return(true);
        }
    public async Task <IEnumerable <ProgramInfo> > GetPrograms(Stream stream, string channelId, ILogger <LiveTvService> logger)
    {
        var root = await JsonSerializer.DeserializeAsync <RootObject>(stream, _jsonOptions).ConfigureAwait(false);

        UtilsHelper.DebugInformation(logger, $"[NextPVR] GetPrograms Response: {JsonSerializer.Serialize(root, _jsonOptions)}");
        _channelId = channelId;
        return(root.Listings
               .Select(i => i)
               .Select(GetProgram));
    }
Example #7
0
    public async Task <bool> GetDefaultSettings(Stream stream, ILogger <LiveTvService> logger)
    {
        var root = await JsonSerializer.DeserializeAsync <ScheduleSettings>(stream, _jsonOptions).ConfigureAwait(false);

        UtilsHelper.DebugInformation(logger, $"[NextPVR] GetDefaultTimerInfo Response: {JsonSerializer.Serialize(root, _jsonOptions)}");
        Plugin.Instance.Configuration.PostPaddingSeconds = int.Parse(root.PostPadding, CultureInfo.InvariantCulture) * 60;
        Plugin.Instance.Configuration.PrePaddingSeconds  = int.Parse(root.PrePadding, CultureInfo.InvariantCulture) * 60;
        Plugin.Instance.Configuration.ShowRepeat         = root.ShowNewInGuide;
        return(true);
    }
        public bool?RecordingError(Stream stream, IJsonSerializer json, ILogger <LiveTvService> logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root.stat != "ok")
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] RecordingError Response: {0}", json.SerializeToString(root)));
                return(true);
            }
            return(false);
        }
        public bool?RecordingError(Stream stream, IJsonSerializer json, ILogger logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root.epgEventJSONObject != null && root.epgEventJSONObject.rtn != null)
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPvr] RecordingError Response: {0}", json.SerializeToString(root)));
                return(root.epgEventJSONObject.rtn.Error);
            }
            return(null);
        }
Example #10
0
        public IEnumerable <ProgramInfo> GetPrograms(Stream stream, IJsonSerializer json, string channelId, ILogger logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            UtilsHelper.DebugInformation(logger, string.Format("[NextPvr] GetPrograms Response: {0}", json.SerializeToString(root)));

            var listings = root.Guide.Listings;

            return(listings.Where(i => string.Equals(i.Channel.channelOID.ToString(_usCulture), channelId, StringComparison.OrdinalIgnoreCase))
                   .SelectMany(i => i.EPGEvents.Select(e => GetProgram(i.Channel, e.epgEventJSONObject.epgEvent))));
        }
Example #11
0
        public static EncoderList ParseEncoderList(Stream stream, IJsonSerializer json, ILogger logger)
        {
            using (var reader = new StreamReader(stream, new UTF8Encoding()))
            {
                string resptext = reader.ReadToEnd();
                UtilsHelper.DebugInformation(logger, string.Format("[MythTV] ParseEncoderList Response: {0}", resptext));

                //resptext = Regex.Replace(resptext, "{\"Version\": {\"Version\"", "{\"Version\": {\"Ver\"");
                var root = json.DeserializeFromString <RootEncoderObject>(resptext);
                return(root.EncoderList);
            }
        }
Example #12
0
    public async Task <bool?> RecordingError(Stream stream, ILogger <LiveTvService> logger)
    {
        var root = await JsonSerializer.DeserializeAsync <RootObject>(stream, _jsonOptions).ConfigureAwait(false);

        if (root.Stat != "ok")
        {
            UtilsHelper.DebugInformation(logger, $"[NextPVR] RecordingError Response: {JsonSerializer.Serialize(root, _jsonOptions)}");
            return(true);
        }

        return(false);
    }
        public ClientKeys GetClientKeys(Stream stream, IJsonSerializer json, ILogger logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root.clientKeys != null && root.clientKeys.sid != null && root.clientKeys.salt != null)
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPvr] ClientKeys: {0}", json.SerializeToString(root)));
                return(root.clientKeys);
            }
            logger.LogError("[NextPvr] Failed to load the ClientKeys from NextPvr.");
            throw new Exception("Failed to load the ClientKeys from NextPvr.");
        }
        public bool LoggedIn(Stream stream, IJsonSerializer json, ILogger <LiveTvService> logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root.stat != "")
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] Connection validation: {0}", json.SerializeToString(root)));
                return(root.stat == "ok");
            }
            logger.LogError("[NextPVR] Failed to validate your connection with NextPVR.");
            throw new Exception("Failed to validate your connection with NextPVR.");
        }
Example #15
0
        public bool LoggedIn(Stream stream, IJsonSerializer json, ILogger logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root.SIDValidation != null)
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPvr] Connection validation: {0}", json.SerializeToString(root)));
                return(root.SIDValidation.validated);
            }
            logger.LogError("[NextPvr] Failed to validate your connection with NextPvr.");
            throw new Exception("Failed to validate your connection with NextPvr.");
        }
        public VLCObj GetVLCResponse(Stream stream, IJsonSerializer json, ILogger logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root.JSONVlcObject.VLC_Obj != null && root.JSONVlcObject.VLC_Obj.isVlcAvailable == true)
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPvr] VLC Response: {0}", json.SerializeToString(root)));
                return(root.JSONVlcObject.VLC_Obj);
            }
            logger.Error("[NextPvr] Failed to load the VLC from NEWA");
            throw new ApplicationException("Failed to load the VLC from NEWA.");
        }
Example #17
0
        /// <summary>
        /// Get the recurrent recordings
        /// </summary>
        /// <param name="cancellationToken">The CancellationToken</param>
        /// <returns></returns>
        public async Task <IEnumerable <SeriesTimerInfo> > GetSeriesTimersAsync(CancellationToken cancellationToken)
        {
            _logger.Info(string.Format("[ArgusTV] Start GetSeriesTimer Async"));
            await EnsureConnectionAsync(cancellationToken);

            List <SeriesTimerInfo> seriesTimerInfos = new List <SeriesTimerInfo>();

            try
            {
                List <UpcomingRecording> upcomingRecordings = Proxies.ControlService.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings).Result.GroupBy(u => u.Program.ScheduleId).Select(grp => grp.First()).ToList();

                foreach (UpcomingRecording upcomingRecording in upcomingRecordings)
                {
                    if (upcomingRecording != null && upcomingRecording.Program != null && upcomingRecording.Program.IsPartOfSeries)
                    {
                        var          schedule       = Proxies.SchedulerService.GetScheduleById(upcomingRecording.Program.ScheduleId).Result;
                        ScheduleRule daysOfWeekRule = schedule.Rules.SingleOrDefault(r => r.Type == ScheduleRuleType.DaysOfWeek);

                        var days = new List <DayOfWeek>();

                        if (daysOfWeekRule != null)
                        {
                            days = SchedulerHelper.GetDaysOfWeek((ScheduleDaysOfWeek)daysOfWeekRule.Arguments[0]);
                        }

                        seriesTimerInfos.Add(new SeriesTimerInfo
                        {
                            Id                 = upcomingRecording.Program.ScheduleId.ToString(),
                            ChannelId          = upcomingRecording.Program.Channel.ChannelId.ToString(),
                            Name               = upcomingRecording.Title,
                            Overview           = Proxies.GuideService.GetProgramById(Guid.Parse(upcomingRecording.Program.GuideProgramId.ToString())).Result.Description,
                            StartDate          = upcomingRecording.ActualStartTimeUtc,
                            ProgramId          = upcomingRecording.Program.GuideProgramId.ToString(),
                            EndDate            = upcomingRecording.ActualStopTimeUtc,
                            PostPaddingSeconds = upcomingRecording.Program.PostRecordSeconds,
                            PrePaddingSeconds  = upcomingRecording.Program.PreRecordSeconds,
                            Days               = days
                        });
                    }
                }

                UtilsHelper.DebugInformation(_logger, string.Format("[ArgusTV] GetSeriesTimers with the following TimerInfo: {0}", _jsonSerializer.SerializeToString(seriesTimerInfos)));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("[ArgusTV] GetSeriesTimers async failed", ex);
                throw new LiveTvConflictException();
            }


            return(seriesTimerInfos);
        }
Example #18
0
    public async Task <bool> LoggedIn(Stream stream, ILogger <LiveTvService> logger)
    {
        var root = await JsonSerializer.DeserializeAsync <RootObject>(stream, _jsonOptions).ConfigureAwait(false);

        if (!string.IsNullOrEmpty(root.Stat))
        {
            UtilsHelper.DebugInformation(logger, $"[NextPVR] Connection validation: {JsonSerializer.Serialize(root, _jsonOptions)}");
            return(root.Stat == "ok");
        }

        logger.LogError("[NextPVR] Failed to validate your connection with NextPVR");
        throw new JsonException("Failed to validate your connection with NextPVR.");
    }
        public IEnumerable <SeriesTimerInfo> GetSeriesTimers(Stream stream, IJsonSerializer json)
        {
            if (stream == null)
            {
                _logger.LogError("[NextPVR] GetSeriesTimers stream == null");
                throw new ArgumentNullException("stream");
            }

            var root = json.DeserializeFromStream <RootObject>(stream);

            UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetSeriesTimers Response: {0}", json.SerializeToString(root)));
            return(root.recurrings
                   .Select(i => i)
                   .Select(GetSeriesTimerInfo));
        }
    public async Task <IEnumerable <SeriesTimerInfo> > GetSeriesTimers(Stream stream)
    {
        if (stream == null)
        {
            _logger.LogError("[NextPVR] GetSeriesTimers stream == null");
            throw new ArgumentNullException(nameof(stream));
        }

        var root = await JsonSerializer.DeserializeAsync <RootObject>(stream, _jsonOptions).ConfigureAwait(false);

        UtilsHelper.DebugInformation(_logger, $"[NextPVR] GetSeriesTimers Response: {JsonSerializer.Serialize(root, _jsonOptions)}");
        return(root.Recurrings
               .Select(i => i)
               .Select(GetSeriesTimerInfo));
    }
        public SeriesTimerInfo GetDefaultTimerInfo(Stream stream, IJsonSerializer json, ILogger logger)
        {
            var root = GetScheduleSettings(stream, json);

            UtilsHelper.DebugInformation(logger, string.Format("[NextPvr] GetDefaultTimerInfo Response: {0}", json.SerializeToString(root)));

            return(new SeriesTimerInfo
            {
                PostPaddingSeconds = root.post_padding_min * 60,
                PrePaddingSeconds = root.pre_padding_min * 60,
                RecordAnyChannel = root.allChannels,
                RecordAnyTime = root.recordAnyTimeslot,
                RecordNewOnly = root.onlyNew
            });
        }
Example #22
0
        public IEnumerable <ProgramInfo> GetPrograms(Stream stream, IJsonSerializer json, string channelId, ILogger logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            UtilsHelper.DebugInformation(logger, string.Format("[VDR] GetPrograms Response: {0}", json.SerializeToString(root)));
//          logger.Info(string.Format("[VDR] Display Root Object: {0}", json.SerializeToString(root)));
            if (root != null && root.events != null)
            {
                return(root.events.Select(epg => new ProgramInfo()
                {
                    ChannelId = channelId,
                    Id = epg.channel + epg.id.ToString(),
                    Overview = epg.description,
                    StartDate = ApiHelper.DateTimeFromUnixTimestampSeconds(epg.start_time).ToUniversalTime(),
                    EndDate = ApiHelper.DateTimeFromUnixTimestampSeconds(epg.start_time).ToUniversalTime().AddSeconds(epg.duration),
                    Genres = new List <string>(),
                    OriginalAirDate = null,
                    //OriginalAirDate = parse infom from Description
                    Name = epg.title,
                    OfficialRating = null,
                    //OfficialRating = parse infom from Description
                    //OfficialRating = "G",
                    //CommunityRating = null, // not provided
                    //CommunityRating = 10,
                    EpisodeTitle = epg.short_text,
                    Audio = ParseAudio(epg.description),
                    IsHD = epg.description.ToLower().Contains(" hd ") || epg.channel_name.ToLower().Contains("hd"),
                    IsRepeat = false,
                    IsSeries = epg.description.Contains("series", StringComparison.OrdinalIgnoreCase),
                    HasImage = (epg.images > 0),
                    ImageUrl = (epg.images > 0) ?  (_baseUrl + "/events/image/1/" + epg.id.ToString(_usCulture)) : null,
                    IsNews = epg.description.Contains("news.", StringComparison.OrdinalIgnoreCase) ||
                             epg.contents.FindAll(str => str.ToLower().Contains("news")).Count > 0,
                    IsMovie = epg.description.Contains("movie.", StringComparison.OrdinalIgnoreCase) ||
                              epg.contents.FindAll(str => str.ToLower().Contains("movie")).Count > 0,
                    IsKids = epg.description.Contains("children.", StringComparison.OrdinalIgnoreCase) ||
                             epg.contents.FindAll(str => str.ToLower().Contains("kid")).Count > 0,

                    IsSports = epg.description.Contains("sports", StringComparison.OrdinalIgnoreCase) ||
                               epg.description.Contains("Sports non-event", StringComparison.OrdinalIgnoreCase) ||
                               epg.description.Contains("Sports event", StringComparison.OrdinalIgnoreCase) ||
                               epg.description.Contains("Sports talk", StringComparison.OrdinalIgnoreCase) ||
                               epg.description.Contains("Sports news", StringComparison.OrdinalIgnoreCase) ||
                               epg.contents.FindAll(str => str.ToLower().Contains("sport")).Count > 0
                }));
            }
            return(new List <ProgramInfo>());
        }
    /// <summary>
    /// Update the series Timer.
    /// </summary>
    /// <param name="info">The series program info.</param>
    /// <param name="url">The url.</param>
    /// <param name="cancellationToken">The CancellationToken.</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task CreateUpdateSeriesTimerAsync(SeriesTimerInfo info, string url, CancellationToken cancellationToken)
    {
        UtilsHelper.DebugInformation(_logger, $"[NextPVR] TimerSettings CreateSeriesTimerAsync: {info.ProgramId} for ChannelId: {info.ChannelId} & Name: {info.Name}");
        await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
                                 .GetStreamAsync(url, cancellationToken);

        bool?error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);

        if (error == null || error == true)
        {
            _logger.LogError("[NextPVR] Failed to create or update the timer with Recurring ID: {0}", info.Id);
            throw new JsonException($"Failed to create or update the timer with Recurring ID: {info.Id}");
        }

        _logger.LogInformation("[NextPVR] CreateUpdateSeriesTimer async for Program ID: {0} Recurring ID {1}", info.ProgramId, info.Id);
    }
Example #24
0
        /// <summary>
        /// Update the series Timer
        /// </summary>
        /// <param name="info">The series program info</param>
        /// <param name="cancellationToken">The CancellationToken</param>
        /// <returns></returns>
        public async Task CreateUpdateSeriesTimerAsync(SeriesTimerInfo info, string url, CancellationToken cancellationToken)
        {
            UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] TimerSettings CreateSeriesTimerAsync: {0} for ChannelId: {1} & Name: {2}", info.ProgramId, info.ChannelId, info.Name));
            await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
                                     .GetStreamAsync(url, cancellationToken);

            bool?error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);

            if (error == null || error == true)
            {
                _logger.LogError("[NextPVR] Failed to create or update the timer with Recurring ID: {0}", info.Id);
                throw new Exception(string.Format("Failed to create or update the timer with Recurring ID: {0}", info.Id));
            }

            _logger.LogInformation("[NextPVR] CreateUpdateSeriesTimer async for Program ID: {0} Recurring ID {1}", info.ProgramId, info.Id);
            //Thread.Sleep(1000);
        }
Example #25
0
        /// <summary>
        /// Update the series Timer
        /// </summary>
        /// <param name="info">The series program info</param>
        /// <param name="cancellationToken">The CancellationToken</param>
        /// <returns></returns>
        public async Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken)
        {
            _logger.LogInformation(string.Format("[NextPvr] Start UpdateSeriesTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);

            var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;

            var options = new HttpRequestOptions
            {
                CancellationToken = cancellationToken,
                Url = string.Format("{0}/public/ScheduleService/UpdateRecurr?sid={1}", baseUrl, Sid),
                DecompressionMethod = CompressionMethod.None
            };

            var timerSettings = await GetDefaultScheduleSettings(cancellationToken).ConfigureAwait(false);

            timerSettings.recurrOID           = int.Parse(info.Id);
            timerSettings.post_padding_min    = info.PostPaddingSeconds / 60;
            timerSettings.pre_padding_min     = info.PrePaddingSeconds / 60;
            timerSettings.allChannels         = info.RecordAnyChannel;
            timerSettings.onlyNew             = info.RecordNewOnly;
            timerSettings.recurringName       = info.Name;
            timerSettings.recordAnyTimeslot   = info.RecordAnyTime;
            timerSettings.keep_all_days       = true;
            timerSettings.days_to_keep        = 0;
            timerSettings.extend_end_time_min = 0;

            var postContent = _jsonSerializer.SerializeToString(timerSettings);

            UtilsHelper.DebugInformation(_logger, string.Format("[NextPvr] TimerSettings UpdateSeriesTimer: {0} for ChannelId: {1} & Name: {2}", postContent, info.ChannelId, info.Name));

            options.RequestContent     = postContent;
            options.RequestContentType = "application/json";

            try
            {
                await _httpClient.Post(options).ConfigureAwait((false));
            }
            catch (HttpException ex)
            {
                _logger.LogError(string.Format("[NextPvr] UpdateSeries async with exception: {0}", ex.Message));
                throw new LiveTvConflictException();
            }
        }
Example #26
0
        /// <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)
        {
            //_logger.Info(string.Format("[VDR] Start CreateTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            _logger.Info("[VDR] Start CreateTimer Async for ChannelId NOT IMPLIMENTED");
            throw new NotImplementedException();

            var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;

            var options = new HttpRequestOptions
            {
                CancellationToken = cancellationToken,
                Url = string.Format("{0}/public/ScheduleService/Record?sid={1}", baseUrl, Sid)
            };

            var timerSettings = await GetDefaultScheduleSettings(cancellationToken).ConfigureAwait(false);

            timerSettings.allChannels = false;
            timerSettings.ChannelOID  = int.Parse(info.ChannelId, _usCulture);

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                timerSettings.epgeventOID = int.Parse(info.ProgramId, _usCulture);
            }

            timerSettings.post_padding_min = info.PostPaddingSeconds / 60;
            timerSettings.pre_padding_min  = info.PrePaddingSeconds / 60;

            var postContent = _jsonSerializer.SerializeToString(timerSettings);

            UtilsHelper.DebugInformation(_logger, string.Format("[VDR] TimerSettings CreateTimer: {0} for ChannelId: {1} & Name: {2}", postContent, info.ChannelId, info.Name));

            options.RequestContent     = postContent;
            options.RequestContentType = "application/json";

            try
            {
                await _httpClient.Post(options).ConfigureAwait((false));
            }
            catch (HttpException ex)
            {
                _logger.Error(string.Format("[VDR] CreateTimer async with exception: {0}", ex.Message));
                throw new LiveTvConflictException();
            }
        }
Example #27
0
        public ClientKeys GetClientKeys(Stream stream, IJsonSerializer json, ILogger <LiveTvService> logger)
        {
            try
            {
                var root = json.DeserializeFromStream <ClientKeys>(stream);

                if (root.sid != null && root.salt != null)
                {
                    UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] ClientKeys: {0}", json.SerializeToString(root)));
                    return(root);
                }
                logger.LogError("[NextPVR] Failed to validate the ClientKeys from NextPVR.");
                throw new Exception("Failed to load the ClientKeys from NextPVR.");
            }
            catch
            {
                logger.LogError("Check NextPVR Version 5");
                throw new UnauthorizedAccessException("Check NextPVR Version");
            }
        }
Example #28
0
    public async Task <ClientKeys> GetClientKeys(Stream stream, ILogger <LiveTvService> logger)
    {
        try
        {
            var root = await JsonSerializer.DeserializeAsync <ClientKeys>(stream, _jsonOptions).ConfigureAwait(false);

            if (root.Sid != null && root.Salt != null)
            {
                UtilsHelper.DebugInformation(logger, $"[NextPVR] ClientKeys: {JsonSerializer.Serialize(root, _jsonOptions)}");
                return(root);
            }

            logger.LogError("[NextPVR] Failed to validate the ClientKeys from NextPVR");
            throw new JsonException("Failed to load the ClientKeys from NextPVR.");
        }
        catch
        {
            logger.LogError("Check NextPVR Version 5");
            throw new UnauthorizedAccessException("Check NextPVR Version");
        }
    }
Example #29
0
        /// <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)
        {
            _logger.LogInformation(string.Format("[NextPvr] Start UpdateTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);

            var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;

            var options = new HttpRequestOptions
            {
                CancellationToken = cancellationToken,
                Url = string.Format("{0}/public/ScheduleService/UpdateRec?sid={1}", baseUrl, Sid),
                DecompressionMethod = CompressionMethod.None
            };

            var timerSettings = await GetDefaultScheduleSettings(cancellationToken).ConfigureAwait(false);

            timerSettings.scheduleOID      = int.Parse(info.Id);
            timerSettings.post_padding_min = info.PostPaddingSeconds / 60;
            timerSettings.pre_padding_min  = info.PrePaddingSeconds / 60;

            var postContent = _jsonSerializer.SerializeToString(timerSettings);

            UtilsHelper.DebugInformation(_logger, string.Format("[NextPvr] TimerSettings UpdateTimer: {0} for ChannelId: {1} & Name: {2}", postContent, info.ChannelId, info.Name));

            options.RequestContent     = postContent;
            options.RequestContentType = "application/json";

            try
            {
                await _httpClient.Post(options).ConfigureAwait((false));

                LastRecordingChange = DateTimeOffset.UtcNow;
            }
            catch (HttpException ex)
            {
                LastRecordingChange = DateTimeOffset.UtcNow;
                _logger.LogError(string.Format("[NextPvr] UpdateTimer Async with exception: {0}", ex.Message));
                throw new LiveTvConflictException();
            }
        }
Example #30
0
        /// <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)
        {
            _logger.Info(string.Format("[ArgusTV] Start GetRecordings Async"));
            await EnsureConnectionAsync(cancellationToken);

            List <RecordingInfo> timerInfos = new List <RecordingInfo>();

            try
            {
                var allRecordingGroups = Proxies.ControlService.GetAllRecordingGroups(ChannelType.Television, RecordingGroupMode.GroupByChannel).Result;

                var channels = (from allRecordingGroup in allRecordingGroups
                                select allRecordingGroup.ChannelId).Distinct();


                foreach (var channel in channels)
                {
                    timerInfos.AddRange(
                        Proxies.ControlService.GetFullRecordings(ChannelType.Television, null, null, null, channel)
                        .Result.Select(recording => new RecordingInfo
                    {
                        Id        = recording.RecordingId.ToString(),
                        ChannelId = recording.ChannelId.ToString(),
                        Name      = recording.Title,
                        Overview  = recording.Description,
                        StartDate = recording.ProgramStartTimeUtc,
                        EndDate   = recording.ProgramStopTimeUtc
                    }));
                }

                UtilsHelper.DebugInformation(_logger, string.Format("[ArgusTV] GetRecordings with the following RecordingInfo: {0}", _jsonSerializer.SerializeToString(timerInfos)));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("[ArgusTV] GetRecordings async failed", ex);
            }

            return(timerInfos);
        }