Ejemplo n.º 1
0
        private void UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer)
        {
            List <ProgramInfo> epgData;

            if (seriesTimer.RecordAnyChannel)
            {
                epgData = GetEpgDataForAllChannels();
            }
            else
            {
                epgData = GetEpgDataForChannel(seriesTimer.ChannelId);
            }

            var newTimers = RecordingHelper.GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll(), _logger);

            var existingTimers = _timerProvider.GetAll()
                                 .Where(i => string.Equals(i.SeriesTimerId, seriesTimer.Id, StringComparison.OrdinalIgnoreCase))
                                 .ToList();

            foreach (var timer in newTimers)
            {
                _timerProvider.AddOrUpdate(timer);
            }

            var newTimerIds = newTimers.Select(i => i.Id).ToList();

            foreach (var timer in existingTimers)
            {
                if (!newTimerIds.Contains(timer.Id, StringComparer.OrdinalIgnoreCase))
                {
                    CancelTimerInternal(timer.Id);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task RecordStream(MediaSourceInfo mediaSourceInfo, CancellationToken cancellationToken)
        {
            HttpRequestOptions options = new HttpRequestOptionsMod()
            {
                Url = mediaSourceInfo.Path
            };
            await RecordingHelper.DownloadVideo(_httpClient, options, _logger, Path.Combine(RecordingPath, mediaSourceInfo.Name), cancellationToken);

            _logger.Info("Recording was a success");
        }
Ejemplo n.º 3
0
        private void AddTimer(TimerInfo item)
        {
            var timespan = RecordingHelper.GetStartTime(item) - DateTime.UtcNow;

            var timer = new Timer(TimerCallback, item.Id, timespan, TimeSpan.Zero);

            if (!_timers.TryAdd(item.Id, timer))
            {
                timer.Dispose();
            }
        }
Ejemplo n.º 4
0
        public async Task RecordStream(SingleTimer timer)
        {
            var mediaStreamInfo = await GetChannelStream(timer.ChannelId, "none", CancellationToken.None);

            HttpRequestOptions options = new HttpRequestOptionsMod()
            {
                Url = mediaStreamInfo.Path + "?duration=" + timer.Duration()
            };
            await RecordingHelper.DownloadVideo(_httpClient, options, _logger, Path.Combine(RecordingPath, timer.GetRecordingName()), timer.Cts.Token);

            _logger.Info("Recording was a success");
        }
Ejemplo n.º 5
0
        public override void Update(TimerInfo item)
        {
            base.Update(item);

            Timer timer;

            if (_timers.TryGetValue(item.Id, out timer))
            {
                var timespan = RecordingHelper.GetStartTime(item) - DateTime.UtcNow;
                timer.Change(timespan, TimeSpan.Zero);
            }
            else
            {
                AddTimer(item);
            }
        }
Ejemplo n.º 6
0
 public static void GetRecordingName_Success(string expected, TimerInfo timerInfo)
 {
     Assert.Equal(expected, RecordingHelper.GetRecordingName(timerInfo));
 }
Ejemplo n.º 7
0
        }                                      //根据语音音量变化判断是否在录音中

        /// <summary>
        /// 加载会议
        /// </summary>
        public void Loading(string code = null, MeetingDTO meeting = null)
        {
            //meeting
            if (!meeting.IsNull())
            {
                Meeting = meeting;
            }
            else if (!code.IsEmpty())
            {
                var result = PlugCoreHelper.ApiUrl.Meeting.MeetingGetCode.GetResult <MeetingDTO, MeetingEditInput>(new MeetingEditInput()
                {
                    Num = code
                });
                if (result.Code == EnumCode.成功)
                {
                    Meeting = meeting;
                }
            }
            else if (Meeting.IsNull())
            {
                //else if(Meeting.IsNull()) 全局会议保持
                var result = PlugCoreHelper.ApiUrl.Meeting.MeetingInsert.GetResult <MeetingDTO, MeetingEditInput>(new MeetingEditInput()
                {
                    Id       = Guid.Empty,
                    Name     = culture.Lang.metName,
                    Descript = culture.Lang.metDescript,
                    Setting  = JsonHelper.Serialize(Setting)
                });
                if (result.Code == EnumCode.成功)
                {
                    Meeting = result.Obj;
                }
            }
            if (Meeting.IsNull() || (!Meeting.IsNull() && (Meeting.Id.IsEmpty() || Meeting.Num.IsEmpty())))
            {
                throw new DbxException(EnumCode.初始失败);
            }

            //device
            Microphones = RecordingHelper.Microphones();
            Microphone  = Microphones.FirstOrDefault();

            //二维码
            var codeBitmap = QrCodeHelper.GetCode(string.Format(EngineHelper.Configuration.Settings.GetValue("meetingViewUrl"), Meeting.Id));

            MeetingCode = WpfHelper.BitmapToSource(codeBitmap);

            //本地数据库
            var meetingDatabasePath = MeetingHelper.GetMeetingDatabaseFile(Meeting.Id);

            if (!File.Exists(meetingDatabasePath))
            {
                FilesHelper.CopyFile(MeetingHelper.TemplateDatabaseFilePath, meetingDatabasePath);
            }

            //记录字体
            RecordFontSize = Setting.FontSize;

            //同步任务
            SyncTask();

            //同步状态
            SyncUI(EnumTaskStatus.Default);
            SyncUI(EnumTaskStatus.Init);

            //远程服务同步任务
            AppHelper.ServerObj.MeetingSyncTask();
        }
Ejemplo n.º 8
0
        private async Task RecordStream(TimerInfo timer, CancellationToken cancellationToken)
        {
            var mediaStreamInfo = await GetChannelStream(timer.ChannelId, "none", CancellationToken.None);

            var duration = (timer.EndDate - RecordingHelper.GetStartTime(timer)).TotalSeconds + timer.PrePaddingSeconds;

            HttpRequestOptions httpRequestOptions = new HttpRequestOptionsMod()
            {
                Url = mediaStreamInfo.Path + "?duration=" + duration
            };

            var info       = GetProgramInfoFromCache(timer.ChannelId, timer.ProgramId);
            var recordPath = RecordingPath;

            if (info.IsMovie)
            {
                recordPath = Path.Combine(recordPath, "Movies", StringHelper.RemoveSpecialCharacters(info.Name));
            }
            else
            {
                recordPath = Path.Combine(recordPath, "TV", StringHelper.RemoveSpecialCharacters(info.Name));
            }

            recordPath = Path.Combine(recordPath, RecordingHelper.GetRecordingName(timer, info));
            Directory.CreateDirectory(Path.GetDirectoryName(recordPath));

            var recording = _recordingProvider.GetAll().FirstOrDefault(x => string.Equals(x.Id, info.Id, StringComparison.OrdinalIgnoreCase));

            if (recording == null)
            {
                recording = new RecordingInfo()
                {
                    ChannelId       = info.ChannelId,
                    Id              = info.Id,
                    StartDate       = info.StartDate,
                    EndDate         = info.EndDate,
                    Genres          = info.Genres ?? null,
                    IsKids          = info.IsKids,
                    IsLive          = info.IsLive,
                    IsMovie         = info.IsMovie,
                    IsHD            = info.IsHD,
                    IsNews          = info.IsNews,
                    IsPremiere      = info.IsPremiere,
                    IsSeries        = info.IsSeries,
                    IsSports        = info.IsSports,
                    IsRepeat        = !info.IsPremiere,
                    Name            = info.Name,
                    EpisodeTitle    = info.EpisodeTitle ?? "",
                    ProgramId       = info.Id,
                    HasImage        = info.HasImage ?? false,
                    ImagePath       = info.ImagePath ?? null,
                    ImageUrl        = info.ImageUrl,
                    OriginalAirDate = info.OriginalAirDate,
                    Status          = RecordingStatus.Scheduled,
                    Overview        = info.Overview,
                    SeriesTimerId   = info.Id.Substring(0, 10)
                };
                _recordingProvider.Add(recording);
            }

            recording.Path   = recordPath;
            recording.Status = RecordingStatus.InProgress;
            _recordingProvider.Update(recording);

            try
            {
                httpRequestOptions.BufferContent     = false;
                httpRequestOptions.CancellationToken = cancellationToken;
                _logger.Info("Writing file to path: " + recordPath);
                using (var response = await _httpClient.SendAsync(httpRequestOptions, "GET"))
                {
                    using (var output = File.Open(recordPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        await response.Content.CopyToAsync(output, 4096, cancellationToken);
                    }
                }

                recording.Status = RecordingStatus.Completed;
            }
            catch (OperationCanceledException)
            {
                recording.Status = RecordingStatus.Cancelled;
            }
            catch
            {
                recording.Status = RecordingStatus.Error;
            }

            _recordingProvider.Update(recording);
            _timerProvider.Delete(timer);
            _logger.Info("Recording was a success");
        }