Starting to rework the LibraryManager

This commit is contained in:
Zoe Roux 2020-02-05 00:47:14 +01:00
parent 38d6b4fbde
commit 5181a6cf46
12 changed files with 911 additions and 1120 deletions

View File

@ -9,18 +9,18 @@ namespace Kyoo.Controllers
//Read values
string GetShowExternalIDs(long showID);
Studio GetStudio(long showID);
List<People> GetDirectors(long showID);
List<People> GetPeople(long showID);
List<Genre> GetGenreForShow(long showID);
List<Season> GetSeasons(long showID);
IEnumerable<People> GetDirectors(long showID);
IEnumerable<People> GetPeople(long showID);
IEnumerable<Genre> GetGenreForShow(long showID);
IEnumerable<Season> GetSeasons(long showID);
int GetSeasonCount(string showSlug, long seasonNumber);
IEnumerable<Show> GetShowsInCollection(long collectionID);
List<Show> GetShowsInLibrary(long libraryID);
IEnumerable<Show> GetShowsInLibrary(long libraryID);
IEnumerable<Show> GetShowsByPeople(long peopleID);
IEnumerable<string> GetLibrariesPath();
//Internal read
(Track video, List<Track> audios, List<Track> subtitles) GetStreams(long episodeID, string showSlug);
(Track video, IEnumerable<Track> audios, IEnumerable<Track> subtitles) GetStreams(long episodeID, string showSlug);
Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced);
//Public read
@ -30,8 +30,8 @@ namespace Kyoo.Controllers
IEnumerable<Library> GetLibraries();
Show GetShowBySlug(string slug);
Season GetSeason(string showSlug, long seasonNumber);
List<Episode> GetEpisodes(string showSlug);
List<Episode> GetEpisodes(string showSlug, long seasonNumber);
IEnumerable<Episode> GetEpisodes(string showSlug);
IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber);
Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true);
People GetPeopleBySlug(string slug);

View File

@ -39,7 +39,10 @@ namespace Kyoo.Models
public Show AsShow()
{
return new Show(-1, Slug, Name, null, null, Overview, null, null, null, null, null, null);
return new Show(-1, Slug, Name, null, null, Overview, null, null, null, null, null, null)
{
IsCollection = true
};
}
public Collection SetShows(ILibraryManager libraryManager)

View File

@ -0,0 +1,11 @@
namespace Kyoo.Models
{
public class CollectionLink
{
public long ID { get; set; }
public long? CollectionID { get; set; }
public virtual Collection Collection { get; set; }
public long ShowID { get; set; }
public virtual Show Show { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace Kyoo.Models
{
public class LibraryLink
{
public long ID { get; set; }
public long LibraryID { get; set; }
public virtual Library Library { get; set; }
public long? ShowID { get; set; }
public virtual Show Show { get; set; }
public long? CollectionID { get; set; }
public virtual Collection Collection { get; set; }
}
}

View File

@ -1,5 +1,4 @@
using Kyoo.Controllers;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@ -38,60 +37,15 @@ namespace Kyoo.Models
ReleaseDate = releaseDate;
Path = path;
Container = Path.Substring(Path.LastIndexOf('.') + 1);
Link = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber);
}
public WatchItem(long episodeID, string showTitle, string showSlug, long seasonNumber, long episodeNumber, string title, DateTime? releaseDate, string path, Track[] audios, Track[] subtitles) : this(episodeID, showTitle, showSlug, seasonNumber, episodeNumber, title, releaseDate, path)
public WatchItem(long episodeID, string showTitle, string showSlug, long seasonNumber, long episodeNumber, string title, DateTime? releaseDate, string path, Track[] audios, Track[] subtitles)
: this(episodeID, showTitle, showSlug, seasonNumber, episodeNumber, title, releaseDate, path)
{
Audios = audios;
Subtitles = subtitles;
}
public static WatchItem FromReader(System.Data.SQLite.SQLiteDataReader reader)
{
return new WatchItem((long)reader["id"],
reader["showTitle"] as string,
reader["showSlug"] as string,
(long)reader["seasonNumber"],
(long)reader["episodeNumber"],
reader["title"] as string,
reader["releaseDate"] as DateTime?,
reader["path"] as string);
}
public WatchItem SetStreams(ILibraryManager libraryManager)
{
(Track video, IEnumerable<Track> audios, IEnumerable<Track> subtitles) streams = libraryManager.GetStreams(EpisodeID, Link);
Container = Path.Substring(Path.LastIndexOf('.') + 1);
Video = streams.video;
Audios = streams.audios;
Subtitles = streams.subtitles;
return this;
}
public WatchItem SetPrevious(ILibraryManager libraryManager)
{
long lastEp = EpisodeNumber - 1;
if(lastEp > 0)
PreviousEpisode = ShowSlug + "-s" + SeasonNumber + "e" + lastEp;
else if(SeasonNumber > 1)
{
int seasonCount = libraryManager.GetSeasonCount(ShowSlug, SeasonNumber - 1);
PreviousEpisode = ShowSlug + "-s" + (SeasonNumber - 1) + "e" + seasonCount;
}
return this;
}
public WatchItem SetNext(ILibraryManager libraryManager)
{
long seasonCount = libraryManager.GetSeasonCount(ShowSlug, SeasonNumber);
if (EpisodeNumber >= seasonCount)
NextEpisode = libraryManager.GetEpisode(ShowSlug, SeasonNumber + 1, 1);
else
NextEpisode = libraryManager.GetEpisode(ShowSlug, SeasonNumber, EpisodeNumber + 1);
return this;
}
}
}

View File

@ -1,7 +0,0 @@
[*.cs]
# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
dotnet_diagnostic.CS4014.severity = silent
# IDE1006: Naming Styles
dotnet_diagnostic.IDE1006.severity = none

File diff suppressed because it is too large Load Diff

View File

@ -19,9 +19,12 @@ namespace Kyoo
public DbSet<Track> Tracks { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<People> Peoples { get; set; }
public DbSet<PeopleLink> PeopleLinks { get; set; }
public DbSet<Studio> Studios { get; set; }
public DbSet<LibraryLink> LibraryLinks { get; set; }
public DbSet<CollectionLink> CollectionLinks { get; set; }
public DbSet<PeopleLink> PeopleLinks { get; set; }
private ValueConverter<string[], string> stringArrayConverter = new ValueConverter<string[], string>(
arr => string.Join("|", arr),
str => str.Split("|", StringSplitOptions.None));
@ -37,16 +40,6 @@ namespace Kyoo
modelBuilder.Entity<Library>().Property(e => e.Paths).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer);
modelBuilder.Entity<Library>().Property(e => e.Providers).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer);
modelBuilder.Entity<Show>().Property(e => e.Aliases).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer);
modelBuilder.Entity<PeopleLink>()
.HasOne(l => l.Show)
.WithMany(s => s.People)
.HasForeignKey(l => l.ShowID);
modelBuilder.Entity<PeopleLink>()
.HasOne(l => l.People)
.WithMany(p => p.Roles)
.HasForeignKey(l => l.PeopleID);
modelBuilder.Entity<Track>()
.Property(t => t.IsDefault)

View File

@ -1,7 +1,7 @@
using Kyoo.Controllers;
using Kyoo.Models;
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Kyoo.Controllers
{
@ -9,28 +9,28 @@ namespace Kyoo.Controllers
[ApiController]
public class EpisodesController : ControllerBase
{
private readonly ILibraryManager libraryManager;
private readonly ILibraryManager _libraryManager;
public EpisodesController(ILibraryManager libraryManager)
{
this.libraryManager = libraryManager;
_libraryManager = libraryManager;
}
[HttpGet("{showSlug}/season/{seasonNumber}")]
public ActionResult<IEnumerable<Episode>> GetEpisodesForSeason(string showSlug, long seasonNumber)
{
List<Episode> episodes = libraryManager.GetEpisodes(showSlug, seasonNumber);
IEnumerable<Episode> episodes = _libraryManager.GetEpisodes(showSlug, seasonNumber);
if(episodes == null)
return NotFound();
return episodes;
return episodes.ToList();
}
[HttpGet("{showSlug}/season/{seasonNumber}/episode/{episodeNumber}")]
public ActionResult<Episode> GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
{
Episode episode = libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
if (episode == null)
return NotFound();

View File

@ -2,6 +2,7 @@
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Kyoo.Controllers
{
@ -9,28 +10,28 @@ namespace Kyoo.Controllers
[ApiController]
public class LibrariesController : ControllerBase
{
private readonly ILibraryManager libraryManager;
private readonly ILibraryManager _libraryManager;
public LibrariesController(ILibraryManager libraryManager)
{
this.libraryManager = libraryManager;
_libraryManager = libraryManager;
}
[HttpGet]
public IEnumerable<Library> GetLibraries()
{
return libraryManager.GetLibraries();
return _libraryManager.GetLibraries();
}
[HttpGet("{librarySlug}")]
public ActionResult<IEnumerable<Show>> GetShows(string librarySlug)
{
Library library = libraryManager.GetLibrary(librarySlug);
Library library = _libraryManager.GetLibrary(librarySlug);
if (library == null)
return NotFound();
return libraryManager.GetShowsInLibrary(library.Id);
return _libraryManager.GetShowsInLibrary(library.Id).ToList();
}
}
}

View File

@ -65,7 +65,7 @@ namespace Kyoo.Controllers
[HttpGet("extract/{showSlug}")]
public async Task<string> ExtractSubtitle(string showSlug)
{
List<Episode> episodes = libraryManager.GetEpisodes(showSlug);
IEnumerable<Episode> episodes = libraryManager.GetEpisodes(showSlug);
foreach (Episode episode in episodes)
{
libraryManager.ClearSubtitles(episode.Id);

View File

@ -1,9 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=controllers_005Cmetadataprovider_005Cimplementations/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=controllers_005Cmetadataprovider_005Cimplementations_005Cthetvdb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=controllers_005Ctranscoder/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=internalapi_005Ccrawler/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=internalapi_005Clibrarymanager/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=internalapi_005Cmetadataprovider_005Cimplementations/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=internalapi_005Cmetadataprovider_005Cimplementations_005Cthetvdb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=internalapi_005Ctranscoder/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>