mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Starting to rework the LibraryManager
This commit is contained in:
parent
38d6b4fbde
commit
5181a6cf46
@ -9,18 +9,18 @@ namespace Kyoo.Controllers
|
|||||||
//Read values
|
//Read values
|
||||||
string GetShowExternalIDs(long showID);
|
string GetShowExternalIDs(long showID);
|
||||||
Studio GetStudio(long showID);
|
Studio GetStudio(long showID);
|
||||||
List<People> GetDirectors(long showID);
|
IEnumerable<People> GetDirectors(long showID);
|
||||||
List<People> GetPeople(long showID);
|
IEnumerable<People> GetPeople(long showID);
|
||||||
List<Genre> GetGenreForShow(long showID);
|
IEnumerable<Genre> GetGenreForShow(long showID);
|
||||||
List<Season> GetSeasons(long showID);
|
IEnumerable<Season> GetSeasons(long showID);
|
||||||
int GetSeasonCount(string showSlug, long seasonNumber);
|
int GetSeasonCount(string showSlug, long seasonNumber);
|
||||||
IEnumerable<Show> GetShowsInCollection(long collectionID);
|
IEnumerable<Show> GetShowsInCollection(long collectionID);
|
||||||
List<Show> GetShowsInLibrary(long libraryID);
|
IEnumerable<Show> GetShowsInLibrary(long libraryID);
|
||||||
IEnumerable<Show> GetShowsByPeople(long peopleID);
|
IEnumerable<Show> GetShowsByPeople(long peopleID);
|
||||||
IEnumerable<string> GetLibrariesPath();
|
IEnumerable<string> GetLibrariesPath();
|
||||||
|
|
||||||
//Internal read
|
//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);
|
Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced);
|
||||||
|
|
||||||
//Public read
|
//Public read
|
||||||
@ -30,8 +30,8 @@ namespace Kyoo.Controllers
|
|||||||
IEnumerable<Library> GetLibraries();
|
IEnumerable<Library> GetLibraries();
|
||||||
Show GetShowBySlug(string slug);
|
Show GetShowBySlug(string slug);
|
||||||
Season GetSeason(string showSlug, long seasonNumber);
|
Season GetSeason(string showSlug, long seasonNumber);
|
||||||
List<Episode> GetEpisodes(string showSlug);
|
IEnumerable<Episode> GetEpisodes(string showSlug);
|
||||||
List<Episode> GetEpisodes(string showSlug, long seasonNumber);
|
IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber);
|
||||||
Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
|
Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
|
||||||
WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true);
|
WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true);
|
||||||
People GetPeopleBySlug(string slug);
|
People GetPeopleBySlug(string slug);
|
||||||
|
@ -39,7 +39,10 @@ namespace Kyoo.Models
|
|||||||
|
|
||||||
public Show AsShow()
|
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)
|
public Collection SetShows(ILibraryManager libraryManager)
|
||||||
|
11
Kyoo.Common/Models/CollectionLink.cs
Normal file
11
Kyoo.Common/Models/CollectionLink.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
13
Kyoo.Common/Models/LibraryLink.cs
Normal file
13
Kyoo.Common/Models/LibraryLink.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using Kyoo.Controllers;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@ -38,60 +37,15 @@ namespace Kyoo.Models
|
|||||||
ReleaseDate = releaseDate;
|
ReleaseDate = releaseDate;
|
||||||
Path = path;
|
Path = path;
|
||||||
|
|
||||||
|
Container = Path.Substring(Path.LastIndexOf('.') + 1);
|
||||||
Link = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber);
|
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;
|
Audios = audios;
|
||||||
Subtitles = subtitles;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
@ -1,11 +1,9 @@
|
|||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Watch;
|
using Kyoo.Models.Watch;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using System.Diagnostics;
|
using System.Linq;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
@ -20,11 +18,6 @@ namespace Kyoo.Controllers
|
|||||||
_database = database;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
~LibraryManager()
|
|
||||||
{
|
|
||||||
sqlConnection.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Read the database
|
#region Read the database
|
||||||
public IEnumerable<Library> GetLibraries()
|
public IEnumerable<Library> GetLibraries()
|
||||||
{
|
{
|
||||||
@ -33,298 +26,137 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
public IEnumerable<string> GetLibrariesPath()
|
public IEnumerable<string> GetLibrariesPath()
|
||||||
{
|
{
|
||||||
const string query = "SELECT path FROM libraries;";
|
IEnumerable<string> paths = new List<string>();
|
||||||
|
return Enumerable.Aggregate(_database.Libraries, paths, (current, lib) => current.Concat(lib.Paths));
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
List<string> libraries = new List<string>();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
libraries.Add(reader["path"] as string);
|
|
||||||
|
|
||||||
return libraries;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetShowExternalIDs(long showID)
|
public string GetShowExternalIDs(long showID)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM shows WHERE id = $showID;";
|
return (from show in _database.Shows where show.ID == showID select show.ExternalIDs).FirstOrDefault();
|
||||||
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showID", showID);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
if (reader.Read())
|
|
||||||
return Show.FromReader(reader).ExternalIDs;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public (Track video, List<Track> audios, List<Track> subtitles) GetStreams(long episodeID, string episodeSlug)
|
public (Track video, IEnumerable<Track> audios, IEnumerable<Track> subtitles) GetStreams(long episodeID, string episodeSlug)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM tracks WHERE episodeID = $episodeID;";
|
IEnumerable<Track> tracks = _database.Tracks.Where(track => track.EpisodeID == episodeID);
|
||||||
|
return ((from track in tracks where track.Type == StreamType.Video select track.SetLink(episodeSlug)).FirstOrDefault(),
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
from track in tracks where track.Type == StreamType.Audio select track.SetLink(episodeSlug),
|
||||||
{
|
from track in tracks where track.Type == StreamType.Subtitle select track.SetLink(episodeSlug));
|
||||||
cmd.Parameters.AddWithValue("$episodeID", episodeID);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
Track video = null;
|
|
||||||
List<Track> audios = new List<Track>();
|
|
||||||
List<Track> subtitles = new List<Track>();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
Track track = Track.FromReader(reader).SetLink(episodeSlug);
|
|
||||||
|
|
||||||
if (track.Type == StreamType.Video)
|
|
||||||
video = track;
|
|
||||||
else if (track.Type == StreamType.Audio)
|
|
||||||
audios.Add(track);
|
|
||||||
else if (track.Type == StreamType.Subtitle)
|
|
||||||
subtitles.Add(track);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (video, audios, subtitles);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced)
|
public Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced)
|
||||||
{
|
{
|
||||||
string query = "SELECT tracks.* FROM tracks JOIN episodes ON tracks.episodeID = episodes.id JOIN shows ON episodes.showID = shows.id WHERE shows.slug = $showSlug AND episodes.seasonNumber = $seasonNumber AND episodes.episodeNumber = $episodeNumber AND tracks.language = $languageTag AND tracks.isForced = $forced;";
|
long? showID = _database.Shows.FirstOrDefault(x => x.Slug == showSlug)?.ID;
|
||||||
|
if (showID == null)
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
|
||||||
cmd.Parameters.AddWithValue("$episodeNumber", episodeNumber);
|
|
||||||
cmd.Parameters.AddWithValue("$languageTag", languageTag);
|
|
||||||
cmd.Parameters.AddWithValue("$forced", forced);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
if (reader.Read())
|
|
||||||
return Track.FromReader(reader).SetLink(Episode.GetSlug(showSlug, seasonNumber, episodeNumber));
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
return (from track in _database.Tracks where track.Episode.ShowID == showID
|
||||||
|
&& track.Episode.SeasonNumber == seasonNumber
|
||||||
|
&& track.Episode.EpisodeNumber == episodeNumber
|
||||||
|
&& track.Language == languageTag select track).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Library GetLibrary(string librarySlug)
|
public Library GetLibrary(string librarySlug)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM libraries WHERE slug = $slug;";
|
return (from library in _database.Libraries where library.Slug == librarySlug select library).FirstOrDefault();
|
||||||
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$slug", librarySlug);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
if (reader.Read())
|
|
||||||
return Library.FromReader(reader);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Show> GetShows()
|
public IEnumerable<Show> GetShows()
|
||||||
{
|
{
|
||||||
List<Show> shows = new List<Show>();
|
return (from show in _database.Shows join link in _database.CollectionLinks on show equals link.Show into gj
|
||||||
SQLiteDataReader reader;
|
from l in gj.DefaultIfEmpty()
|
||||||
string query = "SELECT slug, title, startYear, endYear, '0' FROM shows LEFT JOIN collectionsLinks l ON l.showID = shows.id WHERE l.showID IS NULL UNION SELECT slug, name, startYear, endYear, '1' FROM collections ORDER BY title;";
|
where l.CollectionID == null select l.Show).Union(
|
||||||
|
from collection in _database.Collections select collection.AsShow()).OrderBy(x => x.Title);
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
reader = cmd.ExecuteReader();
|
|
||||||
while (reader.Read())
|
|
||||||
shows.Add(Show.FromQueryReader(reader));
|
|
||||||
}
|
|
||||||
return shows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Show> GetShows(string searchQuery)
|
public IEnumerable<Show> GetShows(string searchQuery)
|
||||||
{
|
{
|
||||||
List<Show> shows = new List<Show>();
|
return (from show in _database.Shows join link in _database.CollectionLinks on show equals link.Show into gj
|
||||||
SQLiteDataReader reader;
|
from l in gj.DefaultIfEmpty()
|
||||||
string query = "SELECT slug, title, aliases, startYear, endYear, '0' FROM (SELECT slug, title, aliases, startYear, endYear, '0' FROM shows LEFT JOIN collectionsLinks l ON l.showID = shows.id WHERE l.showID IS NULL UNION SELECT slug, name, null, startYear, endYear, '1' FROM collections) WHERE title LIKE $query OR aliases LIKE $query ORDER BY title;";
|
where l.CollectionID == null select l.Show).Union(
|
||||||
|
from collection in _database.Collections select collection.AsShow())
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
.Where(x => x.Title.Contains(searchQuery)).OrderBy(x => x.Title);
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$query", "%" + searchQuery + "%");
|
|
||||||
reader = cmd.ExecuteReader();
|
|
||||||
while (reader.Read())
|
|
||||||
shows.Add(Show.FromQueryReader(reader, true));
|
|
||||||
}
|
|
||||||
return shows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Show GetShowBySlug(string slug)
|
public Show GetShowBySlug(string slug)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM shows WHERE slug = $slug;";
|
return (from show in _database.Shows where show.Slug == slug select show).FirstOrDefault();
|
||||||
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$slug", slug);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
if (reader.Read())
|
|
||||||
return Show.FromReader(reader).SetGenres(this).SetStudio(this).SetDirectors(this).SetSeasons(this).SetPeople(this);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Season> GetSeasons(long showID)
|
public IEnumerable<Season> GetSeasons(long showID)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM seasons WHERE showID = $showID ORDER BY seasonNumber;";
|
return from season in _database.Seasons where season.ShowID == showID select season;
|
||||||
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showID", showID);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
List<Season> seasons = new List<Season>();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
seasons.Add(Season.FromReader(reader));
|
|
||||||
|
|
||||||
return seasons;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Season GetSeason(string showSlug, long seasonNumber)
|
public Season GetSeason(string showSlug, long seasonNumber)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM seasons JOIN shows ON shows.id = seasons.showID WHERE shows.slug = $showSlug AND seasons.seasonNumber = $seasonNumber;";
|
return (from season in _database.Seasons
|
||||||
|
where season.SeasonNumber == seasonNumber
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
&& season.Show.Slug == showSlug
|
||||||
{
|
select season).FirstOrDefault();
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
if (reader.Read())
|
|
||||||
return Season.FromReader(reader);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetSeasonCount(string showSlug, long seasonNumber)
|
public int GetSeasonCount(string showSlug, long seasonNumber)
|
||||||
{
|
{
|
||||||
string query = "SELECT count(episodes.id) FROM episodes JOIN shows ON shows.id = episodes.showID WHERE shows.slug = $showSlug AND episodes.seasonNumber = $seasonNumber;";
|
return (from season in _database.Seasons
|
||||||
|
where season.SeasonNumber == seasonNumber
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
&& season.Show.Slug == showSlug
|
||||||
{
|
select season).FirstOrDefault()?.Episodes.Count() ?? 0;
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
|
||||||
|
|
||||||
int count = Convert.ToInt32(cmd.ExecuteScalar());
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Episode> GetEpisodes(string showSlug)
|
public IEnumerable<Episode> GetEpisodes(string showSlug)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM episodes JOIN shows ON shows.id = episodes.showID WHERE shows.slug = $showSlug ORDER BY episodeNumber;";
|
return from episode in _database.Episodes where episode.Show.Slug == showSlug select episode;
|
||||||
|
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
List<Episode> episodes = new List<Episode>();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
episodes.Add(Episode.FromReader(reader).SetThumb(showSlug));
|
|
||||||
|
|
||||||
return episodes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Episode> GetEpisodes(string showSlug, long seasonNumber)
|
public IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM episodes JOIN shows ON shows.id = episodes.showID WHERE shows.slug = $showSlug AND episodes.seasonNumber = $seasonNumber ORDER BY episodeNumber;";
|
return from episode in _database.Episodes where episode.SeasonNumber == seasonNumber
|
||||||
|
&& episode.Show.Slug == showSlug select episode;
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
List<Episode> episodes = new List<Episode>();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
episodes.Add(Episode.FromReader(reader).SetThumb(showSlug));
|
|
||||||
|
|
||||||
return episodes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Episode> GetEpisodes(long showID, long seasonNumber)
|
public IEnumerable<Episode> GetEpisodes(long showID, long seasonNumber)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM episodes WHERE episodes.showID = $showID AND episodes.seasonNumber = $seasonNumber ORDER BY episodeNumber;";
|
return from episode in _database.Episodes where episode.ShowID == showID
|
||||||
|
&& episode.SeasonNumber == seasonNumber select episode;
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showID", showID);
|
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
List<Episode> episodes = new List<Episode>();
|
|
||||||
|
|
||||||
while (reader.Read())
|
|
||||||
episodes.Add(Episode.FromReader(reader));
|
|
||||||
|
|
||||||
return episodes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
string query = "SELECT * FROM episodes JOIN shows ON shows.id = episodes.showID WHERE shows.slug = $showSlug AND episodes.seasonNumber = $seasonNumber AND episodes.episodeNumber = $episodeNumber;";
|
return (from episode in _database.Episodes where episode.EpisodeNumber == episodeNumber
|
||||||
|
&& episode.SeasonNumber == seasonNumber
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
&& episode.Show.Slug == showSlug select episode).FirstOrDefault();
|
||||||
{
|
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
|
||||||
cmd.Parameters.AddWithValue("$episodeNumber", episodeNumber);
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
if (reader.Read())
|
|
||||||
return Episode.FromReader(reader).SetThumb(showSlug);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true)
|
public WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true)
|
||||||
{
|
{
|
||||||
string query = "SELECT episodes.id, shows.title as showTitle, shows.slug as showSlug, seasonNumber, episodeNumber, episodes.title, releaseDate, episodes.path FROM episodes JOIN shows ON shows.id = episodes.showID WHERE shows.slug = $showSlug AND episodes.seasonNumber = $seasonNumber AND episodes.episodeNumber = $episodeNumber;";
|
WatchItem item = (from episode in _database.Episodes where episode.SeasonNumber == seasonNumber
|
||||||
|
&& episode.EpisodeNumber == episodeNumber && episode.Show.Slug == showSlug
|
||||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
select new WatchItem(episode.Id,
|
||||||
{
|
episode.Show.Title,
|
||||||
cmd.Parameters.AddWithValue("$showSlug", showSlug);
|
episode.Show.Slug,
|
||||||
cmd.Parameters.AddWithValue("$seasonNumber", seasonNumber);
|
seasonNumber,
|
||||||
cmd.Parameters.AddWithValue("$episodeNumber", episodeNumber);
|
episodeNumber,
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
episode.Title,
|
||||||
|
episode.ReleaseDate,
|
||||||
if (reader.Read())
|
episode.Path)).FirstOrDefault();
|
||||||
{
|
if (item == null)
|
||||||
if (complete)
|
|
||||||
return WatchItem.FromReader(reader).SetStreams(this).SetPrevious(this).SetNext(this);
|
|
||||||
else
|
|
||||||
return WatchItem.FromReader(reader);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
(item.Video, item.Audios, item.Subtitles) = GetStreams(item.EpisodeID, item.Link);
|
||||||
|
if(episodeNumber > 1)
|
||||||
|
item.PreviousEpisode = showSlug + "-s" + seasonNumber + "e" + (episodeNumber - 1);
|
||||||
|
else if(seasonNumber > 1)
|
||||||
|
item.PreviousEpisode = showSlug + "-s" + (seasonNumber - 1) + "e" + GetSeasonCount(showSlug, seasonNumber - 1);
|
||||||
|
|
||||||
|
if (episodeNumber >= GetSeasonCount(showSlug, seasonNumber))
|
||||||
|
item.NextEpisode = GetEpisode(showSlug, seasonNumber + 1, 1);
|
||||||
|
else
|
||||||
|
item.NextEpisode = GetEpisode(showSlug, seasonNumber, episodeNumber + 1);
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<People> GetPeople(long showID)
|
public IEnumerable<People> GetPeople(long showID)
|
||||||
{
|
{
|
||||||
string query = "SELECT people.id, people.slug, people.name, people.imgPrimary, people.externalIDs, l.role, l.type FROM people JOIN peopleLinks l ON l.peopleID = people.id WHERE l.showID = $showID;";
|
string query = "SELECT people.id, people.slug, people.name, people.imgPrimary, people.externalIDs, l.role, l.type FROM people JOIN peopleLinks l ON l.peopleID = people.id WHERE l.showID = $showID;";
|
||||||
|
|
||||||
@ -358,7 +190,7 @@ namespace Kyoo.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Genre> GetGenreForShow(long showID)
|
public IEnumerable<Genre> GetGenreForShow(long showID)
|
||||||
{
|
{
|
||||||
string query = "SELECT genres.id, genres.slug, genres.name FROM genres JOIN genresLinks l ON l.genreID = genres.id WHERE l.showID = $showID;";
|
string query = "SELECT genres.id, genres.slug, genres.name FROM genres JOIN genresLinks l ON l.genreID = genres.id WHERE l.showID = $showID;";
|
||||||
|
|
||||||
@ -424,7 +256,7 @@ namespace Kyoo.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<People> GetDirectors(long showID)
|
public IEnumerable<People> GetDirectors(long showID)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
//string query = "SELECT genres.id, genres.slug, genres.name FROM genres JOIN genresLinks l ON l.genreID = genres.id WHERE l.showID = $showID;";
|
//string query = "SELECT genres.id, genres.slug, genres.name FROM genres JOIN genresLinks l ON l.genreID = genres.id WHERE l.showID = $showID;";
|
||||||
@ -475,7 +307,7 @@ namespace Kyoo.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Show> GetShowsInLibrary(long libraryID)
|
public IEnumerable<Show> GetShowsInLibrary(long libraryID)
|
||||||
{
|
{
|
||||||
List<Show> shows = new List<Show>();
|
List<Show> shows = new List<Show>();
|
||||||
SQLiteDataReader reader;
|
SQLiteDataReader reader;
|
||||||
@ -997,7 +829,7 @@ namespace Kyoo.Controllers
|
|||||||
cmd.Parameters.AddWithValue("$seasonID", seasonID);
|
cmd.Parameters.AddWithValue("$seasonID", seasonID);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
if (GetSeasons(showID).Count == 0)
|
if (GetSeasons(showID).Count() == 0)
|
||||||
RemoveShow(showID);
|
RemoveShow(showID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1011,7 +843,7 @@ namespace Kyoo.Controllers
|
|||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetEpisodes(episode.ShowID, episode.SeasonNumber).Count == 0)
|
if (GetEpisodes(episode.ShowID, episode.SeasonNumber).Count() == 0)
|
||||||
RemoveSeason(episode.ShowID, episode.SeasonID);
|
RemoveSeason(episode.ShowID, episode.SeasonID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,12 @@ namespace Kyoo
|
|||||||
public DbSet<Track> Tracks { get; set; }
|
public DbSet<Track> Tracks { get; set; }
|
||||||
public DbSet<Genre> Genres { get; set; }
|
public DbSet<Genre> Genres { get; set; }
|
||||||
public DbSet<People> Peoples { get; set; }
|
public DbSet<People> Peoples { get; set; }
|
||||||
public DbSet<PeopleLink> PeopleLinks { get; set; }
|
|
||||||
public DbSet<Studio> Studios { 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>(
|
private ValueConverter<string[], string> stringArrayConverter = new ValueConverter<string[], string>(
|
||||||
arr => string.Join("|", arr),
|
arr => string.Join("|", arr),
|
||||||
str => str.Split("|", StringSplitOptions.None));
|
str => str.Split("|", StringSplitOptions.None));
|
||||||
@ -38,16 +41,6 @@ namespace Kyoo
|
|||||||
modelBuilder.Entity<Library>().Property(e => e.Providers).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<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>()
|
modelBuilder.Entity<Track>()
|
||||||
.Property(t => t.IsDefault)
|
.Property(t => t.IsDefault)
|
||||||
.ValueGeneratedNever();
|
.ValueGeneratedNever();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Kyoo.Controllers;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
@ -9,28 +9,28 @@ namespace Kyoo.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class EpisodesController : ControllerBase
|
public class EpisodesController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ILibraryManager libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public EpisodesController(ILibraryManager libraryManager)
|
public EpisodesController(ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
this.libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{showSlug}/season/{seasonNumber}")]
|
[HttpGet("{showSlug}/season/{seasonNumber}")]
|
||||||
public ActionResult<IEnumerable<Episode>> GetEpisodesForSeason(string showSlug, long 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)
|
if(episodes == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
return episodes;
|
return episodes.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{showSlug}/season/{seasonNumber}/episode/{episodeNumber}")]
|
[HttpGet("{showSlug}/season/{seasonNumber}/episode/{episodeNumber}")]
|
||||||
public ActionResult<Episode> GetEpisode(string showSlug, long seasonNumber, long 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)
|
if (episode == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
@ -9,28 +10,28 @@ namespace Kyoo.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class LibrariesController : ControllerBase
|
public class LibrariesController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ILibraryManager libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public LibrariesController(ILibraryManager libraryManager)
|
public LibrariesController(ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
this.libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IEnumerable<Library> GetLibraries()
|
public IEnumerable<Library> GetLibraries()
|
||||||
{
|
{
|
||||||
return libraryManager.GetLibraries();
|
return _libraryManager.GetLibraries();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{librarySlug}")]
|
[HttpGet("{librarySlug}")]
|
||||||
public ActionResult<IEnumerable<Show>> GetShows(string librarySlug)
|
public ActionResult<IEnumerable<Show>> GetShows(string librarySlug)
|
||||||
{
|
{
|
||||||
Library library = libraryManager.GetLibrary(librarySlug);
|
Library library = _libraryManager.GetLibrary(librarySlug);
|
||||||
|
|
||||||
if (library == null)
|
if (library == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
return libraryManager.GetShowsInLibrary(library.Id);
|
return _libraryManager.GetShowsInLibrary(library.Id).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -65,7 +65,7 @@ namespace Kyoo.Controllers
|
|||||||
[HttpGet("extract/{showSlug}")]
|
[HttpGet("extract/{showSlug}")]
|
||||||
public async Task<string> ExtractSubtitle(string 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)
|
foreach (Episode episode in episodes)
|
||||||
{
|
{
|
||||||
libraryManager.ClearSubtitles(episode.Id);
|
libraryManager.ClearSubtitles(episode.Id);
|
||||||
|
@ -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>
|
|
Loading…
x
Reference in New Issue
Block a user