Esempio n. 1
0
        public IActionResult GetCalendarFeed(int pastDays = 7, int futureDays = 28, string tagList = "", bool unmonitored = false)
        {
            var start = DateTime.Today.AddDays(-pastDays);
            var end   = DateTime.Today.AddDays(futureDays);
            var tags  = new List <int>();

            if (tagList.IsNotNullOrWhiteSpace())
            {
                tags.AddRange(tagList.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var books    = _bookService.BooksBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//readarr.com//Readarr//EN"
            };

            var calendarName = "Readarr Book Schedule";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var book in books.OrderBy(v => v.ReleaseDate.Value))
            {
                var author = _authorService.GetAuthor(book.AuthorId); // Temp fix TODO: Figure out why Book.Author is not populated during BooksBetweenDates Query

                if (tags.Any() && tags.None(author.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <CalendarEvent>();
                occurrence.Uid = "Readarr_book_" + book.Id;

                //occurrence.Status = book.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
                occurrence.Description = book.Editions.Value.Single(x => x.Monitored).Overview;
                occurrence.Categories  = book.Genres;

                occurrence.Start = new CalDateTime(book.ReleaseDate.Value.ToLocalTime())
                {
                    HasTime = false
                };

                occurrence.Summary = $"{author.Name} - {book.Title}";
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(Content(icalendar, "text/calendar"));
        }
Esempio n. 2
0
        public IActionResult GetCalendarFeed(int pastDays = 7, int futureDays = 28, string tagList = "", bool unmonitored = false)
        {
            var start = DateTime.Today.AddDays(-pastDays);
            var end   = DateTime.Today.AddDays(futureDays);
            var tags  = new List <int>();

            if (tagList.IsNotNullOrWhiteSpace())
            {
                tags.AddRange(tagList.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var movies   = _movieService.GetMoviesBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//radarr.video//Radarr//EN"
            };

            var calendarName = "Radarr Movies Calendar";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var movie in movies.OrderBy(v => v.Added))
            {
                if (tags.Any() && tags.None(movie.Tags.Contains))
                {
                    continue;
                }

                CreateEvent(calendar, movie, "cinematic");
                CreateEvent(calendar, movie, "digital");
                CreateEvent(calendar, movie, "physical");
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(Content(icalendar, "text/calendar"));
        }
Esempio n. 3
0
        private object GetCalendarFeed()
        {
            var pastDays    = 7;
            var futureDays  = 28;
            var start       = DateTime.Today.AddDays(-pastDays);
            var end         = DateTime.Today.AddDays(futureDays);
            var unmonitored = Request.GetBooleanQueryParameter("unmonitored");
            var tags        = new List <int>();

            var queryPastDays   = Request.Query.PastDays;
            var queryFutureDays = Request.Query.FutureDays;
            var queryTags       = Request.Query.Tags;

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var books    = _bookService.BooksBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//readarr.com//Readarr//EN"
            };

            var calendarName = "Readarr Book Schedule";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var book in books.OrderBy(v => v.ReleaseDate.Value))
            {
                var author = _authorService.GetAuthor(book.AuthorId); // Temp fix TODO: Figure out why Album.Artist is not populated during AlbumsBetweenDates Query

                if (tags.Any() && tags.None(author.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <CalendarEvent>();
                occurrence.Uid = "Readarr_book_" + book.Id;

                //occurrence.Status = album.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
                occurrence.Description = book.Editions.Value.Single(x => x.Monitored).Overview;
                occurrence.Categories  = book.Genres;

                occurrence.Start = new CalDateTime(book.ReleaseDate.Value.ToLocalTime())
                {
                    HasTime = false
                };

                occurrence.Summary = $"{author.Name} - {book.Title}";
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }
Esempio n. 4
0
        private object GetCalendarFeed()
        {
            var pastDays    = 7;
            var futureDays  = 28;
            var start       = DateTime.Today.AddDays(-pastDays);
            var end         = DateTime.Today.AddDays(futureDays);
            var unmonitored = false;

            //var premiersOnly = false;
            var tags = new List <int>();

            // TODO: Remove start/end parameters in v3, they don't work well for iCal
            var queryStart       = Request.Query.Start;
            var queryEnd         = Request.Query.End;
            var queryPastDays    = Request.Query.PastDays;
            var queryFutureDays  = Request.Query.FutureDays;
            var queryUnmonitored = Request.Query.Unmonitored;

            // var queryPremiersOnly = Request.Query.PremiersOnly;
            var queryTags = Request.Query.Tags;

            if (queryStart.HasValue)
            {
                start = DateTime.Parse(queryStart.Value);
            }

            if (queryEnd.HasValue)
            {
                end = DateTime.Parse(queryEnd.Value);
            }

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryUnmonitored.HasValue)
            {
                unmonitored = bool.Parse(queryUnmonitored.Value);
            }

            //if (queryPremiersOnly.HasValue)
            //{
            //    premiersOnly = bool.Parse(queryPremiersOnly.Value);
            //}
            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var movies   = _movieService.GetMoviesBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//radarr.video//Radarr//EN"
            };

            var calendarName = "Radarr Movies Calendar";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var movie in movies.OrderBy(v => v.Added))
            {
                if (tags.Any() && tags.None(movie.Tags.Contains))
                {
                    continue;
                }

                CreateEvent(calendar, movie, true);
                CreateEvent(calendar, movie, false);
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }
Esempio n. 5
0
        private Response GetCalendarFeed()
        {
            var pastDays    = 7;
            var futureDays  = 28;
            var start       = DateTime.Today.AddDays(-pastDays);
            var end         = DateTime.Today.AddDays(futureDays);
            var unmonitored = false;
            //var premiersOnly = false;
            var tags = new List <int>();

            // TODO: Remove start/end parameters in v3, they don't work well for iCal
            var queryStart       = Request.Query.Start;
            var queryEnd         = Request.Query.End;
            var queryPastDays    = Request.Query.PastDays;
            var queryFutureDays  = Request.Query.FutureDays;
            var queryUnmonitored = Request.Query.Unmonitored;
            // var queryPremiersOnly = Request.Query.PremiersOnly;
            var queryTags = Request.Query.Tags;

            if (queryStart.HasValue)
            {
                start = DateTime.Parse(queryStart.Value);
            }
            if (queryEnd.HasValue)
            {
                end = DateTime.Parse(queryEnd.Value);
            }

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryUnmonitored.HasValue)
            {
                unmonitored = bool.Parse(queryUnmonitored.Value);
            }

            //if (queryPremiersOnly.HasValue)
            //{
            //    premiersOnly = bool.Parse(queryPremiersOnly.Value);
            //}

            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var movies   = _movieService.GetMoviesBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//radarr.video//Bonarr//EN"
            };

            foreach (var movie in movies.OrderBy(v => v.Added))
            {
                if (tags.Any() && tags.None(movie.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <Event>();
                occurrence.Uid    = "NzbDrone_movie_" + movie.Id;
                occurrence.Status = movie.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;

                switch (movie.Status)
                {
                case MovieStatusType.PreDB:
                    if (movie.PhysicalRelease != null)
                    {
                        occurrence.Start = new CalDateTime(movie.PhysicalRelease.Value)
                        {
                            HasTime = true
                        };
                        occurrence.End = new CalDateTime(movie.PhysicalRelease.Value.AddMinutes(movie.Runtime))
                        {
                            HasTime = true
                        };
                    }
                    break;

                case MovieStatusType.InCinemas:
                    if (movie.InCinemas != null)
                    {
                        occurrence.Start = new CalDateTime(movie.InCinemas.Value)
                        {
                            HasTime = true
                        };
                        occurrence.End = new CalDateTime(movie.InCinemas.Value.AddMinutes(movie.Runtime))
                        {
                            HasTime = true
                        };
                    }
                    break;

                case MovieStatusType.Announced:
                    continue;     // no date

                default:
                    if (movie.PhysicalRelease != null)
                    {
                        occurrence.Start = new CalDateTime(movie.PhysicalRelease.Value)
                        {
                            HasTime = true
                        };
                        occurrence.End = new CalDateTime(movie.PhysicalRelease.Value.AddMinutes(movie.Runtime))
                        {
                            HasTime = true
                        };
                    }
                    break;
                }

                occurrence.Description = movie.Overview;
                occurrence.Categories  = new List <string>()
                {
                    movie.Studio
                };

                occurrence.Summary = $"{movie.Title}";
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }
Esempio n. 6
0
        private Response GetCalendarFeed()
        {
            var pastDays     = 7;
            var futureDays   = 28;
            var start        = DateTime.Today.AddDays(-pastDays);
            var end          = DateTime.Today.AddDays(futureDays);
            var unmonitored  = false;
            var premiersOnly = false;
            var asAllDay     = false;
            var tags         = new List <int>();

            // TODO: Remove start/end parameters in v3, they don't work well for iCal
            var queryStart        = Request.Query.Start;
            var queryEnd          = Request.Query.End;
            var queryPastDays     = Request.Query.PastDays;
            var queryFutureDays   = Request.Query.FutureDays;
            var queryUnmonitored  = Request.Query.Unmonitored;
            var queryPremiersOnly = Request.Query.PremiersOnly;
            var queryAsAllDay     = Request.Query.AsAllDay;
            var queryTags         = Request.Query.Tags;

            if (queryStart.HasValue)
            {
                start = DateTime.Parse(queryStart.Value);
            }
            if (queryEnd.HasValue)
            {
                end = DateTime.Parse(queryEnd.Value);
            }

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryUnmonitored.HasValue)
            {
                unmonitored = bool.Parse(queryUnmonitored.Value);
            }

            if (queryPremiersOnly.HasValue)
            {
                premiersOnly = bool.Parse(queryPremiersOnly.Value);
            }

            if (queryAsAllDay.HasValue)
            {
                asAllDay = bool.Parse(queryAsAllDay.Value);
            }

            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var episodes = _episodeService.EpisodesBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//sonarr.tv//Sonarr//EN"
            };



            foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value))
            {
                if (premiersOnly && (episode.SeasonNumber == 0 || episode.EpisodeNumber != 1))
                {
                    continue;
                }

                if (tags.Any() && tags.None(episode.Series.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <Event>();
                occurrence.Uid         = "NzbDrone_episode_" + episode.Id;
                occurrence.Status      = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
                occurrence.Description = episode.Overview;
                occurrence.Categories  = new List <string>()
                {
                    episode.Series.Network
                };

                if (asAllDay)
                {
                    occurrence.Start = new CalDateTime(episode.AirDateUtc.Value)
                    {
                        HasTime = false
                    };
                }
                else
                {
                    occurrence.Start = new CalDateTime(episode.AirDateUtc.Value)
                    {
                        HasTime = true
                    };
                    occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime))
                    {
                        HasTime = true
                    };
                }

                switch (episode.Series.SeriesType)
                {
                case SeriesTypes.Daily:
                    occurrence.Summary = $"{episode.Series.Title} - {episode.Title}";
                    break;

                default:
                    occurrence.Summary = $"{episode.Series.Title} - {episode.SeasonNumber}x{episode.EpisodeNumber:00} - {episode.Title}";
                    break;
                }
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }
Esempio n. 7
0
        private Response GetCalendarFeed()
        {
            var pastDays    = 7;
            var futureDays  = 28;
            var start       = DateTime.Today.AddDays(-pastDays);
            var end         = DateTime.Today.AddDays(futureDays);
            var unmonitored = Request.GetBooleanQueryParameter("unmonitored");
            var tags        = new List <int>();

            var queryPastDays   = Request.Query.PastDays;
            var queryFutureDays = Request.Query.FutureDays;
            var queryTags       = Request.Query.Tags;

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var albums   = _albumService.AlbumsBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//lidarr.audio//Lidarr//EN"
            };

            var calendarName = "Lidarr Music Schedule";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var album in albums.OrderBy(v => v.ReleaseDate.Value))
            {
                var artist = _artistService.GetArtist(album.ArtistId); // Temp fix TODO: Figure out why Album.Artist is not populated during AlbumsBetweenDates Query

                if (tags.Any() && tags.None(artist.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <Event>();
                occurrence.Uid = "NzbDrone_album_" + album.Id;
                //occurrence.Status = album.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
                //occurrence.Description = album.Overview;
                //occurrence.Categories = new List<string>() { album.Series.Network };

                occurrence.Start = new CalDateTime(album.ReleaseDate.Value.ToLocalTime())
                {
                    HasTime = false
                };

                occurrence.Summary = $"{artist.Name} - {album.Title}";
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }
Esempio n. 8
0
        private object GetCalendarFeed()
        {
            var pastDays    = 7;
            var futureDays  = 28;
            var start       = DateTime.Today.AddDays(-pastDays);
            var end         = DateTime.Today.AddDays(futureDays);
            var unmonitored = Request.GetBooleanQueryParameter("unmonitored");
            // There was a typo, recognize both the correct 'premieresOnly' and mistyped 'premiersOnly' boolean for background compat.
            var premieresOnly = Request.GetBooleanQueryParameter("premieresOnly") || Request.GetBooleanQueryParameter("premiersOnly");
            var asAllDay      = Request.GetBooleanQueryParameter("asAllDay");
            var tags          = new List <int>();

            var queryPastDays   = Request.Query.PastDays;
            var queryFutureDays = Request.Query.FutureDays;
            var queryTags       = Request.Query.Tags;

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var episodes = _episodeService.EpisodesBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//sonarr.tv//Sonarr//EN"
            };

            var calendarName = "Sonarr TV Schedule";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value))
            {
                if (premieresOnly && (episode.SeasonNumber == 0 || episode.EpisodeNumber != 1))
                {
                    continue;
                }

                if (tags.Any() && tags.None(episode.Series.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <Event>();
                occurrence.Uid         = "NzbDrone_episode_" + episode.Id;
                occurrence.Status      = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
                occurrence.Description = episode.Overview;
                occurrence.Categories  = new List <string>()
                {
                    episode.Series.Network
                };

                if (asAllDay)
                {
                    occurrence.Start = new CalDateTime(episode.AirDateUtc.Value.ToLocalTime())
                    {
                        HasTime = false
                    };
                }
                else
                {
                    occurrence.Start = new CalDateTime(episode.AirDateUtc.Value)
                    {
                        HasTime = true
                    };
                    occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime))
                    {
                        HasTime = true
                    };
                }

                switch (episode.Series.SeriesType)
                {
                case SeriesTypes.Daily:
                    occurrence.Summary = $"{episode.Series.Title} - {episode.Title}";
                    break;

                default:
                    occurrence.Summary = $"{episode.Series.Title} - {episode.SeasonNumber}x{episode.EpisodeNumber:00} - {episode.Title}";
                    break;
                }
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }