Making transcoder/transmuxer not throw when there was no read/write permissions given

This commit is contained in:
Zoe Roux 2019-12-29 05:57:18 +01:00
parent 877bebb0cb
commit 7e13e2c5c5
3 changed files with 68 additions and 23 deletions

View File

@ -1,3 +1,4 @@
using System;
using Kyoo.Models;
using Kyoo.InternalAPI.TranscoderLink;
using Microsoft.Extensions.Configuration;
@ -5,6 +6,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
#pragma warning disable 4014
namespace Kyoo.InternalAPI
{
@ -18,7 +20,7 @@ namespace Kyoo.InternalAPI
transmuxPath = config.GetValue<string>("transmuxTempPath");
transcodePath = config.GetValue<string>("transcodeTempPath");
Debug.WriteLine("&Api INIT (unmanaged stream size): " + TranscoderAPI.init() + ", Stream size: " + Marshal.SizeOf<Models.Watch.Stream>());
Console.WriteLine("&Api INIT (unmanaged stream size): " + TranscoderAPI.init() + ", Stream size: " + Marshal.SizeOf<Models.Watch.Stream>());
}
public async Task<Track[]> GetTrackInfo(string path)
@ -48,11 +50,19 @@ namespace Kyoo.InternalAPI
float playableDuration = 0;
bool transmuxFailed = false;
Directory.CreateDirectory(folder);
Debug.WriteLine("&Transmuxing " + episode.Link + " at " + episode.Path + ", outputPath: " + folder);
try
{
Directory.CreateDirectory(folder);
Debug.WriteLine("&Transmuxing " + episode.Link + " at " + episode.Path + ", outputPath: " + folder);
if (File.Exists(manifest))
return manifest;
if (File.Exists(manifest))
return manifest;
}
catch (UnauthorizedAccessException)
{
Console.Error.WriteLine($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
return null;
}
Task.Run(() =>
{
transmuxFailed = TranscoderAPI.transmux(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0;
@ -69,11 +79,20 @@ namespace Kyoo.InternalAPI
float playableDuration = 0;
bool transmuxFailed = false;
Directory.CreateDirectory(folder);
Debug.WriteLine("&Transcoding " + episode.Link + " at " + episode.Path + ", outputPath: " + folder);
try
{
Directory.CreateDirectory(folder);
Debug.WriteLine("&Transcoding " + episode.Link + " at " + episode.Path + ", outputPath: " + folder);
if (File.Exists(manifest))
return manifest;
}
catch (UnauthorizedAccessException)
{
Console.Error.WriteLine($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
return null;
}
if (File.Exists(manifest))
return manifest;
Task.Run(() =>
{
transmuxFailed = TranscoderAPI.transcode(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0;

View File

@ -27,7 +27,10 @@ namespace Kyoo.InternalAPI.TranscoderLink
private static extern IntPtr extract_subtitles(string path, string out_path, out int array_length, out int track_count);
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
private static extern void free_streams(IntPtr stream_ptr);
private static extern void free_streams(IntPtr stream_ptr);
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
private static extern void free(IntPtr ptr);
public static void GetTrackInfo(string path, out Track[] tracks)
@ -46,7 +49,7 @@ namespace Kyoo.InternalAPI.TranscoderLink
Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
if (stream.Type != StreamType.Unknow)
{
tracks[j] = (Track)stream;
tracks[j] = new Track(stream);
j++;
}
streamsPtr += size;
@ -55,8 +58,8 @@ namespace Kyoo.InternalAPI.TranscoderLink
else
tracks = null;
free_streams(ptr);
Debug.WriteLine("&" + tracks?.Length + " tracks got at: " + path);
free(ptr);
Console.WriteLine("&" + tracks?.Length + " tracks got at: " + path);
}
public static void ExtractSubtitles(string path, string outPath, out Track[] tracks)
@ -75,7 +78,7 @@ namespace Kyoo.InternalAPI.TranscoderLink
Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
if (stream.Type != StreamType.Unknow)
{
tracks[j] = (Track)stream;
tracks[j] = new Track(stream);
j++;
}
streamsPtr += size;
@ -84,8 +87,8 @@ namespace Kyoo.InternalAPI.TranscoderLink
else
tracks = null;
free_streams(ptr);
Debug.WriteLine("&" + tracks?.Length + " tracks got at: " + path);
free(ptr);
Console.WriteLine("&" + tracks?.Length + " tracks got at: " + path);
}
}
}

View File

@ -27,6 +27,29 @@ namespace Kyoo.Models
[MarshalAs(UnmanagedType.I1)] public bool IsForced;
[JsonIgnore] public string Path;
[JsonIgnore] public StreamType Type;
public Stream() {}
public Stream(string title, string language, string codec, bool isDefault, bool isForced, string path, StreamType type)
{
Title = title;
Language = language;
Codec = codec;
IsDefault = isDefault;
IsForced = isForced;
Path = path;
Type = type;
}
public Stream(Stream stream)
{
Title = stream.Title;
Language = stream.Language;
IsDefault = stream.IsDefault;
IsForced = stream.IsForced;
Codec = stream.Codec;
Type = stream.Type;
}
}
}
@ -39,15 +62,15 @@ namespace Kyoo.Models
[JsonIgnore] public bool IsExternal;
public Track(StreamType type, string title, string language, bool isDefault, bool isForced, string codec, bool isExternal, string path)
: base(title, language, codec, isDefault, isForced, path, type)
{
this.Type = type;
Title = title;
Language = language;
IsDefault = isDefault;
IsForced = isForced;
Codec = codec;
IsExternal = isExternal;
Path = path;
}
public Track(Stream stream)
: base(stream)
{
IsExternal = false;
}
public static Track FromReader(System.Data.SQLite.SQLiteDataReader reader)