mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Implemnting relational data loading inside the repositories
This commit is contained in:
parent
b3847a5bc5
commit
c5b0858d4a
@ -13,11 +13,21 @@ namespace Kyoo.Controllers
|
|||||||
Task<Season> GetSeason(string showSlug, long seasonNumber);
|
Task<Season> GetSeason(string showSlug, long seasonNumber);
|
||||||
Task<Episode> GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
|
Task<Episode> GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
|
||||||
Task<Episode> GetMovieEpisode(string movieSlug);
|
Task<Episode> GetMovieEpisode(string movieSlug);
|
||||||
|
Task<Track> GetTrack(long id);
|
||||||
Task<Track> GetTrack(long episodeID, string language, bool isForced);
|
Task<Track> GetTrack(long episodeID, string language, bool isForced);
|
||||||
Task<Genre> GetGenre(string slug);
|
Task<Genre> GetGenre(string slug);
|
||||||
Task<Studio> GetStudio(string slug);
|
Task<Studio> GetStudio(string slug);
|
||||||
Task<People> GetPeople(string slug);
|
Task<People> GetPeople(string slug);
|
||||||
|
|
||||||
|
// Get by relations
|
||||||
|
Task<IEnumerable<Season>> GetSeasons(long showID);
|
||||||
|
Task<IEnumerable<Season>> GetSeasons(string showSlug);
|
||||||
|
|
||||||
|
Task<IEnumerable<Episode>> GetEpisodes(long showID, long seasonNumber);
|
||||||
|
Task<IEnumerable<Episode>> GetEpisodes(string showSlug, long seasonNumber);
|
||||||
|
Task<IEnumerable<Episode>> GetEpisodes(long seasonID);
|
||||||
|
|
||||||
|
|
||||||
// Get all
|
// Get all
|
||||||
Task<IEnumerable<Library>> GetLibraries();
|
Task<IEnumerable<Library>> GetLibraries();
|
||||||
Task<IEnumerable<Collection>> GetCollections();
|
Task<IEnumerable<Collection>> GetCollections();
|
||||||
|
@ -22,11 +22,18 @@ namespace Kyoo.Controllers
|
|||||||
public interface ISeasonRepository : IRepository<Season>
|
public interface ISeasonRepository : IRepository<Season>
|
||||||
{
|
{
|
||||||
Task<Season> Get(string showSlug, long seasonNumber);
|
Task<Season> Get(string showSlug, long seasonNumber);
|
||||||
|
|
||||||
|
Task<IEnumerable<Season>> GetSeasons(long showID);
|
||||||
|
Task<IEnumerable<Season>> GetSeasons(string showSlug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IEpisodeRepository : IRepository<Episode>
|
public interface IEpisodeRepository : IRepository<Episode>
|
||||||
{
|
{
|
||||||
Task<Episode> Get(string showSlug, long seasonNumber, long episodeNumber);
|
Task<Episode> Get(string showSlug, long seasonNumber, long episodeNumber);
|
||||||
|
|
||||||
|
Task<IEnumerable<Episode>> GetEpisodes(long showID, long seasonNumber);
|
||||||
|
Task<IEnumerable<Episode>> GetEpisodes(string showSlug, long seasonNumber);
|
||||||
|
Task<IEnumerable<Episode>> GetEpisodes(long seasonID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ITrackRepository : IRepository<Track>
|
public interface ITrackRepository : IRepository<Track>
|
||||||
|
@ -61,6 +61,11 @@ namespace Kyoo.Controllers
|
|||||||
return _episodes.Get(movieSlug);
|
return _episodes.Get(movieSlug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Track> GetTrack(long id)
|
||||||
|
{
|
||||||
|
return _tracks.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<Track> GetTrack(long episodeID, string language, bool isForced)
|
public Task<Track> GetTrack(long episodeID, string language, bool isForced)
|
||||||
{
|
{
|
||||||
return _tracks.Get(episodeID, language, isForced);
|
return _tracks.Get(episodeID, language, isForced);
|
||||||
@ -131,6 +136,31 @@ namespace Kyoo.Controllers
|
|||||||
return _providers.GetAll();
|
return _providers.GetAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<Season>> GetSeasons(long showID)
|
||||||
|
{
|
||||||
|
return _seasons.GetSeasons(showID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<Season>> GetSeasons(string showSlug)
|
||||||
|
{
|
||||||
|
return _seasons.GetSeasons(showSlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<Episode>> GetEpisodes(long showID, long seasonNumber)
|
||||||
|
{
|
||||||
|
return _episodes.GetEpisodes(showID, seasonNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<Episode>> GetEpisodes(string showSlug, long seasonNumber)
|
||||||
|
{
|
||||||
|
return _episodes.GetEpisodes(showSlug, seasonNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<Episode>> GetEpisodes(long seasonID)
|
||||||
|
{
|
||||||
|
return _episodes.GetEpisodes(seasonID);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<IEnumerable<Library>> SearchLibraries(string searchQuery)
|
public Task<IEnumerable<Library>> SearchLibraries(string searchQuery)
|
||||||
{
|
{
|
||||||
return _libraries.Search(searchQuery);
|
return _libraries.Search(searchQuery);
|
||||||
|
@ -45,7 +45,7 @@ namespace Kyoo.Controllers
|
|||||||
&& x.SeasonNumber == seasonNumber
|
&& x.SeasonNumber == seasonNumber
|
||||||
&& x.EpisodeNumber == episodeNumber);
|
&& x.EpisodeNumber == episodeNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Episode>> Search(string query)
|
public async Task<IEnumerable<Episode>> Search(string query)
|
||||||
{
|
{
|
||||||
return await _database.Episodes
|
return await _database.Episodes
|
||||||
@ -119,5 +119,22 @@ namespace Kyoo.Controllers
|
|||||||
_database.Episodes.Remove(obj);
|
_database.Episodes.Remove(obj);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Episode>> GetEpisodes(long showID, long seasonNumber)
|
||||||
|
{
|
||||||
|
return await _database.Episodes.Where(x => x.ShowID == showID
|
||||||
|
&& x.SeasonNumber == seasonNumber).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Episode>> GetEpisodes(string showSlug, long seasonNumber)
|
||||||
|
{
|
||||||
|
return await _database.Episodes.Where(x => x.Show.Slug == showSlug
|
||||||
|
&& x.SeasonNumber == seasonNumber).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Episode>> GetEpisodes(long seasonID)
|
||||||
|
{
|
||||||
|
return await _database.Episodes.Where(x => x.SeasonID == seasonID).ToListAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -115,5 +115,15 @@ namespace Kyoo.Controllers
|
|||||||
_database.Seasons.Remove(obj);
|
_database.Seasons.Remove(obj);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Season>> GetSeasons(long showID)
|
||||||
|
{
|
||||||
|
return await _database.Seasons.Where(x => x.ShowID == showID).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Season>> GetSeasons(string showSlug)
|
||||||
|
{
|
||||||
|
return await _database.Seasons.Where(x => x.Show.Slug == showSlug).ToListAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -62,7 +62,7 @@ namespace Kyoo.Tasks
|
|||||||
edited.ID = old.ID;
|
edited.ID = old.ID;
|
||||||
edited.Slug = old.Slug;
|
edited.Slug = old.Slug;
|
||||||
edited.Path = old.Path;
|
edited.Path = old.Path;
|
||||||
await libraryManager.Edit(edited, true);
|
await libraryManager.EditShow(edited, true);
|
||||||
await _thumbnailsManager.Validate(edited, true);
|
await _thumbnailsManager.Validate(edited, true);
|
||||||
}
|
}
|
||||||
if (old.Seasons != null)
|
if (old.Seasons != null)
|
||||||
@ -95,7 +95,7 @@ namespace Kyoo.Tasks
|
|||||||
Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
|
Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
|
||||||
Season edited = await _providerManager.GetSeason(show, old.SeasonNumber, library);
|
Season edited = await _providerManager.GetSeason(show, old.SeasonNumber, library);
|
||||||
edited.ID = old.ID;
|
edited.ID = old.ID;
|
||||||
await libraryManager.Edit(edited, true);
|
await libraryManager.EditSeason(edited, true);
|
||||||
await _thumbnailsManager.Validate(edited, true);
|
await _thumbnailsManager.Validate(edited, true);
|
||||||
}
|
}
|
||||||
if (old.Episodes != null)
|
if (old.Episodes != null)
|
||||||
@ -110,7 +110,7 @@ namespace Kyoo.Tasks
|
|||||||
Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
|
Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
|
||||||
Episode edited = await _providerManager.GetEpisode(show, old.Path, old.SeasonNumber, old.EpisodeNumber, old.AbsoluteNumber, library);
|
Episode edited = await _providerManager.GetEpisode(show, old.Path, old.SeasonNumber, old.EpisodeNumber, old.AbsoluteNumber, library);
|
||||||
edited.ID = old.ID;
|
edited.ID = old.ID;
|
||||||
await libraryManager.Edit(edited, true);
|
await libraryManager.EditEpisode(edited, true);
|
||||||
await _thumbnailsManager.Validate(edited, true);
|
await _thumbnailsManager.Validate(edited, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
@ -19,9 +20,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{collectionSlug}")]
|
[HttpGet("{collectionSlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<Collection> GetShows(string collectionSlug)
|
public async Task<ActionResult<Collection>> GetShows(string collectionSlug)
|
||||||
{
|
{
|
||||||
Collection collection = _libraryManager.GetCollection(collectionSlug);
|
Collection collection = await _libraryManager.GetCollection(collectionSlug);
|
||||||
|
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
@ -20,9 +21,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{showSlug}/season/{seasonNumber}")]
|
[HttpGet("{showSlug}/season/{seasonNumber}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<IEnumerable<Episode>> GetEpisodesForSeason(string showSlug, long seasonNumber)
|
public async Task<ActionResult<IEnumerable<Episode>>> GetEpisodesForSeason(string showSlug, long seasonNumber)
|
||||||
{
|
{
|
||||||
IEnumerable<Episode> episodes = _libraryManager.GetEpisodes(showSlug, seasonNumber);
|
IEnumerable<Episode> episodes = await _libraryManager.GetEpisodes(showSlug, seasonNumber);
|
||||||
|
|
||||||
if(episodes == null)
|
if(episodes == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -33,9 +34,9 @@ namespace Kyoo.Api
|
|||||||
[HttpGet("{showSlug}/season/{seasonNumber}/episode/{episodeNumber}")]
|
[HttpGet("{showSlug}/season/{seasonNumber}/episode/{episodeNumber}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
[JsonDetailed]
|
[JsonDetailed]
|
||||||
public ActionResult<Episode> GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<ActionResult<Episode>> GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
Episode episode = await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
|
|
||||||
if (episode == null)
|
if (episode == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -18,9 +19,9 @@ namespace Kyoo.API
|
|||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<IEnumerable<Genre>> Index()
|
public async Task<ActionResult<IEnumerable<Genre>>> Index()
|
||||||
{
|
{
|
||||||
return _libraryManager.GetGenres().ToList();
|
return (await _libraryManager.GetGenres()).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ using Kyoo.Models;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
@ -22,15 +23,15 @@ namespace Kyoo.Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IEnumerable<Library> GetLibraries()
|
public async Task<IEnumerable<Library>> GetLibraries()
|
||||||
{
|
{
|
||||||
return _libraryManager.GetLibraries();
|
return await _libraryManager.GetLibraries();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("/api/library/create")]
|
[Route("/api/library/create")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Policy="Admin")]
|
[Authorize(Policy="Admin")]
|
||||||
public IActionResult CreateLibrary([FromBody] Library library)
|
public async Task<IActionResult> CreateLibrary([FromBody] Library library)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(library);
|
return BadRequest(library);
|
||||||
@ -42,17 +43,16 @@ namespace Kyoo.Api
|
|||||||
return BadRequest(new {error = "The library should have a least one path."});
|
return BadRequest(new {error = "The library should have a least one path."});
|
||||||
if (_libraryManager.GetLibrary(library.Slug) != null)
|
if (_libraryManager.GetLibrary(library.Slug) != null)
|
||||||
return BadRequest(new {error = "Duplicated library slug"});
|
return BadRequest(new {error = "Duplicated library slug"});
|
||||||
_libraryManager.Register(library);
|
await _libraryManager.RegisterLibrary(library);
|
||||||
_libraryManager.SaveChanges();
|
|
||||||
_taskManager.StartTask("scan", library.Slug);
|
_taskManager.StartTask("scan", library.Slug);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{librarySlug}")]
|
[HttpGet("{librarySlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<IEnumerable<Show>> GetShows(string librarySlug)
|
public async Task<ActionResult<IEnumerable<Show>>> GetShows(string librarySlug)
|
||||||
{
|
{
|
||||||
Library library = _libraryManager.GetLibrary(librarySlug);
|
Library library = await _libraryManager.GetLibrary(librarySlug);
|
||||||
|
|
||||||
if (library == null)
|
if (library == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -19,9 +20,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{peopleSlug}")]
|
[HttpGet("{peopleSlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<Collection> GetPeople(string peopleSlug)
|
public async Task<ActionResult<Collection>> GetPeople(string peopleSlug)
|
||||||
{
|
{
|
||||||
People people = _libraryManager.GetPeople(peopleSlug);
|
People people = await _libraryManager.GetPeople(peopleSlug);
|
||||||
|
|
||||||
if (people == null)
|
if (people == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Kyoo.Controllers;
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -18,17 +19,17 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{query}")]
|
[HttpGet("{query}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<SearchResult> Search(string query)
|
public async Task<ActionResult<SearchResult>> Search(string query)
|
||||||
{
|
{
|
||||||
SearchResult result = new SearchResult
|
SearchResult result = new SearchResult
|
||||||
{
|
{
|
||||||
Query = query,
|
Query = query,
|
||||||
Collections = _libraryManager.SearchCollections(query),
|
Collections = await _libraryManager.SearchCollections(query),
|
||||||
Shows = _libraryManager.SearchShows(query),
|
Shows = await _libraryManager.SearchShows(query),
|
||||||
Episodes = _libraryManager.SearchEpisodes(query),
|
Episodes = await _libraryManager.SearchEpisodes(query),
|
||||||
People = _libraryManager.SearchPeople(query),
|
People = await _libraryManager.SearchPeople(query),
|
||||||
Genres = _libraryManager.SearchGenres(query),
|
Genres = await _libraryManager.SearchGenres(query),
|
||||||
Studios = _libraryManager.SearchStudios(query)
|
Studios = await _libraryManager.SearchStudios(query)
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,9 @@ namespace Kyoo.Api
|
|||||||
[HttpGet("{slug}")]
|
[HttpGet("{slug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
[JsonDetailed]
|
[JsonDetailed]
|
||||||
public ActionResult<Show> GetShow(string slug)
|
public async Task<ActionResult<Show>> GetShow(string slug)
|
||||||
{
|
{
|
||||||
Show show = _libraryManager.GetShow(slug);
|
Show show = await _libraryManager.GetShow(slug);
|
||||||
|
|
||||||
if (show == null)
|
if (show == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -55,7 +55,7 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpPost("edit/{slug}")]
|
[HttpPost("edit/{slug}")]
|
||||||
[Authorize(Policy="Write")]
|
[Authorize(Policy="Write")]
|
||||||
public IActionResult EditShow(string slug, [FromBody] Show show)
|
public async Task<IActionResult> EditShow(string slug, [FromBody] Show show)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(show);
|
return BadRequest(show);
|
||||||
@ -66,7 +66,7 @@ namespace Kyoo.Api
|
|||||||
show.ID = old.ID;
|
show.ID = old.ID;
|
||||||
show.Slug = slug;
|
show.Slug = slug;
|
||||||
show.Path = old.Path;
|
show.Path = old.Path;
|
||||||
_libraryManager.Edit(show, false);
|
await _libraryManager.EditShow(show, false);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,6 @@ namespace Kyoo.Api
|
|||||||
Show show = _database.Shows.Include(x => x.ExternalIDs).FirstOrDefault(x => x.Slug == slug);
|
Show show = _database.Shows.Include(x => x.ExternalIDs).FirstOrDefault(x => x.Slug == slug);
|
||||||
if (show == null)
|
if (show == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
show.ExternalIDs = _libraryManager.Validate(externalIDs);
|
|
||||||
_database.SaveChanges();
|
_database.SaveChanges();
|
||||||
_taskManager.StartTask("re-scan", $"show/{slug}");
|
_taskManager.StartTask("re-scan", $"show/{slug}");
|
||||||
return Ok();
|
return Ok();
|
||||||
@ -96,7 +95,7 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy = "Write")]
|
[Authorize(Policy = "Write")]
|
||||||
public async Task<IActionResult> DownloadImages(string slug)
|
public async Task<IActionResult> DownloadImages(string slug)
|
||||||
{
|
{
|
||||||
Show show = _libraryManager.GetShow(slug);
|
Show show = await _libraryManager.GetShow(slug);
|
||||||
if (show == null)
|
if (show == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
await _thumbnailsManager.Validate(show, true);
|
await _thumbnailsManager.Validate(show, true);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -18,9 +19,9 @@ namespace Kyoo.API
|
|||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<IEnumerable<Studio>> Index()
|
public async Task<ActionResult<IEnumerable<Studio>>> Index()
|
||||||
{
|
{
|
||||||
return _libraryManager.GetStudios().ToList();
|
return (await _libraryManager.GetStudios()).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,31 +14,37 @@ namespace Kyoo.Api
|
|||||||
public class SubtitleController : ControllerBase
|
public class SubtitleController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ITranscoder _transcoder;
|
//private readonly ITranscoder _transcoder;
|
||||||
|
|
||||||
public SubtitleController(ILibraryManager libraryManager, ITranscoder transcoder)
|
public SubtitleController(ILibraryManager libraryManager/*, ITranscoder transcoder*/)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_transcoder = transcoder;
|
// _transcoder = transcoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}.{identifier}.{extension?}")]
|
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}.{identifier}.{extension?}")]
|
||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public IActionResult GetSubtitle(string showSlug, int seasonNumber, int episodeNumber, string identifier, string extension)
|
public async Task<IActionResult> GetSubtitle(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
string identifier,
|
||||||
|
string extension)
|
||||||
{
|
{
|
||||||
string languageTag = identifier.Length == 3 ? identifier.Substring(0, 3) : null;
|
string languageTag = identifier.Length == 3 ? identifier.Substring(0, 3) : null;
|
||||||
bool forced = identifier.Length > 4 && identifier.Substring(4) == "forced";
|
bool forced = identifier.Length > 4 && identifier.Substring(4) == "forced";
|
||||||
Track subtitle = null;
|
Track subtitle = null;
|
||||||
|
|
||||||
if (languageTag != null)
|
if (languageTag != null)
|
||||||
subtitle = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber)?.Tracks
|
subtitle = (await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber))?.Tracks
|
||||||
.FirstOrDefault(x => x.Language == languageTag && x.IsForced == forced);
|
.FirstOrDefault(x => x.Language == languageTag && x.IsForced == forced);
|
||||||
|
|
||||||
if (subtitle == null)
|
if (subtitle == null)
|
||||||
{
|
{
|
||||||
string idString = identifier.IndexOf('-') != -1 ? identifier.Substring(0, identifier.IndexOf('-')) : identifier;
|
string idString = identifier.IndexOf('-') != -1
|
||||||
|
? identifier.Substring(0, identifier.IndexOf('-'))
|
||||||
|
: identifier;
|
||||||
long.TryParse(idString, out long id);
|
long.TryParse(idString, out long id);
|
||||||
subtitle = _libraryManager.GetTracks().FirstOrDefault(x => x.ID == id);
|
subtitle = await _libraryManager.GetTrack(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtitle == null)
|
if (subtitle == null)
|
||||||
@ -57,43 +63,43 @@ namespace Kyoo.Api
|
|||||||
return PhysicalFile(subtitle.Path, mime);
|
return PhysicalFile(subtitle.Path, mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("extract/{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
// [HttpGet("extract/{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
||||||
[Authorize(Policy="Admin")]
|
// [Authorize(Policy="Admin")]
|
||||||
public async Task<string> ExtractSubtitle(string showSlug, long seasonNumber, long episodeNumber)
|
// public async Task<string> ExtractSubtitle(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
// {
|
||||||
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
// Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
episode.Tracks = null;
|
// episode.Tracks = null;
|
||||||
|
//
|
||||||
Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
// Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
||||||
foreach (Track track in tracks)
|
// foreach (Track track in tracks)
|
||||||
{
|
// {
|
||||||
track.EpisodeID = episode.ID;
|
// track.EpisodeID = episode.ID;
|
||||||
_libraryManager.Register(track);
|
// _libraryManager.Register(track);
|
||||||
}
|
// }
|
||||||
await _libraryManager.SaveChanges();
|
// await _libraryManager.SaveChanges();
|
||||||
return "Done. " + tracks.Length + " track(s) extracted.";
|
// return "Done. " + tracks.Length + " track(s) extracted.";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
[HttpGet("extract/{showSlug}")]
|
// [HttpGet("extract/{showSlug}")]
|
||||||
[Authorize(Policy="Admin")]
|
// [Authorize(Policy="Admin")]
|
||||||
public async Task<string> ExtractSubtitle(string showSlug)
|
// public async Task<string> ExtractSubtitle(string showSlug)
|
||||||
{
|
// {
|
||||||
IEnumerable<Episode> episodes = _libraryManager.GetShow(showSlug).Episodes;
|
// IEnumerable<Episode> episodes = _libraryManager.GetShow(showSlug).Episodes;
|
||||||
foreach (Episode episode in episodes)
|
// foreach (Episode episode in episodes)
|
||||||
{
|
// {
|
||||||
episode.Tracks = null;
|
// episode.Tracks = null;
|
||||||
|
//
|
||||||
Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
// Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path);
|
||||||
foreach (Track track in tracks)
|
// foreach (Track track in tracks)
|
||||||
{
|
// {
|
||||||
track.EpisodeID = episode.ID;
|
// track.EpisodeID = episode.ID;
|
||||||
_libraryManager.Register(track);
|
// _libraryManager.Register(track);
|
||||||
}
|
// }
|
||||||
await _libraryManager.SaveChanges();
|
// await _libraryManager.SaveChanges();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return "Done.";
|
// return "Done.";
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
@ -20,9 +21,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("poster/{showSlug}")]
|
[HttpGet("poster/{showSlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public IActionResult GetShowThumb(string showSlug)
|
public async Task<IActionResult> GetShowThumb(string showSlug)
|
||||||
{
|
{
|
||||||
string path = _libraryManager.GetShow(showSlug)?.Path;
|
string path = (await _libraryManager.GetShow(showSlug))?.Path;
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
@ -35,9 +36,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("logo/{showSlug}")]
|
[HttpGet("logo/{showSlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public IActionResult GetShowLogo(string showSlug)
|
public async Task<IActionResult> GetShowLogo(string showSlug)
|
||||||
{
|
{
|
||||||
string path = _libraryManager.GetShow(showSlug)?.Path;
|
string path = (await _libraryManager.GetShow(showSlug))?.Path;
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
@ -50,9 +51,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("backdrop/{showSlug}")]
|
[HttpGet("backdrop/{showSlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public IActionResult GetShowBackdrop(string showSlug)
|
public async Task<IActionResult> GetShowBackdrop(string showSlug)
|
||||||
{
|
{
|
||||||
string path = _libraryManager.GetShow(showSlug)?.Path;
|
string path = (await _libraryManager.GetShow(showSlug))?.Path;
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
@ -76,9 +77,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("thumb/{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
[HttpGet("thumb/{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public IActionResult GetEpisodeThumb(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<IActionResult> GetEpisodeThumb(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
string path = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber)?.Path;
|
string path = (await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber))?.Path;
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
[HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public IActionResult Index(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<IActionResult> Index(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
Episode episode = await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
|
|
||||||
if (episode != null && System.IO.File.Exists(episode.Path))
|
if (episode != null && System.IO.File.Exists(episode.Path))
|
||||||
return PhysicalFile(episode.Path, "video/x-matroska", true);
|
return PhysicalFile(episode.Path, "video/x-matroska", true);
|
||||||
@ -40,7 +40,7 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public async Task<IActionResult> Transmux(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<IActionResult> Transmux(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
Episode episode = await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
|
|
||||||
if (episode == null || !System.IO.File.Exists(episode.Path))
|
if (episode == null || !System.IO.File.Exists(episode.Path))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -63,7 +63,7 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public async Task<IActionResult> Transcode(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<IActionResult> Transcode(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
Episode episode = await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
|
|
||||||
if (episode == null || !System.IO.File.Exists(episode.Path))
|
if (episode == null || !System.IO.File.Exists(episode.Path))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -85,9 +85,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{movieSlug}")]
|
[HttpGet("{movieSlug}")]
|
||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public IActionResult Index(string movieSlug)
|
public async Task<IActionResult> Index(string movieSlug)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetMovieEpisode(movieSlug);
|
Episode episode = await _libraryManager.GetMovieEpisode(movieSlug);
|
||||||
|
|
||||||
if (episode != null && System.IO.File.Exists(episode.Path))
|
if (episode != null && System.IO.File.Exists(episode.Path))
|
||||||
return PhysicalFile(episode.Path, "video/webm", true);
|
return PhysicalFile(episode.Path, "video/webm", true);
|
||||||
@ -98,7 +98,7 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public async Task<IActionResult> Transmux(string movieSlug)
|
public async Task<IActionResult> Transmux(string movieSlug)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetMovieEpisode(movieSlug);
|
Episode episode = await _libraryManager.GetMovieEpisode(movieSlug);
|
||||||
|
|
||||||
if (episode == null || !System.IO.File.Exists(episode.Path))
|
if (episode == null || !System.IO.File.Exists(episode.Path))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -112,7 +112,7 @@ namespace Kyoo.Api
|
|||||||
[Authorize(Policy="Play")]
|
[Authorize(Policy="Play")]
|
||||||
public async Task<IActionResult> Transcode(string movieSlug)
|
public async Task<IActionResult> Transcode(string movieSlug)
|
||||||
{
|
{
|
||||||
Episode episode = _libraryManager.GetMovieEpisode(movieSlug);
|
Episode episode = await _libraryManager.GetMovieEpisode(movieSlug);
|
||||||
|
|
||||||
if (episode == null || !System.IO.File.Exists(episode.Path))
|
if (episode == null || !System.IO.File.Exists(episode.Path))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Kyoo.Controllers;
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -18,9 +19,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
[HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<WatchItem> Index(string showSlug, long seasonNumber, long episodeNumber)
|
public async Task<ActionResult<WatchItem>> Index(string showSlug, long seasonNumber, long episodeNumber)
|
||||||
{
|
{
|
||||||
Episode item = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
Episode item = await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
||||||
|
|
||||||
if(item == null)
|
if(item == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -30,9 +31,9 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
[HttpGet("{movieSlug}")]
|
[HttpGet("{movieSlug}")]
|
||||||
[Authorize(Policy="Read")]
|
[Authorize(Policy="Read")]
|
||||||
public ActionResult<WatchItem> Index(string movieSlug)
|
public async Task<ActionResult<WatchItem>> Index(string movieSlug)
|
||||||
{
|
{
|
||||||
Episode item = _libraryManager.GetMovieEpisode(movieSlug);
|
Episode item = await _libraryManager.GetMovieEpisode(movieSlug);
|
||||||
|
|
||||||
if(item == null)
|
if(item == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user