Implementing movies in the watch and video API

This commit is contained in:
Zoe Roux 2020-03-01 04:16:26 +01:00
parent f8b43be244
commit 2aea6e3a6b
6 changed files with 74 additions and 2 deletions

View File

@ -34,6 +34,7 @@ namespace Kyoo.Controllers
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);
WatchItem GetMovieWatchItem(string movieSlug);
People GetPeopleBySlug(string slug);
Genre GetGenreBySlug(string slug);
Studio GetStudioBySlug(string slug);

View File

@ -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;

View File

@ -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<PeopleLink> GetPeople(long showID)
{
return from link in _database.PeopleLinks where link.ShowID == showID select link;

View File

@ -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<IActionResult> 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<IActionResult> 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);
}
}
}

View File

@ -25,5 +25,15 @@ namespace Kyoo.Api
return item;
}
[HttpGet("{movieSlug}")]
public ActionResult<WatchItem> Index(string movieSlug)
{
WatchItem item = _libraryManager.GetMovieWatchItem(movieSlug);
if(item == null)
return NotFound();
return item;
}
}
}

@ -1 +1 @@
Subproject commit 86409d02221bc750609d212aea912a2e90758a59
Subproject commit cb75c389f2f5938c939b9567759f0919797f081a