Ejemplo n.º 1
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.Info(string.Format("[MythTV] Start UpdateTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            EnsureSetup();

            using (var stream = await _httpClient.Get(GetOptions(cancellationToken, "/Dvr/GetRecordSchedule?RecordId={0}", info.Id)).ConfigureAwait(false))
            {
                RecRule orgRule = DvrResponse.GetRecRule(stream, _jsonSerializer, _logger);
                if (orgRule != null)
                {
                    orgRule.Title    = info.Name;
                    orgRule.ChanId   = info.ChannelId;
                    orgRule.CallSign = await GetCallsign(info.ChannelId, cancellationToken);

                    orgRule.EndTime     = info.EndDate;
                    orgRule.StartTime   = info.StartDate;
                    orgRule.StartOffset = info.PrePaddingSeconds / 60;
                    orgRule.EndOffset   = info.PostPaddingSeconds / 60;

                    var options = PostOptions(cancellationToken, ConvertJsonRecRuleToPost(_jsonSerializer.SerializeToString(orgRule)), "/Dvr/UpdateRecordSchedule");

                    using (var response = await _httpClient.Post(options).ConfigureAwait(false)) { }
                }
            }
        }
Ejemplo n.º 2
0
        public string GetNewDoNotRecordTimerJson(Stream stream, IJsonSerializer json, ILogger logger)
        {
            RecRule rule = GetOneRecRule(stream, json, logger);

            rule.Type = "Do not Record";

            var output = json.SerializeToString(rule);

            logger.Info($"[MythTV RuleResponse: generated new timer json:\n{output}");

            return(output);
        }
Ejemplo n.º 3
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("[MythTV] Start CreateSeriesTimer Async for ChannelId: {0} & Name: {1}", info.ChannelId, info.Name));
            EnsureSetup();

            using (var stream = await _httpClient.Get(GetOptions(cancellationToken, "/Dvr/GetRecordSchedule?Template=Default")).ConfigureAwait(false))
            {
                RecRule orgRule = DvrResponse.GetRecRule(stream, _jsonSerializer, _logger);
                if (orgRule != null)
                {
                    orgRule.Title    = info.Name;
                    orgRule.ChanId   = info.ChannelId;
                    orgRule.CallSign = await GetCallsign(info.ChannelId, cancellationToken);

                    orgRule.EndTime     = info.EndDate;
                    orgRule.StartTime   = info.StartDate;
                    orgRule.StartOffset = info.PrePaddingSeconds / 60;
                    orgRule.EndOffset   = info.PostPaddingSeconds / 60;
                    orgRule.Type        = "Record All";
                    //orgRule.FindDay
                    if (info.RecordAnyChannel)
                    {
                        orgRule.Filter |= RecFilter.ThisChannel;
                    }
                    else
                    {
                        orgRule.Filter &= RecFilter.ThisChannel;
                    }
                    if (info.RecordAnyTime)
                    {
                        orgRule.Filter &= RecFilter.ThisDayTime;
                    }
                    else
                    {
                        orgRule.Filter |= RecFilter.ThisDayTime;
                    }
                    if (info.RecordNewOnly)
                    {
                        orgRule.Filter |= RecFilter.NewEpisode;
                    }
                    else
                    {
                        orgRule.Filter &= RecFilter.NewEpisode;
                    }

                    var options = PostOptions(cancellationToken, ConvertJsonRecRuleToPost(_jsonSerializer.SerializeToString(orgRule)), "/Dvr/AddRecordSchedule");

                    using (var response = await _httpClient.Post(options).ConfigureAwait(false)) { }
                }
            }
        }
Ejemplo n.º 4
0
        public string GetNewSeriesTimerJson(SeriesTimerInfo info, Stream stream, IJsonSerializer json, ILogger logger)
        {
            RecRule orgRule = GetOneRecRule(stream, json, logger);

            if (orgRule != null)
            {
                orgRule.Type = "Record All";

                if (info.RecordAnyChannel)
                {
                    orgRule.Filter &= ~RecFilter.ThisChannel;
                }
                else
                {
                    orgRule.Filter |= RecFilter.ThisChannel;
                }
                if (info.RecordAnyTime)
                {
                    orgRule.Filter &= ~RecFilter.ThisDayTime;
                }
                else
                {
                    orgRule.Filter |= RecFilter.ThisDayTime;
                }
                if (info.RecordNewOnly)
                {
                    orgRule.Filter |= RecFilter.NewEpisode;
                }
                else
                {
                    orgRule.Filter &= ~RecFilter.NewEpisode;
                }

                orgRule.MaxEpisodes = info.KeepUpTo;
                orgRule.MaxNewest   = info.KeepUpTo > 0;
                orgRule.StartOffset = info.PrePaddingSeconds / 60;
                orgRule.EndOffset   = info.PostPaddingSeconds / 60;
            }

            var output = json.SerializeToString(orgRule);

            logger.Info($"[MythTV RuleResponse: generated new timer json:\n{output}");

            return(output);
        }
Ejemplo n.º 5
0
        public string GetNewTimerJson(TimerInfo info, Stream stream, IJsonSerializer json, ILogger logger)
        {
            RecRule rule = GetOneRecRule(stream, json, logger);

            // check if there is an existing rule that is going to cause grief
            if (rule.Type != "Not Recording")
            {
                throw new ExistingTimerException(rule.Id);
            }

            rule.Type        = "Single Record";
            rule.StartOffset = info.PrePaddingSeconds / 60;
            rule.EndOffset   = info.PostPaddingSeconds / 60;

            var output = json.SerializeToString(rule);

            logger.Info($"[MythTV RuleResponse: generated new timer json:\n{output}");

            return(output);
        }
Ejemplo n.º 6
0
        private SeriesTimerInfo RecRuleToSeriesTimerInfo(RecRule item)
        {
            var info = new SeriesTimerInfo()
            {
                Name               = item.Title,
                ChannelId          = item.ChanId,
                EndDate            = item.EndTime,
                StartDate          = item.StartTime,
                Id                 = item.Id,
                PrePaddingSeconds  = item.StartOffset * 60,
                PostPaddingSeconds = item.EndOffset * 60,
                RecordAnyChannel   = !((item.Filter & RecFilter.ThisChannel) == RecFilter.ThisChannel),
                RecordAnyTime      = !((item.Filter & RecFilter.ThisDayTime) == RecFilter.ThisDayTime),
                RecordNewOnly      = ((item.Filter & RecFilter.NewEpisode) == RecFilter.NewEpisode),
                ProgramId          = item.ProgramId,
                SeriesId           = item.SeriesId,
                KeepUpTo           = item.MaxEpisodes
            };

            return(info);
        }
Ejemplo n.º 7
0
        public async Task <MediaSourceInfo> GetChannelStream(string channelOid, string mediaSourceId, CancellationToken cancellationToken)
        {
            _logger.Info("[MythTV] Start ChannelStream");

            throw new NotImplementedException();

            using (var stream = await _httpClient.Get(GetOptions(cancellationToken, "/Dvr/GetRecordSchedule?Template=Default")).ConfigureAwait(false))
            {
                RecRule orgRule = DvrResponse.GetRecRule(stream, _jsonSerializer, _logger);
                if (orgRule != null)
                {
                    DateTime startTime = DateTime.Now.ToUniversalTime();
                    orgRule.Title    = string.Format("Emby LiveTV: {0} ({1}) - {1}", await GetCallsign(channelOid, cancellationToken), channelOid, startTime);
                    orgRule.ChanId   = channelOid;
                    orgRule.CallSign = await GetCallsign(channelOid, cancellationToken);

                    orgRule.EndTime     = startTime.AddHours(5);
                    orgRule.StartTime   = startTime;
                    orgRule.StartOffset = 0;
                    orgRule.EndOffset   = 0;
                    orgRule.Type        = "Single Record";

                    var postContent = ConvertJsonRecRuleToPost(_jsonSerializer.SerializeToString(orgRule));

                    var options = PostOptions(cancellationToken, postContent, "/Dvr/AddRecordSchedule");

                    using (var response = await _httpClient.Post(options).ConfigureAwait(false))
                    {
                        RecordId recId = DvrResponse.ParseRecordId(response.Content, _jsonSerializer);
                        for (int i = 0; i < Plugin.Instance.Configuration.LiveTvWaits; i++)
                        {
                            await Task.Delay(200).ConfigureAwait(false);

                            try
                            {
                                using (var rpstream = await _httpClient.Get(GetOptions(cancellationToken, "/Dvr/GetRecorded?ChanId={0}&StartTime={1}", channelOid, FormateMythDate(startTime))).ConfigureAwait(false))
                                {
                                    var recProg = DvrResponse.ParseRecorded(rpstream, _jsonSerializer, _logger);//Host.DvrService.GetRecorded(int.Parse(channelOid), startTime);
                                    if (recProg != null && File.Exists(Path.Combine(Plugin.Instance.Configuration.UncPath, recProg.FileName)))
                                    {
                                        return(new MediaSourceInfo
                                        {
                                            Id = [email protected](CultureInfo.InvariantCulture),
                                            Path = Path.Combine(Plugin.Instance.Configuration.UncPath, recProg.FileName),
                                            Protocol = MediaProtocol.File,
                                            MediaStreams = new List <MediaStream>
                                            {
                                                new MediaStream
                                                {
                                                    Type = MediaStreamType.Video,
                                                    // Set the index to -1 because we don't know the exact index of the video stream within the container
                                                    Index = -1
                                                },
                                                new MediaStream
                                                {
                                                    Type = MediaStreamType.Audio,
                                                    // Set the index to -1 because we don't know the exact index of the audio stream within the container
                                                    Index = -1
                                                }
                                            }
                                        });

                                        break;
                                    }
                                }
                            }
                            catch
                            {
                                _logger.Info("GetChannelStream wait {0} for {1}", i, channelOid);
                            }
                        }
                    }
                }

                throw new ResourceNotFoundException(string.Format("Could not stream channel {0}", channelOid));
            }
        }