mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-07 10:14:13 -04:00
Finishing the library support.
This commit is contained in:
parent
8b0dca8fbf
commit
8c7bdcebc6
@ -27,7 +27,7 @@ export class LibraryResolverService implements Resolve<Show[]>
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.http.get<Show[]>("api/library/" + slug).pipe(catchError((error: HttpErrorResponse) =>
|
||||
return this.http.get<Show[]>("api/libraries/" + slug).pipe(catchError((error: HttpErrorResponse) =>
|
||||
{
|
||||
console.log(error.status + " - " + error.message);
|
||||
if (error.status == 404)
|
||||
|
@ -21,5 +21,16 @@ namespace Kyoo.Controllers
|
||||
{
|
||||
return libraryManager.GetLibraries();
|
||||
}
|
||||
|
||||
[HttpGet("{librarySlug}")]
|
||||
public ActionResult<IEnumerable<Show>> GetShows(string librarySlug)
|
||||
{
|
||||
Library library = libraryManager.GetLibrary(librarySlug);
|
||||
|
||||
if (library == null)
|
||||
return NotFound();
|
||||
|
||||
return libraryManager.GetShowsInLibrary(library.id);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ namespace Kyoo.Controllers
|
||||
[HttpGet]
|
||||
public IEnumerable<Show> GetShows()
|
||||
{
|
||||
return libraryManager.QueryShows(null);
|
||||
return libraryManager.GetShows();
|
||||
}
|
||||
|
||||
[HttpGet("{slug}")]
|
||||
|
@ -8,7 +8,7 @@ namespace Kyoo.InternalAPI
|
||||
{
|
||||
//Read values
|
||||
string GetShowExternalIDs(long showID);
|
||||
IEnumerable<Show> QueryShows(string selection);
|
||||
IEnumerable<Show> GetShows();
|
||||
Studio GetStudio(long showID);
|
||||
List<People> GetDirectors(long showID);
|
||||
List<People> GetPeople(long showID);
|
||||
@ -16,6 +16,7 @@ namespace Kyoo.InternalAPI
|
||||
List<Season> GetSeasons(long showID);
|
||||
int GetSeasonCount(string showSlug, long seasonNumber);
|
||||
IEnumerable<Show> GetShowsInCollection(long collectionID);
|
||||
List<Show> GetShowsInLibrary(long libraryID);
|
||||
IEnumerable<Show> GetShowsByPeople(long peopleID);
|
||||
IEnumerable<string> GetLibrariesPath();
|
||||
|
||||
@ -24,6 +25,7 @@ namespace Kyoo.InternalAPI
|
||||
Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced);
|
||||
|
||||
//Public read
|
||||
Library GetLibrary(string librarySlug);
|
||||
IEnumerable<Library> GetLibraries();
|
||||
Show GetShowBySlug(string slug);
|
||||
Season GetSeason(string showSlug, long seasonNumber);
|
||||
|
@ -271,7 +271,23 @@ namespace Kyoo.InternalAPI
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<Show> QueryShows(string selection)
|
||||
public Library GetLibrary(string librarySlug)
|
||||
{
|
||||
string query = "SELECT * FROM libraries WHERE slug = $slug;";
|
||||
|
||||
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()
|
||||
{
|
||||
List<Show> shows = new List<Show>();
|
||||
SQLiteDataReader reader;
|
||||
@ -580,6 +596,22 @@ namespace Kyoo.InternalAPI
|
||||
}
|
||||
}
|
||||
|
||||
public List<Show> GetShowsInLibrary(long libraryID)
|
||||
{
|
||||
List<Show> shows = new List<Show>();
|
||||
SQLiteDataReader reader;
|
||||
string query = "SELECT id, slug, title, startYear, endYear, '0' FROM (SELECT id, slug, title, startYear, endYear, '0' FROM shows JOIN librariesLinks lb ON lb.showID = id WHERE lb.libraryID = $libraryID) LEFT JOIN collectionsLinks l ON l.showID = id WHERE l.showID IS NULL UNION SELECT id, slug, name, startYear, endYear, '1' FROM collections JOIN collectionsLinks l ON l.collectionID = collections.id JOIN librariesLinks lb ON lb.showID = l.showID WHERE lb.libraryID = $libraryID ORDER BY title;";
|
||||
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("$libraryID", libraryID);
|
||||
reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
shows.Add(Show.FromQueryReader(reader));
|
||||
}
|
||||
return shows;
|
||||
}
|
||||
|
||||
public IEnumerable<Show> GetShowsByPeople(long peopleID)
|
||||
{
|
||||
string query = "SELECT * FROM shows JOIN peopleLinks l ON l.showID = shows.id WHERE l.peopleID = $id;";
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public struct Library
|
||||
public class Library
|
||||
{
|
||||
[JsonIgnore] public readonly long id;
|
||||
public string Slug;
|
||||
|
@ -99,7 +99,7 @@ namespace Kyoo.Models
|
||||
Title = reader["title"] as string,
|
||||
StartYear = reader["startYear"] as long?,
|
||||
EndYear = reader["endYear"] as long?,
|
||||
IsCollection = reader[4] as string == "1"
|
||||
IsCollection = reader["'0'"] as string == "1"
|
||||
};
|
||||
}
|
||||
|
||||
|
26
Unit Tests/Kyoo-InternalAPI/Library-Tests.cs
Normal file
26
Unit Tests/Kyoo-InternalAPI/Library-Tests.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Kyoo.InternalAPI;
|
||||
using Kyoo.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnitTests.Kyoo_InternalAPI
|
||||
{
|
||||
public class LibraryTests
|
||||
{
|
||||
private IConfiguration config;
|
||||
private ILibraryManager libraryManager;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
libraryManager = new LibraryManager(config);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
using Kyoo;
|
||||
using Kyoo.InternalAPI;
|
||||
using Kyoo.InternalAPI;
|
||||
using Kyoo.InternalAPI.ThumbnailsManager;
|
||||
using Kyoo.Models;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NUnit.Framework;
|
||||
using System.Diagnostics;
|
||||
@ -12,7 +10,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace UnitTests.Kyoo_InternalAPI
|
||||
{
|
||||
public class Tests
|
||||
public class ThumbnailsTests
|
||||
{
|
||||
private IConfiguration config;
|
||||
|
||||
@ -29,7 +27,7 @@ namespace UnitTests.Kyoo_InternalAPI
|
||||
{
|
||||
LibraryManager library = new LibraryManager(config);
|
||||
ThumbnailsManager manager = new ThumbnailsManager(config);
|
||||
Show show = library.GetShowBySlug(library.QueryShows(null).FirstOrDefault().Slug);
|
||||
Show show = library.GetShowBySlug(library.GetShows().FirstOrDefault().Slug);
|
||||
Debug.WriteLine("&Show: " + show.Path);
|
||||
string posterPath = Path.Combine(show.Path, "poster.jpg");
|
||||
File.Delete(posterPath);
|
||||
|
Loading…
x
Reference in New Issue
Block a user