Creating the provider manager

This commit is contained in:
Zoe Roux
2020-01-18 17:34:07 +01:00
parent 9d37426764
commit 3d79d41a60
18 changed files with 343 additions and 279 deletions
+62 -36
View File
@@ -1,50 +1,76 @@
using Kyoo.Controllers;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using Kyoo.Utility;
namespace Kyoo.Models
{
public class Collection
public class Collection : IMergable<Collection>
{
[JsonIgnore] public long id;
public string Slug;
public string Name;
public string Poster;
public string Overview;
[JsonIgnore] public string ImgPrimary;
public IEnumerable<Show> Shows;
[JsonIgnore] public long id = -1;
public string Slug;
public string Name;
public string Poster;
public string Overview;
[JsonIgnore] public string ImgPrimary;
public IEnumerable<Show> Shows;
public Collection() { }
public Collection()
{
}
public Collection(long id, string slug, string name, string overview, string imgPrimary)
{
this.id = id;
Slug = slug;
Name = name;
Overview = overview;
ImgPrimary = imgPrimary;
}
public Collection(long id, string slug, string name, string overview, string imgPrimary)
{
this.id = id;
Slug = slug;
Name = name;
Overview = overview;
ImgPrimary = imgPrimary;
}
public static Collection FromReader(System.Data.SQLite.SQLiteDataReader reader)
{
Collection col = new Collection((long)reader["id"],
reader["slug"] as string,
reader["name"] as string,
reader["overview"] as string,
reader["imgPrimary"] as string);
col.Poster = "poster/" + col.Slug;
return col;
}
public static Collection FromReader(System.Data.SQLite.SQLiteDataReader reader)
{
Collection col = new Collection((long) reader["id"],
reader["slug"] as string,
reader["name"] as string,
reader["overview"] as string,
reader["imgPrimary"] as string);
col.Poster = "poster/" + col.Slug;
return col;
}
public Show AsShow()
{
return new Show(-1, Slug, Name, null, null, Overview, null, null, null, null, null, null);
}
public Show AsShow()
{
return new Show(-1, Slug, Name, null, null, Overview, null, null, null, null, null, null);
}
public Collection SetShows(ILibraryManager libraryManager)
{
Shows = libraryManager.GetShowsInCollection(id);
return this;
}
public Collection SetShows(ILibraryManager libraryManager)
{
Shows = libraryManager.GetShowsInCollection(id);
return this;
}
public Collection Merge(Collection collection)
{
if (id == -1)
id = collection.id;
if (Slug == null)
Slug = collection.Slug;
if (Name == null)
Name = collection.Name;
if (Poster == null)
Poster = collection.Poster;
if (Overview == null)
Overview = collection.Overview;
if (ImgPrimary == null)
ImgPrimary = collection.ImgPrimary;
if (Shows == null)
Shows = collection.Shows;
else
Shows = Shows.Concat(collection.Shows);
return this;
}
}
}
+32 -1
View File
@@ -1,9 +1,10 @@
using Newtonsoft.Json;
using System;
using Kyoo.Utility;
namespace Kyoo.Models
{
public class Episode
public class Episode : IMergable<Episode>
{
[JsonIgnore] public long id;
[JsonIgnore] public long ShowID;
@@ -97,5 +98,35 @@ namespace Kyoo.Models
{
return showSlug + "-s" + seasonNumber + "e" + episodeNumber;
}
public Episode Merge(Episode other)
{
if (id == -1)
id = other.id;
if (ShowID == -1)
ShowID = other.ShowID;
if (SeasonID == -1)
SeasonID = other.SeasonID;
if (seasonNumber == -1)
seasonNumber = other.seasonNumber;
if (episodeNumber == -1)
episodeNumber = other.episodeNumber;
if (absoluteNumber == -1)
absoluteNumber = other.absoluteNumber;
if (Path == null)
Path = other.Path;
if (Title == null)
Title = other.Title;
if (Overview == null)
Overview = other.Overview;
if (ReleaseDate == null)
ReleaseDate = other.ReleaseDate;
if (Runtime == -1)
Runtime = other.Runtime;
if (ImgPrimary == null)
ImgPrimary = other.ImgPrimary;
ExternalIDs += '|' + other.ExternalIDs;
return this;
}
}
}
+7 -4
View File
@@ -7,14 +7,16 @@ namespace Kyoo.Models
[JsonIgnore] public readonly long id;
public string Slug;
public string Name;
public string Path;
public string[] Paths;
public string[] Providers;
public Library(long id, string slug, string name, string path)
public Library(long id, string slug, string name, string[] paths, string[] providers)
{
this.id = id;
Slug = slug;
Name = name;
Path = path;
Paths = paths;
Providers = providers;
}
public static Library FromReader(System.Data.SQLite.SQLiteDataReader reader)
@@ -22,7 +24,8 @@ namespace Kyoo.Models
return new Library((long)reader["id"],
reader["slug"] as string,
reader["name"] as string,
reader["path"] as string);
(reader["path"] as string)?.Split('|'),
(reader["providers"] as string)?.Split('|'));
}
}
}
+21 -2
View File
@@ -1,8 +1,9 @@
using Newtonsoft.Json;
using Kyoo.Utility;
using Newtonsoft.Json;
namespace Kyoo.Models
{
public class People
public class People : IMergable<People>
{
[JsonIgnore] public long id;
public string slug;
@@ -52,5 +53,23 @@ namespace Kyoo.Models
reader["imgPrimary"] as string,
reader["externalIDs"] as string);
}
public People Merge(People other)
{
if (id == -1)
id = other.id;
if (slug == null)
slug = other.slug;
if (Name == null)
Name = other.Name;
if (Role == null)
Role = other.Role;
if (Type == null)
Type = other.Type;
if (imgPrimary == null)
imgPrimary = other.imgPrimary;
externalIDs += '|' + other.externalIDs;
return this;
}
}
}
+22 -2
View File
@@ -1,8 +1,10 @@
using Newtonsoft.Json;
using System.Linq;
using Kyoo.Utility;
using Newtonsoft.Json;
namespace Kyoo.Models
{
public class Season
public class Season : IMergable<Season>
{
[JsonIgnore] public readonly long id;
[JsonIgnore] public long ShowID;
@@ -40,5 +42,23 @@ namespace Kyoo.Models
reader["imgPrimary"] as string,
reader["externalIDs"] as string);
}
public Season Merge(Season other)
{
if (ShowID == -1)
ShowID = other.ShowID;
if (seasonNumber == -1)
seasonNumber = other.seasonNumber;
if (Title == null)
Title = other.Title;
if (Overview == null)
Overview = other.Overview;
if (year == null)
year = other.year;
if (ImgPrimary == null)
ImgPrimary = other.ImgPrimary;
ExternalIDs += '|' + other.ExternalIDs;
return this;
}
}
}
+44 -2
View File
@@ -1,10 +1,12 @@
using Kyoo.Controllers;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using Kyoo.Utility;
namespace Kyoo.Models
{
public class Show
public class Show : IMergable<Show>
{
[JsonIgnore] public long id = -1;
@@ -111,7 +113,7 @@ namespace Kyoo.Models
return new Show((long)reader["id"],
reader["slug"] as string,
reader["title"] as string,
(reader["aliases"] as string)?.Split('|') ?? null,
(reader["aliases"] as string)?.Split('|'),
reader["path"] as string,
reader["overview"] as string,
reader["trailerUrl"] as string,
@@ -161,6 +163,46 @@ namespace Kyoo.Models
seasons = manager.GetSeasons(id);
return this;
}
public Show Merge(Show other)
{
if (id == -1)
id = other.id;
if (Slug == null)
Slug = other.Slug;
if (Title == null)
Title = other.Title;
if (Aliases == null)
Aliases = other.Aliases;
else
Aliases = Aliases.Concat(other.Aliases);
if (Genres == null)
Genres = other.Genres;
else
Genres = Genres.Concat(other.Genres);
if (Path == null)
Path = other.Path;
if (Overview == null)
Overview = other.Overview;
if (TrailerUrl == null)
TrailerUrl = other.TrailerUrl;
if (Status == null)
Status = other.Status;
if (StartYear == null)
StartYear = other.StartYear;
if (EndYear == null)
EndYear = other.EndYear;
if (ImgPrimary == null)
ImgPrimary = other.ImgPrimary;
if (ImgThumb == null)
ImgThumb = other.ImgThumb;
if (ImgLogo == null)
ImgLogo = other.ImgLogo;
if (ImgBackdrop == null)
ImgBackdrop = other.ImgBackdrop;
ExternalIDs += '|' + other.ExternalIDs;
return this;
}
}
public enum Status { Finished, Airing }