private void CheckEpsiodesForRecording(Schedule schedule, TvDatabase.Program program) { if (!schedule.DoesUseEpisodeManagement) return; //check how many episodes we got while (true) { IList<Recording> recordings = Recording.ListAll(); List<Recording> episodes = GetEpisodes(program.Title, recordings); if (episodes.Count <= schedule.MaxAirings) return; Recording oldestEpisode = GetOldestEpisode(episodes); if (oldestEpisode == null) return; Log.Write("diskmanagement: Delete episode {0} {1} {2} {3}", oldestEpisode.ReferencedChannel(), oldestEpisode.Title, oldestEpisode.StartTime.ToLongDateString(), oldestEpisode.StartTime.ToLongTimeString()); // Delete the file from disk and the recording entry from the database. bool result = RecordingFileHandler.DeleteRecordingOnDisk(oldestEpisode.FileName); if (result) { oldestEpisode.Delete(); } } }
public void OnScheduleEnded(string recordingFilename, Schedule recording, TvDatabase.Program program) { Log.Write("diskmanagement: recording {0} ended. type:{1} max episodes:{2}", program.Title, (ScheduleRecordingType)recording.ScheduleType, recording.MaxAirings); CheckEpsiodesForRecording(recording, program); }
public RecordingThread(Guid recorderId, string schedulerBaseUrl, CardChannelAllocation channelAllocation, DateTime startTimeUtc, DateTime stopTimeUtc, UpcomingProgram recordingProgram, string suggestedBaseFileName, TvDatabase.Card recordOnCard, TvDatabase.Channel channel) : base(recorderId, schedulerBaseUrl, channelAllocation, startTimeUtc, stopTimeUtc, recordingProgram, true) { _suggestedBaseFileName = suggestedBaseFileName; _recordOnCard = recordOnCard; _channel = channel; }
public RecordingThread(Guid recorderTunerId, string serverHostName, int tcpPort, CardChannelAllocation channelAllocation, DateTime startTimeUtc, DateTime stopTimeUtc, UpcomingProgram recordingProgram, string suggestedBaseFileName, TvDatabase.Card recordOnCard, TvDatabase.Channel channel) : base(recorderTunerId, serverHostName, tcpPort, channelAllocation, startTimeUtc, stopTimeUtc, recordingProgram, true) { _suggestedBaseFileName = suggestedBaseFileName; _recordOnCard = recordOnCard; _channel = channel; }
public static bool IsAutoLinked(TvDatabase.Channel mpChannel) { return Instance.IsAutoLinkedInternal(mpChannel); }
public void SetLinkedMediaPortalChannelInternal(Channel channel, TvDatabase.Channel mpChannel) { EnsureLoaded(); _readerWriterLock.EnterWriteLock(); try { ClearLinkedMediaPortalChannel(channel); ChannelLink link = new ChannelLink(channel.ChannelType, channel.ChannelId, channel.DisplayName, mpChannel.IdChannel, mpChannel.DisplayName); _linksById.Add(link.ChannelId, link); } finally { _readerWriterLock.ExitWriteLock(); } }
public bool IsAutoLinkedInternal(TvDatabase.Channel mpChannel) { EnsureLoaded(); _readerWriterLock.EnterReadLock(); try { return _autoLinkedMPChannels.ContainsKey(mpChannel.IdChannel); } finally { _readerWriterLock.ExitReadLock(); } }
private ChannelLink GetChannelLinkForMediaPortalChannelInternal(TvDatabase.Channel channel) { EnsureLoaded(); _readerWriterLock.EnterReadLock(); try { foreach (ChannelLink link in _linksById.Values) { if (link.MPChannelId == channel.IdChannel && link.MPChannelName == channel.DisplayName) { return link; } } return null; } finally { _readerWriterLock.ExitReadLock(); } }
public static ChannelLink GetChannelLinkForMediaPortalChannel(TvDatabase.Channel channel) { return Instance.GetChannelLinkForMediaPortalChannelInternal(channel); }
private static void EnsureGuideChannelForDvbEpg(SchedulerServiceAgent tvSchedulerAgent, GuideServiceAgent tvGuideAgent, Channel channel, TvDatabase.Channel mpChannel) { if (!channel.GuideChannelId.HasValue) { string externalId = mpChannel.ExternalId; if (String.IsNullOrEmpty(externalId)) { externalId = mpChannel.DisplayName; } channel.GuideChannelId = tvGuideAgent.EnsureChannel(externalId, mpChannel.DisplayName, channel.ChannelType); tvSchedulerAgent.AttachChannelToGuide(channel.ChannelId, channel.GuideChannelId.Value); } }
public static bool CreateProgram(TvDatabase.Program program, int scheduleType, out ISchedule currentSchedule) { ServiceRegistration.Get<ILogger>().Debug("SlimTvService3.CreateProgram: program = {0}", program.ToString()); TvDatabase.Schedule schedule; TvDatabase.Schedule saveSchedule = null; TvBusinessLayer layer = new TvBusinessLayer(); if (IsRecordingProgram(program, out schedule, false)) // check if schedule is already existing { ServiceRegistration.Get<ILogger>().Debug("SlimTvService3.CreateProgram - series schedule found ID={0}, Type={1}", schedule.IdSchedule, schedule.ScheduleType); ServiceRegistration.Get<ILogger>().Debug(" - schedule= {0}", schedule.ToString()); if (schedule.IsSerieIsCanceled(schedule.GetSchedStartTimeForProg(program), program.IdChannel)) { // Delete the cancelled schedule. saveSchedule = schedule; schedule = new TvDatabase.Schedule(program.IdChannel, program.Title, program.StartTime, program.EndTime) { PreRecordInterval = saveSchedule.PreRecordInterval, PostRecordInterval = saveSchedule.PostRecordInterval, ScheduleType = (int)ScheduleRecordingType.Once }; } } else { ServiceRegistration.Get<ILogger>().Debug("SlimTvService3.CreateProgram - no series schedule"); // No series schedule => create it schedule = new TvDatabase.Schedule(program.IdChannel, program.Title, program.StartTime, program.EndTime) { PreRecordInterval = Int32.Parse(layer.GetSetting("preRecordInterval", "5").Value), PostRecordInterval = Int32.Parse(layer.GetSetting("postRecordInterval", "5").Value), ScheduleType = scheduleType }; } if (saveSchedule != null) { ServiceRegistration.Get<ILogger>().Debug("SlimTvService3.CreateProgram - UnCancelSerie at {0}", program.StartTime); saveSchedule.UnCancelSerie(program.StartTime, program.IdChannel); saveSchedule.Persist(); currentSchedule = saveSchedule.ToSchedule(); } else { ServiceRegistration.Get<ILogger>().Debug("SlimTvService3.CreateProgram - create schedule = {0}", schedule.ToString()); schedule.Persist(); currentSchedule = schedule.ToSchedule(); } return currentSchedule != null; }
private bool CreateSpawnedOnceSchedule(Schedule schedule, TvDatabase.Program current) { bool isSpawnedOnceScheduleCreated = false; Schedule dbSchedule = Schedule.RetrieveOnce(current.IdChannel, current.Title, current.StartTime, current.EndTime); if (dbSchedule == null) // not created yet { Schedule once = Schedule.RetrieveOnce(current.IdChannel, current.Title, current.StartTime, current.EndTime); if (once == null) // make sure that we DO NOT create multiple once recordings. { Schedule newSchedule = new Schedule(schedule); newSchedule.IdChannel = current.IdChannel; newSchedule.StartTime = current.StartTime; newSchedule.EndTime = current.EndTime; newSchedule.ScheduleType = 0; // type Once newSchedule.Series = true; newSchedule.IdParentSchedule = schedule.IdSchedule; newSchedule.Persist(); isSpawnedOnceScheduleCreated = true; // 'once typed' created schedule will be used instead at next call of IsTimeToRecord() } } return isSpawnedOnceScheduleCreated; }
private static void EnsureGuideChannelForDvbEpg(Channel channel, TvDatabase.Channel mpChannel) { if (!channel.GuideChannelId.HasValue) { string externalId = mpChannel.ExternalId; if (String.IsNullOrEmpty(externalId)) { externalId = mpChannel.DisplayName; } channel.GuideChannelId = Proxies.GuideService.EnsureChannelExists(externalId, mpChannel.DisplayName, channel.ChannelType).Result; Proxies.SchedulerService.AttachChannelToGuide(channel.ChannelId, channel.GuideChannelId.Value).Wait(); } }
public ChannelItem(TvDatabase.Channel channel) { _channel = channel; }
public ImportChannel(TvDatabase.Channel mpChannel, string groupName, int groupSequence) { this.Channel = mpChannel; this.GroupName = groupName; this.GroupSequence = groupSequence; if (mpChannel.ChannelNumber > 0) { this.LogicalChannelNumber = mpChannel.ChannelNumber; } }
private static Channel EnsureChannelForDvbEpg(SchedulerServiceAgent tvSchedulerAgent, TvDatabase.Channel mpChannel, bool epgSyncAutoCreateChannels, bool epgSyncAutoCreateChannelsWithGroup) { ChannelLink channelLink = ChannelLinks.GetChannelLinkForMediaPortalChannel(mpChannel); ChannelType channelType = mpChannel.IsTv ? ChannelType.Television : ChannelType.Radio; Channel channel = null; if (channelLink != null) { channel = tvSchedulerAgent.GetChannelById(channelLink.ChannelId); if (channel == null) { channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, channelLink.ChannelName); } } if (channel == null) { channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, mpChannel.DisplayName); } if (channel == null && (epgSyncAutoCreateChannels || epgSyncAutoCreateChannelsWithGroup)) { string groupName = "DVB-EPG"; if (epgSyncAutoCreateChannelsWithGroup) { IList<TvDatabase.GroupMap> groupMaps = mpChannel.ReferringGroupMap(); foreach (TvDatabase.GroupMap groupMap in groupMaps) { TvDatabase.ChannelGroup channelGroup = TvDatabase.ChannelGroup.Retrieve(groupMap.IdGroup); if (channelGroup != null) { groupName = channelGroup.GroupName; break; } } } Guid channelId = tvSchedulerAgent.EnsureChannel(channelType, mpChannel.DisplayName, groupName); channel = tvSchedulerAgent.GetChannelById(channelId); if (!channel.LogicalChannelNumber.HasValue && mpChannel.ChannelNumber > 0) { channel.LogicalChannelNumber = mpChannel.ChannelNumber; tvSchedulerAgent.SaveChannel(channel); } } return channel; }
public static bool IsRecordingProgram(TvDatabase.Program program, out TvDatabase.Schedule recordingSchedule, bool filterCanceledRecordings) { recordingSchedule = null; IList<TvDatabase.Schedule> schedules = TvDatabase.Schedule.ListAll(); foreach (TvDatabase.Schedule schedule in schedules) { if (schedule.Canceled != TvDatabase.Schedule.MinSchedule || (filterCanceledRecordings && schedule.IsSerieIsCanceled(schedule.GetSchedStartTimeForProg(program), program.IdChannel))) { continue; } if (schedule.IsManual && schedule.IdChannel == program.IdChannel && schedule.EndTime >= program.EndTime) { TvDatabase.Schedule manual = schedule.Clone(); manual.ProgramName = program.Title; manual.EndTime = program.EndTime; manual.StartTime = program.StartTime; if (manual.IsRecordingProgram(program, filterCanceledRecordings)) { recordingSchedule = schedule; return true; } } else if (schedule.IsRecordingProgram(program, filterCanceledRecordings)) { recordingSchedule = schedule; return true; } } return false; }
public ImportChannel(TvDatabase.Channel mpChannel, string groupName, int groupSequence) { this.Channel = mpChannel; this.GroupName = groupName; this.GroupSequence = groupSequence; }
public static void SetLinkedMediaPortalChannel(Channel channel, TvDatabase.Channel mpChannel) { Instance.SetLinkedMediaPortalChannelInternal(channel, mpChannel); }