Fixing authorization on the video API

This commit is contained in:
Zoe Roux 2020-04-01 02:57:58 +02:00
parent 906e0551e5
commit 10eb7d57a8
3 changed files with 20 additions and 8 deletions

View File

@ -20,8 +20,8 @@ namespace Kyoo.Controllers
public Transcoder(IConfiguration config) public Transcoder(IConfiguration config)
{ {
_transmuxPath = config.GetValue<string>("transmuxTempPath"); _transmuxPath = Path.GetFullPath(config.GetValue<string>("transmuxTempPath"));
_transcodePath = config.GetValue<string>("transcodeTempPath"); _transcodePath = Path.GetFullPath(config.GetValue<string>("transcodeTempPath"));
if (TranscoderAPI.init() != Marshal.SizeOf<Models.Watch.Stream>()) if (TranscoderAPI.init() != Marshal.SizeOf<Models.Watch.Stream>())
throw new BadTranscoderException(); throw new BadTranscoderException();
@ -78,10 +78,11 @@ namespace Kyoo.Controllers
public async Task<string> Transcode(WatchItem episode) public async Task<string> Transcode(WatchItem episode)
{ {
return null; // Not implemented yet.
string folder = Path.Combine(_transcodePath, episode.Link); string folder = Path.Combine(_transcodePath, episode.Link);
string manifest = Path.Combine(folder, episode.Link + ".m3u8"); string manifest = Path.Combine(folder, episode.Link + ".m3u8");
float playableDuration = 0; float playableDuration = 0;
bool transmuxFailed = false; bool transcodeFailed = false;
try try
{ {
@ -99,11 +100,11 @@ namespace Kyoo.Controllers
Task.Run(() => Task.Run(() =>
{ {
transmuxFailed = TranscoderAPI.transcode(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0; transcodeFailed = TranscoderAPI.transcode(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0;
}); });
while (playableDuration < 10 || (!File.Exists(manifest) && !transmuxFailed)) while (playableDuration < 10 || (!File.Exists(manifest) && !transcodeFailed))
await Task.Delay(10); await Task.Delay(10);
return transmuxFailed ? null : manifest; return transcodeFailed ? null : manifest;
} }
} }
} }

View File

@ -15,12 +15,14 @@ namespace Kyoo.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly ITranscoder _transcoder; private readonly ITranscoder _transcoder;
private readonly string _transmuxPath; private readonly string _transmuxPath;
private readonly string _transcodePath;
public VideoController(ILibraryManager libraryManager, ITranscoder transcoder, IConfiguration config) public VideoController(ILibraryManager libraryManager, ITranscoder transcoder, IConfiguration config)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_transcoder = transcoder; _transcoder = transcoder;
_transmuxPath = config.GetValue<string>("transmuxTempPath"); _transmuxPath = config.GetValue<string>("transmuxTempPath");
_transcodePath = config.GetValue<string>("transcodeTempPath");
} }
[HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")] [HttpGet("{showSlug}-s{seasonNumber}e{episodeNumber}")]
@ -51,7 +53,7 @@ namespace Kyoo.Api
[HttpGet("transmux/{episodeLink}/segment/{chunk}")] [HttpGet("transmux/{episodeLink}/segment/{chunk}")]
public IActionResult GetTransmuxedChunk(string episodeLink, string chunk) public IActionResult GetTransmuxedChunk(string episodeLink, string chunk)
{ {
string path = Path.Combine(_transmuxPath, episodeLink); string path = Path.GetFullPath(Path.Combine(_transmuxPath, episodeLink));
path = Path.Combine(path, "segments" + Path.DirectorySeparatorChar + chunk); path = Path.Combine(path, "segments" + Path.DirectorySeparatorChar + chunk);
return PhysicalFile(path, "video/MP2T"); return PhysicalFile(path, "video/MP2T");
@ -71,6 +73,15 @@ namespace Kyoo.Api
return StatusCode(500); return StatusCode(500);
} }
[HttpGet("transcode/{episodeLink}/segment/{chunk}")]
public IActionResult GetTranscodedChunk(string episodeLink, string chunk)
{
string path = Path.GetFullPath(Path.Combine(_transcodePath, episodeLink));
path = Path.Combine(path, "segments" + Path.DirectorySeparatorChar + chunk);
return PhysicalFile(path, "video/MP2T");
}
[HttpGet("{movieSlug}")] [HttpGet("{movieSlug}")]
[Authorize(Policy="Play")] [Authorize(Policy="Play")]

@ -1 +1 @@
Subproject commit a0f3da729cf4160d12f1b45d093b388c8e9f9199 Subproject commit ee72f573bd4815ebf7918e76a797310c140cf454