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
        /// <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.º 3
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));
            }
        }