Skip to content

Commit

Permalink
Randomize and add Kodi banner support
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Sep 2, 2016
1 parent b315aa4 commit 1904ef5
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 50 deletions.
92 changes: 48 additions & 44 deletions JMMContracts/PlexAndKodi/PlexAndKodiContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,182 +172,186 @@ public class Video
[XmlAttribute("thumb")]
public string Thumb { get; set; }

[DataMember(EmitDefaultValue = false, Order = 25)]
[DataMember(EmitDefaultValue = false, Order = 25)]
[XmlAttribute("banner")]
public string Banner { get; set; }

[DataMember(EmitDefaultValue = false, Order = 26)]
[XmlAttribute("parentThumb")]
public string ParentThumb { get; set; }

[DataMember(EmitDefaultValue = false, Order = 26)]
[DataMember(EmitDefaultValue = false, Order = 27)]
[XmlAttribute("grandparentThumb")]
public string GrandparentThumb { get; set; }

[DataMember(EmitDefaultValue = false, Order = 27)]
[DataMember(EmitDefaultValue = false, Order = 28)]
[XmlAttribute("parentArt")]
public string ParentArt { get; set; }

[DataMember(EmitDefaultValue = false, Order = 28)]
[DataMember(EmitDefaultValue = false, Order = 29)]
[XmlAttribute("grandparentArt")]
public string GrandparentArt { get; set; }

[DataMember(EmitDefaultValue = false, Order = 29)]
[DataMember(EmitDefaultValue = false, Order = 30)]
[XmlAttribute("ratingKey")]
public string RatingKey { get; set; }

[DataMember(EmitDefaultValue = false, Order = 30)]
[DataMember(EmitDefaultValue = false, Order = 31)]
[XmlAttribute("parentRatingkey")]
public string ParentRatingKey { get; set; }

[DataMember(EmitDefaultValue = false, Order = 31)]
[DataMember(EmitDefaultValue = false, Order = 32)]
[XmlAttribute("grandparentRatingKey")]
public string GrandparentRatingKey { get; set; }

[DataMember(EmitDefaultValue = false, Order = 32)]
[DataMember(EmitDefaultValue = false, Order = 33)]
[XmlAttribute("key")]
public string Key { get; set; }

[DataMember(EmitDefaultValue = false, Order = 33)]
[DataMember(EmitDefaultValue = false, Order = 34)]
[XmlAttribute("parentKey")]
public string ParentKey { get; set; }

[DataMember(EmitDefaultValue = false, Order = 34)]
[DataMember(EmitDefaultValue = false, Order = 35)]
[XmlAttribute("grandparentKey")]
public string GrandparentKey { get; set; }

[DataMember(EmitDefaultValue = false, Order = 35)]
[DataMember(EmitDefaultValue = false, Order = 36)]
[XmlAttribute("index")]
public string Index { get; set; }

[Plex]
[DataMember(EmitDefaultValue = false, Order = 36)]
[DataMember(EmitDefaultValue = false, Order = 37)]
[XmlAttribute("parentIndex")]
public string ParentIndex { get; set; }

[DataMember(EmitDefaultValue = false, Order = 37)]
[DataMember(EmitDefaultValue = false, Order = 38)]
[XmlAttribute("guid")]
public string Guid { get; set; }

[DataMember(EmitDefaultValue = false, Order = 38)]
[DataMember(EmitDefaultValue = false, Order = 39)]
[XmlAttribute("type")]
public string Type { get; set; }

[DataMember(EmitDefaultValue = false, Order = 39)]
[DataMember(EmitDefaultValue = false, Order = 40)]
[XmlAttribute("title")]
public string Title { get; set; }

[DataMember(EmitDefaultValue = false, Order = 40)]
[DataMember(EmitDefaultValue = false, Order = 41)]
[XmlAttribute("title1")]
public string Title1 { get; set; }

[DataMember(EmitDefaultValue = false, Order = 41)]
[DataMember(EmitDefaultValue = false, Order = 42)]
[XmlAttribute("title2")]
public string Title2 { get; set; }

[DataMember(EmitDefaultValue = false, Order = 42)]
[DataMember(EmitDefaultValue = false, Order = 43)]
[XmlAttribute("parentTitle")]
public string ParentTitle { get; set; }

[DataMember(EmitDefaultValue = false, Order = 43)]
[DataMember(EmitDefaultValue = false, Order = 44)]
[XmlAttribute("grandparentTitle")]
public string GrandparentTitle { get; set; }

[DataMember(EmitDefaultValue = false, Order = 44)]
[DataMember(EmitDefaultValue = false, Order = 45)]
[XmlAttribute("summary")]
public string Summary { get; set; }

[DataMember(EmitDefaultValue = false, Order = 45)]
[DataMember(EmitDefaultValue = false, Order = 46)]
[XmlAttribute("year")]
public string Year { get; set; }

[Plex]
[DataMember(EmitDefaultValue = false, Order = 46)]
[DataMember(EmitDefaultValue = false, Order = 47)]
[XmlAttribute("duration")]
public string Duration { get; set; }

[DataMember(EmitDefaultValue = false, Order = 47)]
[DataMember(EmitDefaultValue = false, Order = 48)]
[XmlAttribute("episode_count")]
public string EpisodeCount { get; set; }

[DataMember(EmitDefaultValue = false, Order = 48)]
[DataMember(EmitDefaultValue = false, Order = 49)]
[XmlAttribute("updatedAt")]
public string UpdatedAt { get; set; }

[DataMember(EmitDefaultValue = false, Order = 49)]
[DataMember(EmitDefaultValue = false, Order = 50)]
[XmlAttribute("addedAt")]
public string AddedAt { get; set; }

[DataMember(EmitDefaultValue = false, Order = 50)]
[DataMember(EmitDefaultValue = false, Order = 51)]
[XmlAttribute("lastViewedAt")]
public string LastViewedAt { get; set; }

[DataMember(EmitDefaultValue = false, Order = 51)]
[DataMember(EmitDefaultValue = false, Order = 52)]
[XmlAttribute("originallyAvailableAt")]
public string OriginallyAvailableAt { get; set; }

[DataMember(EmitDefaultValue = false, Order = 52)]
[DataMember(EmitDefaultValue = false, Order = 53)]
[XmlAttribute("leafCount")]
public string LeafCount { get; set; }

[Plex]
[DataMember(EmitDefaultValue = false, Order = 53)]
[DataMember(EmitDefaultValue = false, Order = 54)]
[XmlAttribute("childCount")]
public string ChildCount { get; set; }

[DataMember(EmitDefaultValue = false, Order = 54)]
[DataMember(EmitDefaultValue = false, Order = 55)]
[XmlAttribute("viewedLeafCount")]
public string ViewedLeafCount { get; set; }

[DataMember(EmitDefaultValue = false, Order = 55)]
[DataMember(EmitDefaultValue = false, Order = 56)]
[XmlAttribute("original_title")]
public string OriginalTitle { get; set; }

[DataMember(EmitDefaultValue = false, Order = 56)]
[DataMember(EmitDefaultValue = false, Order = 57)]
[XmlAttribute("source_title")]
public string SourceTitle { get; set; }

[DataMember(EmitDefaultValue = false, Order = 57)]
[DataMember(EmitDefaultValue = false, Order = 58)]
[XmlAttribute("rating")]
public string Rating { get; set; }

[DataMember(EmitDefaultValue = false, Order = 58)]
[DataMember(EmitDefaultValue = false, Order = 59)]
[XmlAttribute("season")]
public string Season { get; set; }

[DataMember(EmitDefaultValue = false, Order = 59)]
[DataMember(EmitDefaultValue = false, Order = 60)]
[XmlAttribute("viewCount")]
public string ViewCount { get; set; }

[DataMember(EmitDefaultValue = false, Order = 60)]
[DataMember(EmitDefaultValue = false, Order = 61)]
[XmlAttribute("viewOffset")]
public string ViewOffset { get; set; }

[DataMember(EmitDefaultValue = false, Order = 61)]
[DataMember(EmitDefaultValue = false, Order = 62)]
[XmlAttribute("primaryExtraKey")]
public string PrimaryExtraKey { get; set; }

[DataMember(EmitDefaultValue = false, Order = 62)]
[DataMember(EmitDefaultValue = false, Order = 63)]
[XmlAttribute("chapterSource")]
public string ChapterSource { get; set; }

[DataMember(EmitDefaultValue = false, Order = 63)]
[DataMember(EmitDefaultValue = false, Order = 64)]
[XmlAttribute("tagline")]
public string Tagline { get; set; }

[DataMember(EmitDefaultValue = false, Order = 64)]
[DataMember(EmitDefaultValue = false, Order = 65)]
[XmlAttribute("contentRating")]
public string ContentRating { get; set; }

[DataMember(EmitDefaultValue = false, Order = 65)]
[DataMember(EmitDefaultValue = false, Order = 66)]
[XmlAttribute("studio")]
public string Studio { get; set; }

[DataMember(EmitDefaultValue = false, Order = 66)]
[DataMember(EmitDefaultValue = false, Order = 67)]
[XmlAttribute("extraType")]
public string ExtraType { get; set; }

[DataMember(EmitDefaultValue = false, Order = 67)]
[DataMember(EmitDefaultValue = false, Order = 68)]
[XmlAttribute]
public string EpisodeType { get; set; }

[DataMember(EmitDefaultValue = false, Order = 68)]
[DataMember(EmitDefaultValue = false, Order = 69)]
[XmlAttribute]
public string EpisodeNumber { get; set; }

Expand Down
55 changes: 54 additions & 1 deletion JMMServer/Entities/AniDB_Anime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,60 @@ public AniDB_Anime_DefaultImage GetDefaultWideBanner(ISession session)
return repDefaults.GetByAnimeIDAndImagezSizeType(session, this.AnimeID, (int) ImageSizeType.WideBanner);
}

public string AnimeTypeRAW
public ImageDetails GetDefaultWideBannerDetailsNoBlanks(ISession session)
{
Random bannerRandom = new Random();

ImageDetails details = null;
if (GetDefaultWideBanner() == null)
{
// get a random banner (only tvdb)
if (this.AnimeTypeEnum == enAnimeType.Movie)
{
// MovieDB doesn't have banners
return null;
}
else
{
List<TvDB_ImageWideBanner> banners = GetTvDBImageWideBanners(session);
if (banners.Count == 0) return null;

TvDB_ImageWideBanner tvBanner = banners[bannerRandom.Next(0, banners.Count)];
details = new ImageDetails()
{
ImageType = JMMImageType.TvDB_Banner,
ImageID = tvBanner.TvDB_ImageWideBannerID
};
return details;
}
}
else
{
ImageEntityType imageType = (ImageEntityType) GetDefaultWideBanner().ImageParentType;

switch (imageType)
{
case ImageEntityType.TvDB_Banner:

TvDB_ImageWideBannerRepository repTvBanner = new TvDB_ImageWideBannerRepository();
TvDB_ImageWideBanner tvBanner = repTvBanner.GetByID(session,
GetDefaultWideBanner(session).ImageParentID);
if (tvBanner != null)
details = new ImageDetails()
{
ImageType = JMMImageType.TvDB_Banner,
ImageID = tvBanner.TvDB_ImageWideBannerID
};

return details;

}
}

return null;
}

public string AnimeTypeRAW
{
get
{
Expand Down
15 changes: 11 additions & 4 deletions JMMServer/PlexAndKodi/CommonImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ private MediaContainer GetItemsFromPlaylist(IProvider prov, int userid, string i
if (int.TryParse(playlist.PlaylistItems.Split('|')[0].Split(';')[1], out episodeID))
{
var anime = repo.GetByID(session, episodeID).GetAnimeSeries(session).GetAnime(session);
dir.Thumb = anime.GetDefaultPosterDetailsNoBlanks(session).GenPoster();
dir.Art = anime.GetDefaultFanartDetailsNoBlanks(session).GenArt();
dir.Thumb = anime?.GetDefaultPosterDetailsNoBlanks(session)?.GenPoster();
dir.Art = anime?.GetDefaultFanartDetailsNoBlanks(session)?.GenArt();
dir.Banner = anime?.GetDefaultWideBannerDetailsNoBlanks(session)?.GenArt();
}
else
{
Expand Down Expand Up @@ -459,10 +460,10 @@ public MediaContainer Search(IProvider prov, string UserId, string limit, string
a =>
a.Contract != null && a.Contract.AniDBAnime != null &&
a.Contract.AniDBAnime.AniDBAnime != null &&
a.Contract.AniDBAnime.AniDBAnime.AllTags.Contains(query,
(a.Contract.AniDBAnime.AniDBAnime.AllTags.Contains(query,
StringComparer.InvariantCultureIgnoreCase) ||
a.Contract.AniDBAnime.CustomTags.Select(b => b.TagName)
.Contains(query, StringComparer.InvariantCultureIgnoreCase))
.Contains(query, StringComparer.InvariantCultureIgnoreCase)))
: repSeries.GetAll()
.Where(
a =>
Expand Down Expand Up @@ -541,10 +542,12 @@ public MediaContainer GetItemsFromGroup(IProvider prov, int userid, string Group
{
AnimeSeries ser = repSer.GetByID(grpChild.DefaultAnimeSeriesID.Value);
v.Art = Helper.GetRandomFanartFromSeries(new List<AnimeSeries>() { ser });
v.Banner = Helper.GetRandomBannerFromSeries(new List<AnimeSeries>() {ser});
}
else
{
v.Art = Helper.GetRandomFanartFromSeries(grpChild.GetAllSeries());
v.Banner = Helper.GetRandomBannerFromSeries(grpChild.GetAllSeries());
}
retGroups.Add(prov, v, info);
v.ParentThumb = v.GrandparentThumb = null;
Expand All @@ -563,10 +566,12 @@ public MediaContainer GetItemsFromGroup(IProvider prov, int userid, string Group
{
AnimeSeries ser1 = repSer.GetByID(grp.DefaultAnimeSeriesID.Value);
v.Art = Helper.GetRandomFanartFromSeries(new List<AnimeSeries>() { ser1 });
v.Banner = Helper.GetRandomBannerFromSeries(new List<AnimeSeries>() {ser1});
}
else
{
v.Art = Helper.GetRandomFanartFromSeries(grp.GetAllSeries());
v.Banner = Helper.GetRandomBannerFromSeries(grp.GetAllSeries());
}
retGroups.Add(prov, v, info);
v.ParentThumb = v.GrandparentThumb = null;
Expand Down Expand Up @@ -1168,10 +1173,12 @@ private MediaContainer GetGroupsOrSubFiltersFromFilter(IProvider prov, int useri
AnimeSeriesRepository repSer = new AnimeSeriesRepository();
AnimeSeries ser1 = repSer.GetByID(grp.DefaultAnimeSeriesID.Value);
v.Art = Helper.GetRandomFanartFromSeries(new List<AnimeSeries>() { ser1 });
v.Banner = Helper.GetRandomBannerFromSeries(new List<AnimeSeries>() {ser1});
}
else
{
v.Art = Helper.GetRandomFanartFromSeries(grp.GetAllSeries());
v.Banner = Helper.GetRandomBannerFromSeries(grp.GetAllSeries());
}
order.Add(v.Group, v);
retGroups.Add(prov, v, info);
Expand Down
25 changes: 24 additions & 1 deletion JMMServer/PlexAndKodi/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,30 @@ public static void AddInformationFromMasterSeries(Video v, Contract_AnimeSeries
v.IsMovie = ret;
}

public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source, int seed = -1)
public static string GetRandomBannerFromSeries(List<AnimeSeries> series)
{
using (var session = JMMService.SessionFactory.OpenSession())
{
return GetRandomBannerFromSeries(series, session);
}
}

public static string GetRandomBannerFromSeries(List<AnimeSeries> series, ISession session)
{
foreach (AnimeSeries ser in series.Randomize())
{
AniDB_Anime anim = ser.GetAnime(session);
if (anim != null)
{
ImageDetails banner = anim.GetDefaultWideBannerDetailsNoBlanks(session);
if (banner != null)
return banner.GenArt();
}
}
return null;
}

public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source, int seed = -1)
{
Random rnd;
if (seed == -1)
Expand Down

0 comments on commit 1904ef5

Please sign in to comment.