Added a new cacher job to cache all episodes in Plex.
pull/470/head
tidusjar 8 years ago
parent 605f6f18fb
commit 14fddfc118

@ -1,45 +1,47 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IPlexApi.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using PlexRequests.Api.Models;
using PlexRequests.Api.Models.Plex;
namespace PlexRequests.Api.Interfaces
{
public interface IPlexApi
{
PlexAuthentication SignIn(string username, string password);
PlexFriends GetUsers(string authToken);
PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost);
PlexStatus GetStatus(string authToken, Uri uri);
PlexAccount GetAccount(string authToken);
PlexLibraries GetLibrarySections(string authToken, Uri plexFullHost);
PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId);
PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId);
}
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IPlexApi.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using PlexRequests.Api.Models;
using PlexRequests.Api.Models.Plex;
namespace PlexRequests.Api.Interfaces
{
public interface IPlexApi
{
PlexAuthentication SignIn(string username, string password);
PlexFriends GetUsers(string authToken);
PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost);
PlexStatus GetStatus(string authToken, Uri uri);
PlexAccount GetAccount(string authToken);
PlexLibraries GetLibrarySections(string authToken, Uri plexFullHost);
PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId);
PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId);
PlexEpisodeMetadata GetEpisodeMetaData(string authToken, Uri host, string ratingKey);
PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount);
}
}

@ -0,0 +1,81 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexEpisodeMetadata.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Api.Models.Plex
{
using System.Xml.Serialization;
using System.Collections.Generic;
[XmlRoot(ElementName = "MediaContainer")]
public class PlexEpisodeMetadata
{
[XmlElement(ElementName = "Video")]
public List<Video> Video { get; set; }
[XmlAttribute(AttributeName = "size")]
public string Size { get; set; }
[XmlAttribute(AttributeName = "allowSync")]
public string AllowSync { get; set; }
[XmlAttribute(AttributeName = "art")]
public string Art { get; set; }
[XmlAttribute(AttributeName = "banner")]
public string Banner { get; set; }
[XmlAttribute(AttributeName = "identifier")]
public string Identifier { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "librarySectionID")]
public string LibrarySectionID { get; set; }
[XmlAttribute(AttributeName = "librarySectionTitle")]
public string LibrarySectionTitle { get; set; }
[XmlAttribute(AttributeName = "librarySectionUUID")]
public string LibrarySectionUUID { get; set; }
[XmlAttribute(AttributeName = "mediaTagPrefix")]
public string MediaTagPrefix { get; set; }
[XmlAttribute(AttributeName = "mediaTagVersion")]
public string MediaTagVersion { get; set; }
[XmlAttribute(AttributeName = "mixedParents")]
public string MixedParents { get; set; }
[XmlAttribute(AttributeName = "nocache")]
public string Nocache { get; set; }
[XmlAttribute(AttributeName = "parentIndex")]
public string ParentIndex { get; set; }
[XmlAttribute(AttributeName = "parentTitle")]
public string ParentTitle { get; set; }
[XmlAttribute(AttributeName = "parentYear")]
public string ParentYear { get; set; }
[XmlAttribute(AttributeName = "theme")]
public string Theme { get; set; }
[XmlAttribute(AttributeName = "title1")]
public string Title1 { get; set; }
[XmlAttribute(AttributeName = "title2")]
public string Title2 { get; set; }
[XmlAttribute(AttributeName = "viewGroup")]
public string ViewGroup { get; set; }
[XmlAttribute(AttributeName = "viewMode")]
public string ViewMode { get; set; }
}
}

@ -1,35 +1,35 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexType.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Services
{
public enum PlexMediaType
{
Movie,
Show,
Music // double check this one
}
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexType.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Services
{
public enum PlexMediaType
{
Movie,
Show,
Artist
}
}

@ -1,336 +1,338 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexSearch.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Collections.Generic;
using System.Xml.Serialization;
namespace PlexRequests.Api.Models.Plex
{
[XmlRoot(ElementName = "Part")]
public class Part
{
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "file")]
public string File { get; set; }
[XmlAttribute(AttributeName = "size")]
public string Size { get; set; }
[XmlAttribute(AttributeName = "audioProfile")]
public string AudioProfile { get; set; }
[XmlAttribute(AttributeName = "container")]
public string Container { get; set; }
[XmlAttribute(AttributeName = "videoProfile")]
public string VideoProfile { get; set; }
[XmlAttribute(AttributeName = "has64bitOffsets")]
public string Has64bitOffsets { get; set; }
[XmlAttribute(AttributeName = "hasChapterTextStream")]
public string HasChapterTextStream { get; set; }
[XmlAttribute(AttributeName = "optimizedForStreaming")]
public string OptimizedForStreaming { get; set; }
}
[XmlRoot(ElementName = "Media")]
public class Media
{
[XmlElement(ElementName = "Part")]
public Part Part { get; set; }
[XmlAttribute(AttributeName = "videoResolution")]
public string VideoResolution { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "bitrate")]
public string Bitrate { get; set; }
[XmlAttribute(AttributeName = "width")]
public string Width { get; set; }
[XmlAttribute(AttributeName = "height")]
public string Height { get; set; }
[XmlAttribute(AttributeName = "aspectRatio")]
public string AspectRatio { get; set; }
[XmlAttribute(AttributeName = "audioChannels")]
public string AudioChannels { get; set; }
[XmlAttribute(AttributeName = "audioCodec")]
public string AudioCodec { get; set; }
[XmlAttribute(AttributeName = "videoCodec")]
public string VideoCodec { get; set; }
[XmlAttribute(AttributeName = "container")]
public string Container { get; set; }
[XmlAttribute(AttributeName = "videoFrameRate")]
public string VideoFrameRate { get; set; }
[XmlAttribute(AttributeName = "audioProfile")]
public string AudioProfile { get; set; }
[XmlAttribute(AttributeName = "videoProfile")]
public string VideoProfile { get; set; }
[XmlAttribute(AttributeName = "optimizedForStreaming")]
public string OptimizedForStreaming { get; set; }
[XmlAttribute(AttributeName = "has64bitOffsets")]
public string Has64bitOffsets { get; set; }
}
[XmlRoot(ElementName = "Genre")]
public class Genre
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Writer")]
public class Writer
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Director")]
public class Director
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Country")]
public class Country
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Role")]
public class Role
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Video")]
public class Video
{
public string ProviderId { get; set; }
[XmlAttribute(AttributeName = "guid")]
public string Guid { get; set; }
[XmlElement(ElementName = "Media")]
public List<Media> Media { get; set; }
[XmlElement(ElementName = "Genre")]
public List<Genre> Genre { get; set; }
[XmlElement(ElementName = "Writer")]
public List<Writer> Writer { get; set; }
[XmlElement(ElementName = "Director")]
public Director Director { get; set; }
[XmlElement(ElementName = "Country")]
public Country Country { get; set; }
[XmlElement(ElementName = "Role")]
public List<Role> Role { get; set; }
[XmlAttribute(AttributeName = "allowSync")]
public string AllowSync { get; set; }
[XmlAttribute(AttributeName = "librarySectionID")]
public string LibrarySectionID { get; set; }
[XmlAttribute(AttributeName = "librarySectionTitle")]
public string LibrarySectionTitle { get; set; }
[XmlAttribute(AttributeName = "librarySectionUUID")]
public string LibrarySectionUUID { get; set; }
[XmlAttribute(AttributeName = "personal")]
public string Personal { get; set; }
[XmlAttribute(AttributeName = "sourceTitle")]
public string SourceTitle { get; set; }
[XmlAttribute(AttributeName = "ratingKey")]
public string RatingKey { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "studio")]
public string Studio { get; set; }
[XmlAttribute(AttributeName = "type")]
public string Type { get; set; }
[XmlAttribute(AttributeName = "title")]
public string Title { get; set; }
[XmlAttribute(AttributeName = "contentRating")]
public string ContentRating { get; set; }
[XmlAttribute(AttributeName = "summary")]
public string Summary { get; set; }
[XmlAttribute(AttributeName = "rating")]
public string Rating { get; set; }
[XmlAttribute(AttributeName = "audienceRating")]
public string AudienceRating { get; set; }
[XmlAttribute(AttributeName = "year")]
public string Year { get; set; }
[XmlAttribute(AttributeName = "tagline")]
public string Tagline { get; set; }
[XmlAttribute(AttributeName = "thumb")]
public string Thumb { get; set; }
[XmlAttribute(AttributeName = "art")]
public string Art { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "originallyAvailableAt")]
public string OriginallyAvailableAt { get; set; }
[XmlAttribute(AttributeName = "addedAt")]
public string AddedAt { get; set; }
[XmlAttribute(AttributeName = "updatedAt")]
public string UpdatedAt { get; set; }
[XmlAttribute(AttributeName = "audienceRatingImage")]
public string AudienceRatingImage { get; set; }
[XmlAttribute(AttributeName = "chapterSource")]
public string ChapterSource { get; set; }
[XmlAttribute(AttributeName = "ratingImage")]
public string RatingImage { get; set; }
[XmlAttribute(AttributeName = "titleSort")]
public string TitleSort { get; set; }
[XmlAttribute(AttributeName = "parentRatingKey")]
public string ParentRatingKey { get; set; }
[XmlAttribute(AttributeName = "grandparentRatingKey")]
public string GrandparentRatingKey { get; set; }
[XmlAttribute(AttributeName = "grandparentKey")]
public string GrandparentKey { get; set; }
[XmlAttribute(AttributeName = "parentKey")]
public string ParentKey { get; set; }
[XmlAttribute(AttributeName = "grandparentTitle")]
public string GrandparentTitle { get; set; }
[XmlAttribute(AttributeName = "index")]
public string Index { get; set; }
[XmlAttribute(AttributeName = "parentIndex")]
public string ParentIndex { get; set; }
[XmlAttribute(AttributeName = "parentThumb")]
public string ParentThumb { get; set; }
[XmlAttribute(AttributeName = "grandparentThumb")]
public string GrandparentThumb { get; set; }
[XmlAttribute(AttributeName = "grandparentArt")]
public string GrandparentArt { get; set; }
[XmlAttribute(AttributeName = "viewCount")]
public string ViewCount { get; set; }
[XmlAttribute(AttributeName = "lastViewedAt")]
public string LastViewedAt { get; set; }
[XmlAttribute(AttributeName = "grandparentTheme")]
public string GrandparentTheme { get; set; }
}
[XmlRoot(ElementName = "Provider")]
public class Provider
{
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "title")]
public string Title { get; set; }
[XmlAttribute(AttributeName = "type")]
public string Type { get; set; }
}
[XmlRoot(ElementName = "Directory")]
public class Directory1
{
public string ProviderId { get; set; }
[XmlAttribute(AttributeName = "guid")]
public string Guid { get; set; }
[XmlElement(ElementName = "Genre")]
public List<Genre> Genre { get; set; }
[XmlElement(ElementName = "Role")]
public List<Role> Role { get; set; }
[XmlAttribute(AttributeName = "allowSync")]
public string AllowSync { get; set; }
[XmlAttribute(AttributeName = "librarySectionID")]
public string LibrarySectionID { get; set; }
[XmlAttribute(AttributeName = "librarySectionTitle")]
public string LibrarySectionTitle { get; set; }
[XmlAttribute(AttributeName = "librarySectionUUID")]
public string LibrarySectionUUID { get; set; }
[XmlAttribute(AttributeName = "personal")]
public string Personal { get; set; }
[XmlAttribute(AttributeName = "sourceTitle")]
public string SourceTitle { get; set; }
[XmlAttribute(AttributeName = "ratingKey")]
public string RatingKey { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "studio")]
public string Studio { get; set; }
[XmlAttribute(AttributeName = "type")]
public string Type { get; set; }
[XmlAttribute(AttributeName = "title")]
public string Title { get; set; }
[XmlAttribute(AttributeName = "contentRating")]
public string ContentRating { get; set; }
[XmlAttribute(AttributeName = "summary")]
public string Summary { get; set; }
[XmlAttribute(AttributeName = "index")]
public string Index { get; set; }
[XmlAttribute(AttributeName = "rating")]
public string Rating { get; set; }
[XmlAttribute(AttributeName = "viewCount")]
public string ViewCount { get; set; }
[XmlAttribute(AttributeName = "lastViewedAt")]
public string LastViewedAt { get; set; }
[XmlAttribute(AttributeName = "year")]
public string Year { get; set; }
[XmlAttribute(AttributeName = "thumb")]
public string Thumb { get; set; }
[XmlAttribute(AttributeName = "art")]
public string Art { get; set; }
[XmlAttribute(AttributeName = "banner")]
public string Banner { get; set; }
[XmlAttribute(AttributeName = "theme")]
public string Theme { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "originallyAvailableAt")]
public string OriginallyAvailableAt { get; set; }
[XmlAttribute(AttributeName = "leafCount")]
public string LeafCount { get; set; }
[XmlAttribute(AttributeName = "viewedLeafCount")]
public string ViewedLeafCount { get; set; }
[XmlAttribute(AttributeName = "childCount")]
public string ChildCount { get; set; }
[XmlAttribute(AttributeName = "addedAt")]
public string AddedAt { get; set; }
[XmlAttribute(AttributeName = "updatedAt")]
public string UpdatedAt { get; set; }
[XmlAttribute(AttributeName = "parentTitle")]
public string ParentTitle { get; set; }
}
[XmlRoot(ElementName = "MediaContainer")]
public class PlexSearch
{
[XmlElement(ElementName = "Directory")]
public List<Directory1> Directory { get; set; }
[XmlElement(ElementName = "Video")]
public List<Video> Video { get; set; }
[XmlElement(ElementName = "Provider")]
public List<Provider> Provider { get; set; }
[XmlAttribute(AttributeName = "size")]
public string Size { get; set; }
[XmlAttribute(AttributeName = "identifier")]
public string Identifier { get; set; }
[XmlAttribute(AttributeName = "mediaTagPrefix")]
public string MediaTagPrefix { get; set; }
[XmlAttribute(AttributeName = "mediaTagVersion")]
public string MediaTagVersion { get; set; }
}
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexSearch.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Collections.Generic;
using System.Xml.Serialization;
namespace PlexRequests.Api.Models.Plex
{
[XmlRoot(ElementName = "Part")]
public class Part
{
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "file")]
public string File { get; set; }
[XmlAttribute(AttributeName = "size")]
public string Size { get; set; }
[XmlAttribute(AttributeName = "audioProfile")]
public string AudioProfile { get; set; }
[XmlAttribute(AttributeName = "container")]
public string Container { get; set; }
[XmlAttribute(AttributeName = "videoProfile")]
public string VideoProfile { get; set; }
[XmlAttribute(AttributeName = "has64bitOffsets")]
public string Has64bitOffsets { get; set; }
[XmlAttribute(AttributeName = "hasChapterTextStream")]
public string HasChapterTextStream { get; set; }
[XmlAttribute(AttributeName = "optimizedForStreaming")]
public string OptimizedForStreaming { get; set; }
}
[XmlRoot(ElementName = "Media")]
public class Media
{
[XmlElement(ElementName = "Part")]
public Part Part { get; set; }
[XmlAttribute(AttributeName = "videoResolution")]
public string VideoResolution { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "bitrate")]
public string Bitrate { get; set; }
[XmlAttribute(AttributeName = "width")]
public string Width { get; set; }
[XmlAttribute(AttributeName = "height")]
public string Height { get; set; }
[XmlAttribute(AttributeName = "aspectRatio")]
public string AspectRatio { get; set; }
[XmlAttribute(AttributeName = "audioChannels")]
public string AudioChannels { get; set; }
[XmlAttribute(AttributeName = "audioCodec")]
public string AudioCodec { get; set; }
[XmlAttribute(AttributeName = "videoCodec")]
public string VideoCodec { get; set; }
[XmlAttribute(AttributeName = "container")]
public string Container { get; set; }
[XmlAttribute(AttributeName = "videoFrameRate")]
public string VideoFrameRate { get; set; }
[XmlAttribute(AttributeName = "audioProfile")]
public string AudioProfile { get; set; }
[XmlAttribute(AttributeName = "videoProfile")]
public string VideoProfile { get; set; }
[XmlAttribute(AttributeName = "optimizedForStreaming")]
public string OptimizedForStreaming { get; set; }
[XmlAttribute(AttributeName = "has64bitOffsets")]
public string Has64bitOffsets { get; set; }
}
[XmlRoot(ElementName = "Genre")]
public class Genre
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Writer")]
public class Writer
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Director")]
public class Director
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Country")]
public class Country
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Role")]
public class Role
{
[XmlAttribute(AttributeName = "tag")]
public string Tag { get; set; }
}
[XmlRoot(ElementName = "Video")]
public class Video
{
public string ProviderId { get; set; }
[XmlAttribute(AttributeName = "guid")]
public string Guid { get; set; }
[XmlElement(ElementName = "Media")]
public List<Media> Media { get; set; }
[XmlElement(ElementName = "Genre")]
public List<Genre> Genre { get; set; }
[XmlElement(ElementName = "Writer")]
public List<Writer> Writer { get; set; }
[XmlElement(ElementName = "Director")]
public Director Director { get; set; }
[XmlElement(ElementName = "Country")]
public Country Country { get; set; }
[XmlElement(ElementName = "Role")]
public List<Role> Role { get; set; }
[XmlAttribute(AttributeName = "allowSync")]
public string AllowSync { get; set; }
[XmlAttribute(AttributeName = "librarySectionID")]
public string LibrarySectionID { get; set; }
[XmlAttribute(AttributeName = "librarySectionTitle")]
public string LibrarySectionTitle { get; set; }
[XmlAttribute(AttributeName = "librarySectionUUID")]
public string LibrarySectionUUID { get; set; }
[XmlAttribute(AttributeName = "personal")]
public string Personal { get; set; }
[XmlAttribute(AttributeName = "sourceTitle")]
public string SourceTitle { get; set; }
[XmlAttribute(AttributeName = "ratingKey")]
public string RatingKey { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "studio")]
public string Studio { get; set; }
[XmlAttribute(AttributeName = "type")]
public string Type { get; set; }
[XmlAttribute(AttributeName = "title")]
public string Title { get; set; }
[XmlAttribute(AttributeName = "contentRating")]
public string ContentRating { get; set; }
[XmlAttribute(AttributeName = "summary")]
public string Summary { get; set; }
[XmlAttribute(AttributeName = "rating")]
public string Rating { get; set; }
[XmlAttribute(AttributeName = "audienceRating")]
public string AudienceRating { get; set; }
[XmlAttribute(AttributeName = "year")]
public string Year { get; set; }
[XmlAttribute(AttributeName = "tagline")]
public string Tagline { get; set; }
[XmlAttribute(AttributeName = "thumb")]
public string Thumb { get; set; }
[XmlAttribute(AttributeName = "art")]
public string Art { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "originallyAvailableAt")]
public string OriginallyAvailableAt { get; set; }
[XmlAttribute(AttributeName = "addedAt")]
public string AddedAt { get; set; }
[XmlAttribute(AttributeName = "updatedAt")]
public string UpdatedAt { get; set; }
[XmlAttribute(AttributeName = "audienceRatingImage")]
public string AudienceRatingImage { get; set; }
[XmlAttribute(AttributeName = "chapterSource")]
public string ChapterSource { get; set; }
[XmlAttribute(AttributeName = "ratingImage")]
public string RatingImage { get; set; }
[XmlAttribute(AttributeName = "titleSort")]
public string TitleSort { get; set; }
[XmlAttribute(AttributeName = "parentRatingKey")]
public string ParentRatingKey { get; set; }
[XmlAttribute(AttributeName = "grandparentRatingKey")]
public string GrandparentRatingKey { get; set; }
[XmlAttribute(AttributeName = "grandparentKey")]
public string GrandparentKey { get; set; }
[XmlAttribute(AttributeName = "parentKey")]
public string ParentKey { get; set; }
[XmlAttribute(AttributeName = "grandparentTitle")]
public string GrandparentTitle { get; set; }
[XmlAttribute(AttributeName = "index")]
public string Index { get; set; }
[XmlAttribute(AttributeName = "parentIndex")]
public string ParentIndex { get; set; }
[XmlAttribute(AttributeName = "parentThumb")]
public string ParentThumb { get; set; }
[XmlAttribute(AttributeName = "grandparentThumb")]
public string GrandparentThumb { get; set; }
[XmlAttribute(AttributeName = "grandparentArt")]
public string GrandparentArt { get; set; }
[XmlAttribute(AttributeName = "viewCount")]
public string ViewCount { get; set; }
[XmlAttribute(AttributeName = "lastViewedAt")]
public string LastViewedAt { get; set; }
[XmlAttribute(AttributeName = "grandparentTheme")]
public string GrandparentTheme { get; set; }
}
[XmlRoot(ElementName = "Provider")]
public class Provider
{
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "title")]
public string Title { get; set; }
[XmlAttribute(AttributeName = "type")]
public string Type { get; set; }
}
[XmlRoot(ElementName = "Directory")]
public class Directory1
{
public string ProviderId { get; set; }
[XmlAttribute(AttributeName = "guid")]
public string Guid { get; set; }
[XmlElement(ElementName = "Genre")]
public List<Genre> Genre { get; set; }
[XmlElement(ElementName = "Role")]
public List<Role> Role { get; set; }
[XmlAttribute(AttributeName = "allowSync")]
public string AllowSync { get; set; }
[XmlAttribute(AttributeName = "librarySectionID")]
public string LibrarySectionID { get; set; }
[XmlAttribute(AttributeName = "librarySectionTitle")]
public string LibrarySectionTitle { get; set; }
[XmlAttribute(AttributeName = "librarySectionUUID")]
public string LibrarySectionUUID { get; set; }
[XmlAttribute(AttributeName = "personal")]
public string Personal { get; set; }
[XmlAttribute(AttributeName = "sourceTitle")]
public string SourceTitle { get; set; }
[XmlAttribute(AttributeName = "ratingKey")]
public string RatingKey { get; set; }
[XmlAttribute(AttributeName = "key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "studio")]
public string Studio { get; set; }
[XmlAttribute(AttributeName = "type")]
public string Type { get; set; }
[XmlAttribute(AttributeName = "title")]
public string Title { get; set; }
[XmlAttribute(AttributeName = "contentRating")]
public string ContentRating { get; set; }
[XmlAttribute(AttributeName = "summary")]
public string Summary { get; set; }
[XmlAttribute(AttributeName = "index")]
public string Index { get; set; }
[XmlAttribute(AttributeName = "rating")]
public string Rating { get; set; }
[XmlAttribute(AttributeName = "viewCount")]
public string ViewCount { get; set; }
[XmlAttribute(AttributeName = "lastViewedAt")]
public string LastViewedAt { get; set; }
[XmlAttribute(AttributeName = "year")]
public string Year { get; set; }
[XmlAttribute(AttributeName = "thumb")]
public string Thumb { get; set; }
[XmlAttribute(AttributeName = "art")]
public string Art { get; set; }
[XmlAttribute(AttributeName = "banner")]
public string Banner { get; set; }
[XmlAttribute(AttributeName = "theme")]
public string Theme { get; set; }
[XmlAttribute(AttributeName = "duration")]
public string Duration { get; set; }
[XmlAttribute(AttributeName = "originallyAvailableAt")]
public string OriginallyAvailableAt { get; set; }
[XmlAttribute(AttributeName = "leafCount")]
public string LeafCount { get; set; }
[XmlAttribute(AttributeName = "viewedLeafCount")]
public string ViewedLeafCount { get; set; }
[XmlAttribute(AttributeName = "childCount")]
public string ChildCount { get; set; }
[XmlAttribute(AttributeName = "addedAt")]
public string AddedAt { get; set; }
[XmlAttribute(AttributeName = "updatedAt")]
public string UpdatedAt { get; set; }
[XmlAttribute(AttributeName = "parentTitle")]
public string ParentTitle { get; set; }
}
[XmlRoot(ElementName = "MediaContainer")]
public class PlexSearch
{
[XmlElement(ElementName = "Directory")]
public List<Directory1> Directory { get; set; }
[XmlElement(ElementName = "Video")]
public List<Video> Video { get; set; }
[XmlElement(ElementName = "Provider")]
public List<Provider> Provider { get; set; }
[XmlAttribute(AttributeName = "size")]
public string Size { get; set; }
[XmlAttribute(AttributeName = "totalSize")]
public string TotalSize { get; set; }
[XmlAttribute(AttributeName = "identifier")]
public string Identifier { get; set; }
[XmlAttribute(AttributeName = "mediaTagPrefix")]
public string MediaTagPrefix { get; set; }
[XmlAttribute(AttributeName = "mediaTagVersion")]
public string MediaTagVersion { get; set; }
}
}

@ -62,6 +62,7 @@
<Compile Include="Notifications\SlackNotificationBody.cs" />
<Compile Include="Plex\PlexAccount.cs" />
<Compile Include="Plex\PlexAuthentication.cs" />
<Compile Include="Plex\PlexEpisodeMetadata.cs" />
<Compile Include="Plex\PlexError.cs" />
<Compile Include="Plex\PlexFriends.cs" />
<Compile Include="Plex\PlexLibraries.cs" />

@ -168,7 +168,7 @@ namespace PlexRequests.Api
try
{
var lib = RetryHandler.Execute<PlexLibraries>(() => Api.ExecuteXml<PlexLibraries> (request, plexFullHost),
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexLibraries> (request, plexFullHost),
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrarySections for Plex, Retrying {0}", timespan), new TimeSpan[] {
TimeSpan.FromSeconds (5),
TimeSpan.FromSeconds(10),
@ -197,7 +197,7 @@ namespace PlexRequests.Api
try
{
var lib = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexSearch> (request, plexFullHost),
(exception, timespan) => Log.Error (exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan), new TimeSpan[] {
TimeSpan.FromSeconds (5),
TimeSpan.FromSeconds(10),
@ -213,6 +213,65 @@ namespace PlexRequests.Api
}
}
public PlexEpisodeMetadata GetEpisodeMetaData(string authToken, Uri host, string ratingKey)
{
//192.168.1.69:32400/library/metadata/3662/allLeaves
// The metadata ratingkey should be in the Cache
// Search for it and then call the above with the Directory.RatingKey
// THEN! We need the episode metadata using result.Vide.Key ("/library/metadata/3664")
// We then have the GUID which contains the TVDB ID plus the season and episode number: guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
var request = new RestRequest
{
Method = Method.GET,
Resource = "/library/metadata/{ratingKey}/allLeaves"
};
request.AddUrlSegment("ratingKey", ratingKey);
AddHeaders(ref request, authToken);
try
{
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexEpisodeMetadata>(request, host),
(exception, timespan) => Log.Error(exception, "Exception when calling GetEpisodeMetaData for Plex, Retrying {0}", timespan));
return lib;
}
catch (Exception e)
{
Log.Error(e, "There has been a API Exception when attempting to get GetEpisodeMetaData");
return new PlexEpisodeMetadata();
}
}
public PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount)
{
var request = new RestRequest
{
Method = Method.GET,
Resource = "/library/sections/{section}/all"
};
request.AddQueryParameter("type", 4.ToString());
request.AddQueryParameter("X-Plex-Container-Start", startPage.ToString());
request.AddQueryParameter("X-Plex-Container-Size", returnCount.ToString());
request.AddUrlSegment("section", section);
AddHeaders(ref request, authToken);
try
{
var lib = RetryHandler.Execute(() => Api.ExecuteXml<PlexSearch>(request, host),
(exception, timespan) => Log.Error(exception, "Exception when calling GetAllEpisodes for Plex, Retrying {0}", timespan));
return lib;
}
catch (Exception e)
{
Log.Error(e, "There has been a API Exception when attempting to get GetAllEpisodes");
return new PlexSearch();
}
}
public PlexMetadata GetMetadata(string authToken, Uri plexFullHost, string itemId)
{
var request = new RestRequest

@ -1,53 +1,54 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CacheKeys.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Core
{
public class CacheKeys
{
public struct TimeFrameMinutes
{
public const int SchedulerCaching = 60;
}
public const string PlexLibaries = nameof(PlexLibaries);
public const string TvDbToken = nameof(TvDbToken);
public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles);
public const string SonarrQueued = nameof(SonarrQueued);
public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles);
public const string SickRageQueued = nameof(SickRageQueued);
public const string CouchPotatoQualityProfiles = nameof(CouchPotatoQualityProfiles);
public const string CouchPotatoQueued = nameof(CouchPotatoQueued);
public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings);
public const string LastestProductVersion = nameof(LastestProductVersion);
}
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CacheKeys.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Core
{
public class CacheKeys
{
public struct TimeFrameMinutes
{
public const int SchedulerCaching = 60;
}
public const string PlexLibaries = nameof(PlexLibaries);
public const string PlexEpisodes = nameof(PlexEpisodes);
public const string TvDbToken = nameof(TvDbToken);
public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles);
public const string SonarrQueued = nameof(SonarrQueued);
public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles);
public const string SickRageQueued = nameof(SickRageQueued);
public const string CouchPotatoQualityProfiles = nameof(CouchPotatoQualityProfiles);
public const string CouchPotatoQueued = nameof(CouchPotatoQueued);
public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings);
public const string LastestProductVersion = nameof(LastestProductVersion);
}
}

@ -37,6 +37,7 @@ namespace PlexRequests.Core.SettingModels
StoreBackup = 24;
StoreCleanup = 24;
UserRequestLimitResetter = 12;
PlexEpisodeCacher = 20;
}
public int PlexAvailabilityChecker { get; set; }
public int SickRageCacher { get; set; }
@ -45,5 +46,6 @@ namespace PlexRequests.Core.SettingModels
public int StoreBackup { get; set; }
public int StoreCleanup { get; set; }
public int UserRequestLimitResetter { get; set; }
public int PlexEpisodeCacher { get; set; }
}
}

@ -36,11 +36,25 @@ namespace PlexRequests.Helpers.Tests
public class PlexHelperTests
{
[TestCaseSource(nameof(PlexGuids))]
public string CreateUriWithSubDir(string guid)
public string GetProviderId(string guid)
{
return PlexHelper.GetProviderIdFromPlexGuid(guid);
}
[TestCaseSource(nameof(PlexTvEpisodeGuids))]
public List<string> GetEpisodeAndSeasons(string guid)
{
var ep = PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(guid);
var list = new List<string>
{
ep.ProviderId,
ep.SeasonNumber.ToString(),
ep.EpisodeNumber.ToString(),
};
return list;
}
private static IEnumerable<TestCaseData> PlexGuids
{
@ -56,6 +70,17 @@ namespace PlexRequests.Helpers.Tests
}
}
private static IEnumerable<TestCaseData> PlexTvEpisodeGuids
{
get
{
yield return new TestCaseData("com.plexapp.agents.thetvdb://269586/2/8?lang=en").Returns(new List<string> { "269586","2","8" })
.SetName("Valid");
yield return new TestCaseData("com.plexapp.agents.thetvdb://abc/112/388?lang=en").Returns(new List<string> { "abc", "112","388" })
.SetName("Valid Long");
}
}
}
}

@ -43,5 +43,29 @@ namespace PlexRequests.Helpers
}
return string.Empty;
}
public static EpisodeModelHelper GetSeasonsAndEpisodesFromPlexGuid(string guid)
{
var ep = new EpisodeModelHelper();
//guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
if (string.IsNullOrEmpty(guid))
return null;
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
if (guidSplit.Length > 2)
{
ep.ProviderId = guidSplit[1];
ep.SeasonNumber = int.Parse(guidSplit[2]);
ep.EpisodeNumber = int.Parse(guidSplit[3]);
}
return ep;
}
}
public class EpisodeModelHelper
{
public string ProviderId { get; set; }
public int SeasonNumber { get; set; }
public int EpisodeNumber { get; set; }
}
}

@ -1,42 +1,43 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IAvailabilityChecker.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using PlexRequests.Services.Models;
using System.Collections.Generic;
namespace PlexRequests.Services.Interfaces
{
public interface IAvailabilityChecker
{
void CheckAndUpdateAll();
List<PlexMovie> GetPlexMovies();
bool IsMovieAvailable(PlexMovie[] plexMovies, string title, string year, string providerId = null);
List<PlexTvShow> GetPlexTvShows();
bool IsTvShowAvailable(PlexTvShow[] plexShows, string title, string year, string providerId = null);
List<PlexAlbum> GetPlexAlbums();
bool IsAlbumAvailable(PlexAlbum[] plexAlbums, string title, string year, string artist);
}
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IAvailabilityChecker.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using PlexRequests.Services.Models;
using System.Collections.Generic;
namespace PlexRequests.Services.Interfaces
{
public interface IAvailabilityChecker
{
void CheckAndUpdateAll();
List<PlexMovie> GetPlexMovies();
bool IsMovieAvailable(PlexMovie[] plexMovies, string title, string year, string providerId = null);
List<PlexTvShow> GetPlexTvShows();
bool IsTvShowAvailable(PlexTvShow[] plexShows, string title, string year, string providerId = null);
List<PlexAlbum> GetPlexAlbums();
bool IsAlbumAvailable(PlexAlbum[] plexAlbums, string title, string year, string artist);
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
}
}

@ -35,5 +35,6 @@ namespace PlexRequests.Services.Jobs
public const string PlexChecker = "Plex Availability Cacher";
public const string StoreCleanup = "Database Cleanup";
public const string RequestLimitReset = "Request Limit Reset";
public const string EpisodeCacher = "Request Limit Reset";
}
}

@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
@ -238,6 +239,19 @@ namespace PlexRequests.Services.Jobs
return false;
}
public bool IsEpisodeAvailable(string theTvDbId, int season, int episode)
{
var episodes = Cache.Get<List<PlexEpisodeModel>>(CacheKeys.PlexEpisodes);
foreach (var result in episodes)
{
if (result.Episodes.ProviderId.Equals(theTvDbId) && result.Episodes.EpisodeNumber == episode && result.Episodes.SeasonNumber == season)
{
return true;
}
}
return false;
}
public List<PlexAlbum> GetPlexAlbums()
{
var albums = new List<PlexAlbum>();
@ -246,7 +260,7 @@ namespace PlexRequests.Services.Jobs
{
var albumLibs = libs.Where(x =>
x.Directory.Any(y =>
y.Type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)
y.Type.Equals(PlexMediaType.Artist.ToString(), StringComparison.CurrentCultureIgnoreCase)
)
).ToArray();

@ -0,0 +1,136 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexEpisodeCacher.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Plex;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Services.Interfaces;
using PlexRequests.Services.Models;
using Quartz;
namespace PlexRequests.Services.Jobs
{
public class PlexEpisodeCacher : IJob
{
public PlexEpisodeCacher(ISettingsService<PlexSettings> plexSettings, IPlexApi plex, ICacheProvider cache,
IJobRecord rec)
{
Plex = plexSettings;
PlexApi = plex;
Cache = cache;
Job = rec;
}
private ISettingsService<PlexSettings> Plex { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private IPlexApi PlexApi { get; }
private ICacheProvider Cache { get; }
private IJobRecord Job { get; }
private const int ResultCount = 25;
public void CacheEpisodes()
{
var results = new List<PlexSearch>();
var settings = Plex.GetSettings();
var sections = PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri);
var tvSection = sections.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase));
var tvSectionId = tvSection?.Key;
var currentPosition = 0;
int totalSize;
var episodes = PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount);
results.Add(episodes);
int.TryParse(episodes.TotalSize, out totalSize);
currentPosition += ResultCount;
while (currentPosition < totalSize)
{
results.Add(PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount));
currentPosition += ResultCount;
}
var episodesModel = new List<PlexEpisodeModel>();
var metadataList = new List<PlexEpisodeMetadata>();
foreach (var r in results)
{
foreach (var video in r.Video)
{
var ratingKey = video.RatingKey;
var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, ratingKey);
metadataList.Add(metadata);
}
}
foreach (var m in metadataList)
{
foreach (var video in m.Video)
{
episodesModel.Add(new PlexEpisodeModel
{
RatingKey = video.RatingKey,
EpisodeTitle = video.Title,
Guid = video.Guid,
ShowTitle = video.GrandparentTitle
});
}
}
if (results.Any())
{
Cache.Set(CacheKeys.PlexEpisodes, episodesModel, CacheKeys.TimeFrameMinutes.SchedulerCaching);
}
}
public void Execute(IJobExecutionContext context)
{
try
{
CacheEpisodes();
}
catch (Exception e)
{
Log.Error(e);
}
finally
{
Job.Record(JobNames.EpisodeCacher);
}
}
}
}

@ -0,0 +1,40 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexEpisodeModel.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using PlexRequests.Helpers;
namespace PlexRequests.Services.Models
{
public class PlexEpisodeModel
{
public EpisodeModelHelper Episodes => PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(Guid);
public string Guid { get; set; }
public string RatingKey { get; set; }
public string EpisodeTitle { get; set; }
public string ShowTitle { get; set; }
}
}

@ -73,6 +73,7 @@
<Compile Include="Interfaces\IJobRecord.cs" />
<Compile Include="Jobs\JobRecord.cs" />
<Compile Include="Jobs\JobNames.cs" />
<Compile Include="Jobs\PlexEpisodeCacher.cs" />
<Compile Include="Jobs\StoreBackup.cs" />
<Compile Include="Jobs\StoreCleanup.cs" />
<Compile Include="Jobs\CouchPotatoCacher.cs" />
@ -81,6 +82,7 @@
<Compile Include="Jobs\SonarrCacher.cs" />
<Compile Include="Jobs\UserRequestLimitResetter.cs" />
<Compile Include="Models\PlexAlbum.cs" />
<Compile Include="Models\PlexEpisodeModel.cs" />
<Compile Include="Models\PlexMovie.cs" />
<Compile Include="Models\PlexTvShow.cs" />
<Compile Include="Interfaces\ISickRageCacher.cs" />

@ -56,21 +56,20 @@ namespace PlexRequests.UI.Jobs
{
var jobs = new List<IJobDetail>();
var plex = JobBuilder.Create<PlexAvailabilityChecker>().WithIdentity("PlexAvailabilityChecker", "Plex").Build();
var sickrage = JobBuilder.Create<SickRageCacher>().WithIdentity("SickRageCacher", "Cache").Build();
var sonarr = JobBuilder.Create<SonarrCacher>().WithIdentity("SonarrCacher", "Cache").Build();
var cp = JobBuilder.Create<CouchPotatoCacher>().WithIdentity("CouchPotatoCacher", "Cache").Build();
var store = JobBuilder.Create<StoreBackup>().WithIdentity("StoreBackup", "Database").Build();
var storeClean = JobBuilder.Create<StoreCleanup>().WithIdentity("StoreCleanup", "Database").Build();
var userRequestLimitReset = JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build();
jobs.Add(plex);
jobs.Add(sickrage);
jobs.Add(sonarr);
jobs.Add(cp);
jobs.Add(store);
jobs.Add(storeClean);
jobs.Add(userRequestLimitReset);
var jobList = new List<IJobDetail>
{
JobBuilder.Create<PlexAvailabilityChecker>().WithIdentity("PlexAvailabilityChecker", "Plex").Build(),
JobBuilder.Create<PlexEpisodeCacher>().WithIdentity("PlexEpisodeCacher", "Cache").Build(),
JobBuilder.Create<SickRageCacher>().WithIdentity("SickRageCacher", "Cache").Build(),
JobBuilder.Create<SonarrCacher>().WithIdentity("SonarrCacher", "Cache").Build(),
JobBuilder.Create<CouchPotatoCacher>().WithIdentity("CouchPotatoCacher", "Cache").Build(),
JobBuilder.Create<StoreBackup>().WithIdentity("StoreBackup", "Database").Build(),
JobBuilder.Create<StoreCleanup>().WithIdentity("StoreCleanup", "Database").Build(),
JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build()
};
jobs.AddRange(jobList);
return jobs;
}
@ -145,19 +144,26 @@ namespace PlexRequests.UI.Jobs
.WithSimpleSchedule(x => x.WithIntervalInHours(s.StoreBackup).RepeatForever())
.Build();
var storeCleanup =
TriggerBuilder.Create()
.WithIdentity("StoreCleanup", "Database")
.StartNow()
.WithSimpleSchedule(x => x.WithIntervalInHours(s.StoreCleanup).RepeatForever())
.Build();
var storeCleanup =
TriggerBuilder.Create()
.WithIdentity("StoreCleanup", "Database")
.StartNow()
.WithSimpleSchedule(x => x.WithIntervalInHours(s.StoreCleanup).RepeatForever())
.Build();
var userRequestLimiter =
TriggerBuilder.Create()
.WithIdentity("UserRequestLimiter", "Request")
.StartAt(DateTimeOffset.Now.AddMinutes(5)) // Everything has started on application start, lets wait 5 minutes
.WithSimpleSchedule(x => x.WithIntervalInHours(s.UserRequestLimitResetter).RepeatForever())
.Build();
TriggerBuilder.Create()
.WithIdentity("UserRequestLimiter", "Request")
.StartAt(DateTimeOffset.Now.AddMinutes(5)) // Everything has started on application start, lets wait 5 minutes
.WithSimpleSchedule(x => x.WithIntervalInHours(s.UserRequestLimitResetter).RepeatForever())
.Build();
var plexEpCacher =
TriggerBuilder.Create()
.WithIdentity("PlexEpisodeCacher", "Cache")
.StartAt(DateTimeOffset.Now.AddMinutes(2)) // Everything has started on application start, lets wait 5 minutes
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.PlexEpisodeCacher).RepeatForever())
.Build();
triggers.Add(plexAvailabilityChecker);
@ -167,6 +173,7 @@ namespace PlexRequests.UI.Jobs
triggers.Add(storeBackup);
triggers.Add(storeCleanup);
triggers.Add(userRequestLimiter);
triggers.Add(plexEpCacher);
return triggers;
}

@ -572,12 +572,14 @@ namespace PlexRequests.UI.Modules
}
// check if the show/episodes have already been requested
var existingRequest = await RequestService.CheckRequestAsync(showId);
var difference = new List<Store.EpisodesModel>();
if (existingRequest != null)
{
if (episodeRequest)
{
var difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
difference = GetListDifferences(existingRequest.Episodes, episodeModel.Episodes).ToList();
if (!difference.Any())
{
return await AddUserToRequest(existingRequest, settings, fullShowName);
@ -601,7 +603,13 @@ namespace PlexRequests.UI.Modules
}
if (episodeRequest)
{
// TODO: If it's an episode request, check if the episode exists
foreach (var d in difference)
{
if (Checker.IsEpisodeAvailable(providerId, d.SeasonNumber, d.EpisodeNumber))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} {d.SeasonNumber} - {d.EpisodeNumber} {Resources.UI.Search_AlreadyInPlex}" });
}
}
}
else
{
@ -949,14 +957,16 @@ namespace PlexRequests.UI.Modules
{
var requested = dbDbShow?.Episodes
.Any(episodesModel =>
ep.number == episodesModel.EpisodeNumber && ep.season == episodesModel.SeasonNumber);
ep.number == episodesModel.EpisodeNumber && ep.season == episodesModel.SeasonNumber) ?? false;
var alreadyInPlex = Checker.IsEpisodeAvailable(seriesId.ToString(), ep.season, ep.number);
model.Add(new EpisodeListViewModel
{
Id = show.id,
SeasonNumber = ep.season,
EpisodeNumber = ep.number,
Requested = requested ?? false,
Requested = requested || alreadyInPlex,
Name = ep.name,
EpisodeId = ep.id
});

@ -33,7 +33,11 @@
<input type="text" class="form-control form-control-custom " id="CouchPotatoCacher" name="CouchPotatoCacher" value="@Model.CouchPotatoCacher">
</div>
<div class="form-group">
<label for="PlexEpisodeCacher" class="control-label">Plex Episode Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="PlexEpisodeCacher" name="PlexEpisodeCacher" value="@Model.PlexEpisodeCacher">
</div>
<div class="form-group">
<label for="SonarrCacher" class="control-label">Sonarr Cacher (min)</label>
<div>

Loading…
Cancel
Save