From 2aea6e3a6bd5bedf23f0a8b39410fe50e8f52b26 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 1 Mar 2020 04:16:26 +0100 Subject: [PATCH] Implementing movies in the watch and video API --- Kyoo.Common/Controllers/ILibraryManager.cs | 1 + Kyoo.Common/Models/WatchItem.cs | 1 + Kyoo/Controllers/LibraryManager.cs | 25 ++++++++++++++- Kyoo/Views/API/VideoAPI.cs | 37 ++++++++++++++++++++++ Kyoo/Views/API/WatchAPI.cs | 10 ++++++ Kyoo/Views/WebClient | 2 +- 6 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index f1e4476b..ff59610d 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -34,6 +34,7 @@ namespace Kyoo.Controllers IEnumerable GetEpisodes(string showSlug, long seasonNumber); Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber); WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true); + WatchItem GetMovieWatchItem(string movieSlug); People GetPeopleBySlug(string slug); Genre GetGenreBySlug(string slug); Studio GetStudioBySlug(string slug); diff --git a/Kyoo.Common/Models/WatchItem.cs b/Kyoo.Common/Models/WatchItem.cs index 0e7dc99f..98c460e0 100644 --- a/Kyoo.Common/Models/WatchItem.cs +++ b/Kyoo.Common/Models/WatchItem.cs @@ -18,6 +18,7 @@ namespace Kyoo.Models [JsonIgnore] public string Path; public string PreviousEpisode; public Episode NextEpisode; + public bool IsMovie; public string Container; public Track Video; diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index a58e32a5..2dfd306c 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -1,4 +1,5 @@ -using Kyoo.Models; +using System; +using Kyoo.Models; using Kyoo.Models.Watch; using System.Collections.Generic; using System.Linq; @@ -165,6 +166,28 @@ namespace Kyoo.Controllers return item; } + public WatchItem GetMovieWatchItem(string movieSlug) + { + Show movie = _database.Shows.FirstOrDefault(x => x.Slug == movieSlug); + if (movie == null) + return null; + Episode episode = _database.Episodes.FirstOrDefault(x => x.ShowID == movie.ID); + if (episode == null) + return null; + WatchItem item = new WatchItem(movie.ID, + movie.Title, + movie.Slug, + -1, + -1, + movie.Title, + null, + episode.Path); + item.Link = movie.Slug; + item.IsMovie = true; + (item.Video, item.Audios, item.Subtitles) = GetStreams(item.EpisodeID, item.Link); + return item; + } + public IEnumerable GetPeople(long showID) { return from link in _database.PeopleLinks where link.ShowID == showID select link; diff --git a/Kyoo/Views/API/VideoAPI.cs b/Kyoo/Views/API/VideoAPI.cs index f8c5d5e8..57b833b5 100644 --- a/Kyoo/Views/API/VideoAPI.cs +++ b/Kyoo/Views/API/VideoAPI.cs @@ -66,5 +66,42 @@ namespace Kyoo.Api return PhysicalFile(path, "application/x-mpegURL ", true); return StatusCode(500); } + + + [HttpGet("{movieSlug}")] + public IActionResult Index(string movieSlug) + { + WatchItem episode = _libraryManager.GetMovieWatchItem(movieSlug); + + if (episode != null && System.IO.File.Exists(episode.Path)) + return PhysicalFile(episode.Path, "video/x-matroska", true); + return NotFound(); + } + + [HttpGet("transmux/{movieSlug}")] + public async Task Transmux(string movieSlug) + { + WatchItem episode = _libraryManager.GetMovieWatchItem(movieSlug); + + if (episode == null || !System.IO.File.Exists(episode.Path)) + return NotFound(); + string path = await _transcoder.Transmux(episode); + if (path != null) + return PhysicalFile(path, "application/x-mpegURL ", true); + return StatusCode(500); + } + + [HttpGet("transcode/{movieSlug}")] + public async Task Transcode(string movieSlug) + { + WatchItem episode = _libraryManager.GetMovieWatchItem(movieSlug); + + if (episode == null || !System.IO.File.Exists(episode.Path)) + return NotFound(); + string path = await _transcoder.Transcode(episode); + if (path != null) + return PhysicalFile(path, "application/x-mpegURL ", true); + return StatusCode(500); + } } } \ No newline at end of file diff --git a/Kyoo/Views/API/WatchAPI.cs b/Kyoo/Views/API/WatchAPI.cs index 28dde853..b6569c87 100644 --- a/Kyoo/Views/API/WatchAPI.cs +++ b/Kyoo/Views/API/WatchAPI.cs @@ -25,5 +25,15 @@ namespace Kyoo.Api return item; } + + [HttpGet("{movieSlug}")] + public ActionResult Index(string movieSlug) + { + WatchItem item = _libraryManager.GetMovieWatchItem(movieSlug); + + if(item == null) + return NotFound(); + return item; + } } } diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 86409d02..cb75c389 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 86409d02221bc750609d212aea912a2e90758a59 +Subproject commit cb75c389f2f5938c939b9567759f0919797f081a