Пример #1
0
 public override bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs)
 {
     programs = _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.ChannelId), from, to)
                .Select(tvProgram => tvProgram.ToProgram(true))
                .Distinct(ProgramComparer.Instance)
                .ToList();
     return(programs.Count > 0);
 }
Пример #2
0
        //public override async Task<AsyncResult<IDictionary<int, IProgram[]>>> GetNowAndNextForChannelGroupAsync(IChannelGroup channelGroup)
        //{
        //  var nowNextPrograms = new Dictionary<int, IProgram[]>();
        //  IList<IChannel> channels;
        //  if (!GetChannels(channelGroup, out channels))
        //    return false;

        //  foreach (IChannel channel in channels)
        //  {
        //    IProgram programNow;
        //    IProgram programNext;
        //    if (GetNowNextProgram(channel, out programNow, out programNext))
        //      nowNextPrograms[channel.ChannelId] = new[] { programNow, programNext };
        //  }
        //  return true;
        //}

        public override async Task <AsyncResult <IList <IProgram> > > GetProgramsAsync(IChannel channel, DateTime from, DateTime to)
        {
            await _initComplete.Task;

            var programs = _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.ChannelId), from, to)
                           .Select(tvProgram => GetProgram(tvProgram, true))
                           .Distinct(ProgramComparer.Instance)
                           .ToList();
            var success = programs.Count > 0;

            return(new AsyncResult <IList <IProgram> >(success, programs));
        }
Пример #3
0
        public bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs)
        {
#if TVE3
            programs = _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.ChannelId), from, to)
#else
            IProgramService programService = GlobalServiceProvider.Instance.Get <IProgramService>();
            programs = programService.GetProgramsByChannelAndStartEndTimes(channel.ChannelId, from, to)
#endif
                       .Select(tvProgram => tvProgram.ToProgram(true))
                       .Distinct(ProgramComparer.Instance)
                       .ToList();
            return(programs.Count > 0);
        }
Пример #4
0
        private static void UpdateCurrentProgramTitle(ref Schedule recNew)
        {
            TvBusinessLayer layer    = new TvBusinessLayer();
            IList <Program> programs = layer.GetPrograms(recNew.ReferencedChannel(), recNew.StartTime, recNew.EndTime);

            if (programs != null && programs.Count > 0)
            {
                recNew.ProgramName = programs[0].Title;
            }
        }
Пример #5
0
        private WebScheduledRecording GetScheduledRecording(Schedule schedule, DateTime date)
        {
            // ignore schedules that don't even match the date we are checking for
            ScheduleRecordingType type = (ScheduleRecordingType)schedule.ScheduleType;

            if ((type == ScheduleRecordingType.Weekends && !(date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)) ||
                (type == ScheduleRecordingType.WorkingDays && (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)) ||
                (type == ScheduleRecordingType.Weekly && schedule.StartTime.DayOfWeek != date.DayOfWeek) ||
                (type == ScheduleRecordingType.Once && schedule.StartTime.Date != date.Date) ||
                (type == ScheduleRecordingType.WeeklyEveryTimeOnThisChannel && schedule.StartTime.Date != date.Date))
            {
                return(null);
            }

            // retrieve some data
            var channel = Channel.Retrieve(schedule.IdChannel);
            WebScheduledRecording recording = new WebScheduledRecording();

            recording.ScheduleId = schedule.IdSchedule;

            // first check all types that do not require any EPG matching
            ScheduleRecordingType[] noEpgTypes = { ScheduleRecordingType.Daily,  ScheduleRecordingType.Weekends, ScheduleRecordingType.WorkingDays,
                                                   ScheduleRecordingType.Weekly, ScheduleRecordingType.Once };
            if (noEpgTypes.Contains(type))
            {
                recording.ChannelId   = channel.IdChannel;
                recording.ChannelName = channel.DisplayName;
                recording.StartTime   = schedule.StartTime;
                recording.EndTime     = schedule.EndTime;
                var matchingPrograms = _tvBusiness.GetPrograms(channel, schedule.StartTime, schedule.EndTime);
                recording.ProgramId = matchingPrograms.Any() ? matchingPrograms.First().IdProgram : 0;
                recording.Title     = matchingPrograms.Any() ? matchingPrograms.First().Title : schedule.ProgramName;
                return(recording);
            }

            // all schedule types which reach this far match a program in the EPG
            IList <Program> programs =
                type == ScheduleRecordingType.WeeklyEveryTimeOnThisChannel || type == ScheduleRecordingType.EveryTimeOnThisChannel ?
                _tvBusiness.GetPrograms(channel, date.Date, date.Date.Add(TimeSpan.FromDays(1))) :
                _tvBusiness.GetPrograms(date.Date, date.Date.Add(TimeSpan.FromDays(1)));
            var program = programs.FirstOrDefault(x => x.Title == schedule.ProgramName && (x.StartTime > DateTime.Now || date.Date < DateTime.Today));

            if (program == null)
            {
                return(null);
            }

            // set properties from the program and channel of the program
            channel               = program.ReferencedChannel();
            recording.ChannelId   = channel.IdChannel;
            recording.ChannelName = channel.DisplayName;
            recording.StartTime   = program.StartTime;
            recording.EndTime     = program.EndTime;
            recording.ProgramId   = program.IdProgram;
            recording.Title       = program.Title;
            return(recording);
        }
Пример #6
0
        private void OnShowContextMenu(int iItem, bool clicked)
        {
            m_iSelectedItem = iItem;
            GUIListItem item = GetItem(iItem);

            if (item == null)
            {
                return;
            }

            if (item.IsFolder && clicked)
            {
                bool noitems = false;
                if (item.Label == "..")
                {
                    if (selectedItem != null)
                    {
                        selectedItem = null;
                    }
                    LoadDirectory();
                    return;
                }
                if (selectedItem == null)
                {
                    IList <Schedule> seriesList = TVHome.Util.GetRecordingTimes(item.TVTag as Schedule);
                    if (seriesList.Count < 1)
                    {
                        noitems = true; // no items existing
                    }
                    else
                    {
                        selectedItem = item.TVTag as Schedule;
                    }
                }
                if (noitems == false)
                {
                    LoadDirectory();
                    return;
                }
            }

            bool showSeries = btnSeries.Selected;

            Schedule rec = item.TVTag as Schedule;

            if (rec == null)
            {
                return;
            }

            Log.Info("OnShowContextMenu: Rec = {0}", rec.ToString());
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading(rec.ProgramName);

            if (showSeries && item.IsFolder)
            {
                dlg.AddLocalizedString(982); //Cancel this show (618=delete)
                dlg.AddLocalizedString(888); //Episodes management
            }
            else if (rec.Series == false)
            {
                dlg.AddLocalizedString(618); //delete
            }
            else
            {
                dlg.AddLocalizedString(981); //Cancel this show
                dlg.AddLocalizedString(982); //Delete this entire recording
                dlg.AddLocalizedString(888); //Episodes management
            }
            VirtualCard card;
            TvServer    server = new TvServer();

            bool isRec = Schedule.IsScheduleRecording(rec.IdSchedule); //TVHome.IsRecordingSchedule(rec, null, out card);

            if (isRec)
            {
                dlg.AddLocalizedString(979); //Play recording from beginning
                dlg.AddLocalizedString(980); //Play recording from live point
            }

            //Schedule schedDB = Schedule.Retrieve(rec.IdSchedule);
            //if (schedDB.ScheduleType != (int)ScheduleRecordingType.Once)
            //{
            dlg.AddLocalizedString(1048); // settings
            //}

            dlg.DoModal(GetID);
            if (dlg.SelectedLabel == -1)
            {
                return;
            }

            bool isSchedRec = TvDatabase.Schedule.IsScheduleRecording(rec.IdSchedule);
            //TVHome.IsRecordingSchedule(rec, null, out card);

            string fileName = "";

            if (isSchedRec)
            {
                bool isCardRec = server.IsRecording(rec.ReferencedChannel().IdChannel, out card);
                if (isCardRec && card != null)
                {
                    fileName = card.RecordingFileName;
                }
            }
            Log.Info("recording fname:{0}", fileName);
            switch (dlg.SelectedId)
            {
            case 888: ////Episodes management
                TvPriorities.OnSetEpisodesToKeep(rec);
                break;

            case 1048: ////settings
                Schedule schedule = item.MusicTag as Schedule;
                if (schedule == null)
                {
                    schedule = item.TVTag as Schedule;
                }
                if (schedule != null)
                {
                    TVProgramInfo.CurrentRecording = schedule;
                    GUIWindowManager.ActivateWindow((int)Window.WINDOW_TV_PROGRAM_INFO);
                }
                return;

            case 882: ////Quality settings
                TvPriorities.OnSetQuality(rec);
                break;

            case 981: //Cancel this show
            {
                var layer = new TvBusinessLayer();
                // get the program that this episode is for
                var progs = layer.GetPrograms(rec.ReferencedChannel(), rec.StartTime, rec.EndTime);
                // pick up the schedule that is actually used for recording
                // see TVUtil.GetRecordingTimes where schedules are all spawend as one off types
                // and this is what rec is (ie. it does not actually exist in the database)
                var  realSchedule = Schedule.Retrieve(rec.IdParentSchedule) ?? rec;
                bool res          = TVUtil.DeleteRecAndSchedWithPrompt(realSchedule, progs[0]);
                if (res)
                {
                    LoadDirectory();
                }
            }
            break;

            case 982: //Delete series recording
                goto case 618;

            case 618: // delete entire recording
            {
                bool res = TVUtil.DeleteRecAndEntireSchedWithPrompt(rec, rec.StartTime);
                if (res)
                {
                    if (showSeries && !item.IsFolder)
                    {
                        OnShowContextMenu(0, true);
                        return;
                    }
                    else
                    {
                        LoadDirectory();
                    }
                }
            }
            break;

            case 979: // Play recording from beginning
            {
                Recording recDB = Recording.Retrieve(fileName);
                if (recDB != null)
                {
                    TVUtil.PlayRecording(recDB);
                }
            }
                return;

            case 980: // Play recording from live point
            {
                TVHome.ViewChannelAndCheck(rec.ReferencedChannel());
                if (g_Player.Playing)
                {
                    g_Player.ShowFullScreenWindow();
                }

                /*
                 * g_Player.Stop();
                 * if (System.IO.File.Exists(fileName))
                 * {
                 * g_Player.Play(fileName, g_Player.MediaType.Recording);
                 * g_Player.SeekAbsolute(g_Player.Duration);
                 * g_Player.ShowFullScreenWindow();
                 * return;
                 * }
                 * else
                 * {
                 * string url = server.GetRtspUrlForFile(fileName);
                 * Log.Info("recording url:{0}", url);
                 * if (url.Length > 0)
                 * {
                 *  g_Player.Play(url, g_Player.MediaType.Recording);
                 *
                 *  if (g_Player.Playing)
                 *  {
                 *    g_Player.SeekAbsolute(g_Player.Duration);
                 *    g_Player.SeekAbsolute(g_Player.Duration);
                 *    g_Player.ShowFullScreenWindow();
                 *    return;
                 *  }
                 * }
                 * }*/
            }
            break;
            }
            while (m_iSelectedItem >= GetItemCount() && m_iSelectedItem > 0)
            {
                m_iSelectedItem--;
            }
            GUIControl.SelectItemControl(GetID, listSchedules.GetID, m_iSelectedItem);
        }
        private void ImportPrograms(Channel dbChannel, IList <EpgProgram> epgPrograms)
        {
            int  iInserted = 0;
            bool hasGaps   = false;

            _layer.RemoveOldPrograms(dbChannel.IdChannel);

            EpgHoleCollection holes = new EpgHoleCollection();

            if ((dbChannel.EpgHasGaps || _alwaysFillHoles) && !_alwaysReplace)
            {
                Log.Epg("{0}: {1} is marked to have epg gaps. Calculating them...", _grabberName, dbChannel.DisplayName);
                IList <Program> infos = _layer.GetPrograms(dbChannel, DateTime.Now);
                if (infos.Count > 1)
                {
                    for (int i = 1; i < infos.Count; i++)
                    {
                        Program  prev    = infos[i - 1];
                        Program  current = infos[i];
                        TimeSpan diff    = current.StartTime - prev.EndTime;
                        if (diff.TotalMinutes > 5)
                        {
                            holes.Add(new EpgHole(prev.EndTime, current.StartTime));
                        }
                    }
                }
                Log.Epg("{0}: {1} Found {2} epg holes.", _grabberName, dbChannel.DisplayName, holes.Count);
            }
            DateTime   dbLastProgram = _layer.GetNewestProgramForChannel(dbChannel.IdChannel);
            EpgProgram lastProgram   = null;

            for (int i = 0; i < epgPrograms.Count; i++)
            {
                EpgProgram epgProgram = epgPrograms[i];
                // Check for dupes
                if (lastProgram != null)
                {
                    if (epgProgram.StartTime == lastProgram.StartTime && epgProgram.EndTime == lastProgram.EndTime)
                    {
                        continue;
                    }
                    TimeSpan diff = epgProgram.StartTime - lastProgram.EndTime;
                    if (diff.Minutes > 5)
                    {
                        hasGaps = true;
                    }
                }
                if (epgProgram.StartTime <= dbLastProgram && !_alwaysReplace)
                {
                    if (epgProgram.StartTime < DateTime.Now)
                    {
                        continue;
                    }
                    if (!holes.FitsInAnyHole(epgProgram.StartTime, epgProgram.EndTime))
                    {
                        continue;
                    }
                    Log.Epg("{0}: Great we stuffed an epg hole {1}-{2} :-)", _grabberName,
                            epgProgram.StartTime.ToShortDateString() + " " + epgProgram.StartTime.ToShortTimeString(),
                            epgProgram.EndTime.ToShortDateString() + " " + epgProgram.EndTime.ToShortTimeString());
                }
                Program prog = null;
                if (_alwaysReplace)
                {
                    try
                    {
                        IList <Program> epgs = _layer.GetProgramExists(dbChannel, epgProgram.StartTime, epgProgram.EndTime);

                        if (epgs.Count > 0)
                        {
                            prog = epgs[0];
                            if (epgs.Count > 1)
                            {
                                Log.Epg("- {0} entries are obsolete for {1} from {2} to {3}", epgs.Count - 1, dbChannel.DisplayName,
                                        epgProgram.StartTime, epgProgram.EndTime);
                            }
                            for (int idx = 1; idx < epgs.Count; idx++)
                            {
                                try
                                {
                                    epgs[idx].Delete();
                                    Log.Epg("- Deleted the epg entry {0} ({1} - {2})", epgs[idx].Title, epgs[idx].StartTime,
                                            epgs[idx].EndTime);
                                }
                                catch (Exception ex)
                                {
                                    Log.Epg("Error during epg entry deletion: {0}", ex.Message);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Epg("Error the existing epg entry check: {0}", ex.Message);
                    }
                }
                AddProgramAndApplyTemplates(dbChannel, epgProgram, prog);
                iInserted++;
                lastProgram = epgProgram;
            }
            dbChannel.LastGrabTime = DateTime.Now;
            dbChannel.EpgHasGaps   = hasGaps;
            dbChannel.Persist();

            //_layer.StartResetProgramStatesThread(System.Threading.ThreadPriority.Lowest);


            Log.Epg("- Inserted {0} epg entries for channel {1}", iInserted, dbChannel.DisplayName);
        }
Пример #8
0
 public IList <WebProgramBasic> GetProgramsBasicForChannel(int channelId, DateTime startTime, DateTime endTime)
 {
     return(_tvBusiness.GetPrograms(Channel.Retrieve(channelId), startTime, endTime).Select(p => p.ToWebProgramBasic()).ToList());
 }