|
|
|
@ -2,7 +2,11 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using DDay.iCal;
|
|
|
|
|
using Ical.Net;
|
|
|
|
|
using Ical.Net.DataTypes;
|
|
|
|
|
using Ical.Net.Interfaces.Serialization;
|
|
|
|
|
using Ical.Net.Serialization;
|
|
|
|
|
using Ical.Net.Serialization.iCalendar.Factory;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using Nancy.Responses;
|
|
|
|
|
using NzbDrone.Core.Tags;
|
|
|
|
@ -22,6 +26,7 @@ namespace NzbDrone.Api.Calendar
|
|
|
|
|
_tagService = tagService;
|
|
|
|
|
|
|
|
|
|
Get["/NzbDrone.ics"] = options => GetCalendarFeed();
|
|
|
|
|
Get["/Sonarr.ics"] = options => GetCalendarFeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetCalendarFeed()
|
|
|
|
@ -75,7 +80,12 @@ namespace NzbDrone.Api.Calendar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var episodes = _episodeService.EpisodesBetweenDates(start, end, unmonitored);
|
|
|
|
|
var icalCalendar = new iCalendar();
|
|
|
|
|
var calendar = new Ical.Net.Calendar
|
|
|
|
|
{
|
|
|
|
|
ProductId = "-//sonarr.tv//Sonarr//EN"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value))
|
|
|
|
|
{
|
|
|
|
@ -89,28 +99,27 @@ namespace NzbDrone.Api.Calendar
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var occurrence = icalCalendar.Create<Event>();
|
|
|
|
|
occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString();
|
|
|
|
|
var occurrence = calendar.Create<Event>();
|
|
|
|
|
occurrence.Uid = "NzbDrone_episode_" + episode.Id;
|
|
|
|
|
occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
|
|
|
|
|
occurrence.Start = new iCalDateTime(episode.AirDateUtc.Value) { HasTime = true };
|
|
|
|
|
occurrence.End = new iCalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true };
|
|
|
|
|
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = true };
|
|
|
|
|
occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true };
|
|
|
|
|
occurrence.Description = episode.Overview;
|
|
|
|
|
occurrence.Categories = new List<string>() { episode.Series.Network };
|
|
|
|
|
|
|
|
|
|
switch (episode.Series.SeriesType)
|
|
|
|
|
{
|
|
|
|
|
case SeriesTypes.Daily:
|
|
|
|
|
occurrence.Summary = string.Format("{0} - {1}", episode.Series.Title, episode.Title);
|
|
|
|
|
occurrence.Summary = $"{episode.Series.Title} - {episode.Title}";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
occurrence.Summary = string.Format("{0} - {1}x{2:00} - {3}", episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber, episode.Title);
|
|
|
|
|
occurrence.Summary =$"{episode.Series.Title} - {episode.SeasonNumber}x{episode.EpisodeNumber:00} - {episode.Title}";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var serializer = new DDay.iCal.Serialization.iCalendar.SerializerFactory().Build(icalCalendar.GetType(), new DDay.iCal.Serialization.SerializationContext()) as DDay.iCal.Serialization.IStringSerializer;
|
|
|
|
|
var icalendar = serializer.SerializeToString(icalCalendar);
|
|
|
|
|
var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
|
|
|
|
|
var icalendar = serializer.SerializeToString(calendar);
|
|
|
|
|
|
|
|
|
|
return new TextResponse(icalendar, "text/calendar");
|
|
|
|
|
}
|
|
|
|
|