Exemplo n.º 1
0
        public IEnumerable <RecordingInfo> GetRecordings(CancellationToken cancellationToken)
        {
            var response = GetFromService <List <Recording> >(cancellationToken, "GetRecordings");

            var recordings = response.Select(r =>
            {
                var recording = new RecordingInfo()
                {
                    ChannelId    = r.ChannelId.ToString(CultureInfo.InvariantCulture),
                    EndDate      = r.EndTime,
                    EpisodeTitle = r.EpisodeName,
                    Genres       = new List <String>(),
                    Id           = r.Id.ToString(CultureInfo.InvariantCulture),
                    Name         = r.Title,
                    Overview     = r.Description,
                    ProgramId    = r.ScheduleId.ToString(CultureInfo.InvariantCulture),
                    StartDate    = r.StartTime,
                    ImageUrl     = _wssProxy.GetRecordingImageUrl(r.Id.ToString()),
                };

                if (!String.IsNullOrEmpty(r.Genre))
                {
                    recording.Genres.Add(r.Genre);
                }

                return(recording);
            }).ToList();

            return(recordings);
        }
        public IEnumerable <RecordingInfo> GetRecordings(CancellationToken cancellationToken)
        {
            var configuration = Plugin.Instance.Configuration;
            var localpath     = String.Format("{0}", configuration.LocalFilePath);
            var remotepath    = String.Format("{0}", configuration.RemoteFilePath);

            var schedules  = GetFromService <List <Schedule> >(cancellationToken, "GetSchedules");
            var recordings = GetFromService <List <Recording> >(cancellationToken, "GetRecordings").Select(r =>
            {
                var recording = new RecordingInfo()
                {
                    Name         = r.Title,
                    EpisodeTitle = r.EpisodeName,
                    Id           = r.Id,
                    TimerId      = r.ScheduleId.ToString(CultureInfo.InvariantCulture),
                    ChannelId    = r.ChannelId.ToString(CultureInfo.InvariantCulture),
                    StartDate    = r.StartTime,
                    EndDate      = r.EndTime,
                    Overview     = r.Description,
                    Genres       = new List <String>(),
                    Status       = (r.IsRecording) ? RecordingStatus.InProgress : RecordingStatus.Completed,
                    HasImage     = false,
                };

                if (!String.IsNullOrEmpty(r.EpisodeNum))
                {
                    int EpisodeNumber;
                    int SeasonNumber;

                    recording.IsSeries = true;
                    recording.ShowId   = r.Title;

                    if (String.IsNullOrEmpty(r.SeriesNum))
                    {
                        Int32.TryParse((Regex.Match(r.EpisodeNum, @"\d+").Value), out EpisodeNumber);
                        recording.EpisodeTitle = String.Format("E{0} - {1}", EpisodeNumber, r.EpisodeName);
                    }

                    if (!String.IsNullOrEmpty(r.SeriesNum))
                    {
                        Int32.TryParse((Regex.Match(r.SeriesNum, @"\d+").Value), out SeasonNumber);
                        Int32.TryParse((Regex.Match(r.EpisodeNum, @"\d+").Value), out EpisodeNumber);
                        recording.EpisodeTitle = String.Format("S{0}, E{1} - {2}", SeasonNumber, EpisodeNumber, r.EpisodeName);
                    }
                }

                if (!r.IsRecording)
                {
                    recording.HasImage = true;
                    recording.ImageUrl = _wssProxy.GetRecordingImageUrl(r.Id);
                }

                //if (configuration.EnableDirectAccess && !configuration.RequiresPathSubstitution && !r.IsRecording)
                if (configuration.EnableDirectAccess && !configuration.RequiresPathSubstitution)
                {
                    recording.Path = r.FileName;
                }

                //if (configuration.EnableDirectAccess && configuration.RequiresPathSubstitution && !r.IsRecording)
                if (configuration.EnableDirectAccess && configuration.RequiresPathSubstitution)
                {
                    recording.Path = r.FileName.Replace(localpath, remotepath);
                }

                if (!String.IsNullOrEmpty(r.Genre))
                {
                    recording.Genres.Add(r.Genre);
                }

                var series = schedules.Where(s => (s.ScheduleType > 0 && s.Title == r.Title)).FirstOrDefault();
                if (series != null)
                {
                    recording.SeriesTimerId = series.Id.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    Plugin.Logger.Info("The recording \"{0} - {1}\" does not match any series schedule", r.Title, r.EpisodeName);
                }

                return(recording);
            }).ToList();

            Plugin.Logger.Info("Found recordings: {0} ", recordings.Count());
            return(recordings);
        }
        public IEnumerable <RecordingInfo> GetRecordings(CancellationToken cancellationToken)
        {
            var response      = GetFromService <List <Recording> >(cancellationToken, "GetRecordings");
            var configuration = Plugin.Instance.Configuration;

            if (configuration.EnableDirectAccess && !configuration.RequiresPathSubstitution)
            {
                var recordings = response.Select(r =>
                {
                    var recording = new RecordingInfo()
                    {
                        ChannelId    = r.ChannelId.ToString(CultureInfo.InvariantCulture),
                        EndDate      = r.EndTime,
                        EpisodeTitle = r.EpisodeName,
                        Genres       = new List <String>(),
                        Id           = r.Id.ToString(CultureInfo.InvariantCulture),
                        IsSeries     = (!String.IsNullOrEmpty(r.EpisodeNum)) ? true : false,
                        Name         = r.Title,
                        Overview     = r.Description,
                        ProgramId    = r.ScheduleId.ToString(CultureInfo.InvariantCulture),
                        StartDate    = r.StartTime,
                        ImageUrl     = _wssProxy.GetRecordingImageUrl(r.Id.ToString()),
                        Path         = r.FileName,
                    };

                    if (r.IsRecording)
                    {
                        var schedule = GetFromService <Schedule>(cancellationToken, "GetScheduleById?scheduleId={0}", r.ScheduleId);
                        {
                            if (schedule.Series)
                            {
                                recording.SeriesTimerId = schedule.ParentScheduleId.ToString(CultureInfo.InvariantCulture);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(r.Genre))
                    {
                        recording.Genres.Add(r.Genre);
                    }

                    return(recording);
                }).ToList();

                return(recordings);
            }

            else if (configuration.EnableDirectAccess && configuration.RequiresPathSubstitution)
            {
                var localpath  = String.Format("{0}", configuration.LocalFilePath);
                var remotepath = String.Format("{0}", configuration.RemoteFilePath);

                var recordings = response.Select(r =>
                {
                    var recording = new RecordingInfo()
                    {
                        ChannelId    = r.ChannelId.ToString(CultureInfo.InvariantCulture),
                        EndDate      = r.EndTime,
                        EpisodeTitle = r.EpisodeName,
                        Genres       = new List <String>(),
                        Id           = r.Id.ToString(CultureInfo.InvariantCulture),
                        IsSeries     = (!String.IsNullOrEmpty(r.EpisodeNum)) ? true : false,
                        Name         = r.Title,
                        Overview     = r.Description,
                        ProgramId    = r.ScheduleId.ToString(CultureInfo.InvariantCulture),
                        StartDate    = r.StartTime,
                        ImageUrl     = _wssProxy.GetRecordingImageUrl(r.Id.ToString()),
                        Path         = r.FileName.Replace(localpath, remotepath),
                    };

                    if (r.IsRecording)
                    {
                        var schedule = GetFromService <Schedule>(cancellationToken, "GetScheduleById?scheduleId={0}", r.ScheduleId);
                        {
                            if (schedule.Series)
                            {
                                recording.SeriesTimerId = schedule.ParentScheduleId.ToString(CultureInfo.InvariantCulture);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(r.Genre))
                    {
                        recording.Genres.Add(r.Genre);
                    }

                    return(recording);
                }).ToList();

                return(recordings);
            }

            else
            {
                var recordings = response.Select(r =>
                {
                    var recording = new RecordingInfo()
                    {
                        ChannelId    = r.ChannelId.ToString(CultureInfo.InvariantCulture),
                        EndDate      = r.EndTime,
                        EpisodeTitle = r.EpisodeName,
                        Genres       = new List <String>(),
                        Id           = r.Id.ToString(CultureInfo.InvariantCulture),
                        IsSeries     = (!String.IsNullOrEmpty(r.EpisodeNum)) ? true : false,
                        Name         = r.Title,
                        Overview     = r.Description,
                        ProgramId    = r.ScheduleId.ToString(CultureInfo.InvariantCulture),
                        StartDate    = r.StartTime,
                        ImageUrl     = _wssProxy.GetRecordingImageUrl(r.Id.ToString(), scheduleDefaults.PreRecordInterval),
                    };

                    if (r.IsRecording)
                    {
                        var schedule = GetFromService <Schedule>(cancellationToken, "GetScheduleById?scheduleId={0}", r.ScheduleId);
                        {
                            if (schedule.Series)
                            {
                                recording.SeriesTimerId = schedule.ParentScheduleId.ToString(CultureInfo.InvariantCulture);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(r.Genre))
                    {
                        recording.Genres.Add(r.Genre);
                    }

                    return(recording);
                }).ToList();

                return(recordings);
            }
        }