mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-09 00:24:17 -04:00
Test with a c style array.
This commit is contained in:
parent
1f5a589f96
commit
adc36d7579
@ -17,6 +17,9 @@ extern "C" struct Stream
|
|||||||
bool isForced;
|
bool isForced;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
|
Stream()
|
||||||
|
: title(NULL), language(NULL), codec(NULL), isDefault(NULL), isForced(NULL), path(NULL) {}
|
||||||
|
|
||||||
Stream(const char* title, const char* languageCode, const char* codec, bool isDefault, bool isForced, char* path)
|
Stream(const char* title, const char* languageCode, const char* codec, bool isDefault, bool isForced, char* path)
|
||||||
: title(title), language(languageCode), codec(codec), isDefault(isDefault), isForced(isForced), path(path) { }
|
: title(title), language(languageCode), codec(codec), isDefault(isDefault), isForced(isForced), path(path) { }
|
||||||
};
|
};
|
@ -200,14 +200,16 @@ int Transmux(const char *path, const char *outPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount)
|
Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount, int *subtitleCount)
|
||||||
{
|
{
|
||||||
AVFormatContext *inputContext = NULL;
|
AVFormatContext *inputContext = NULL;
|
||||||
|
|
||||||
if (open_input_context(&inputContext, path) != 0)
|
if (open_input_context(&inputContext, path) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
std::vector<Stream> *subtitleStreams = new std::vector<Stream>();
|
*streamCount = inputContext->nb_streams;
|
||||||
|
*subtitleCount = 0;
|
||||||
|
Stream *subtitleStreams = new Stream[*streamCount];
|
||||||
const unsigned int outputCount = inputContext->nb_streams;
|
const unsigned int outputCount = inputContext->nb_streams;
|
||||||
AVFormatContext **outputList = new AVFormatContext * [outputCount];
|
AVFormatContext **outputList = new AVFormatContext * [outputCount];
|
||||||
|
|
||||||
@ -255,7 +257,9 @@ Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount
|
|||||||
|
|
||||||
stream.path = _strdup(outStream.str().c_str());
|
stream.path = _strdup(outStream.str().c_str());
|
||||||
|
|
||||||
subtitleStreams->push_back(stream);
|
subtitleStreams[i] = stream;
|
||||||
|
*subtitleCount += 1;
|
||||||
|
//subtitleStreams->push_back(stream);
|
||||||
std::cout << "Stream #" << i << "(" << stream.language << "), stream type: " << inputCodecpar->codec_type << " codec: " << stream.codec << std::endl;
|
std::cout << "Stream #" << i << "(" << stream.language << "), stream type: " << inputCodecpar->codec_type << " codec: " << stream.codec << std::endl;
|
||||||
|
|
||||||
AVFormatContext *outputContext = NULL;
|
AVFormatContext *outputContext = NULL;
|
||||||
@ -337,6 +341,7 @@ Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount
|
|||||||
|
|
||||||
delete[] outputList;
|
delete[] outputList;
|
||||||
|
|
||||||
*streamCount = subtitleStreams->size();
|
return subtitleStreams;
|
||||||
return subtitleStreams->data();
|
//*streamCount = subtitleStreams->size();
|
||||||
|
//return subtitleStreams->data();
|
||||||
}
|
}
|
@ -12,6 +12,6 @@
|
|||||||
extern "C" API int Init();
|
extern "C" API int Init();
|
||||||
|
|
||||||
//Take the path of the file and the path of the output directory. It will return the list of subtitle streams in the streams variable. The int returned is the number of subtitles extracted.
|
//Take the path of the file and the path of the output directory. It will return the list of subtitle streams in the streams variable. The int returned is the number of subtitles extracted.
|
||||||
extern "C" API Stream* ExtractSubtitles(const char* path, const char* outPath, int* streamsCount);
|
extern "C" API Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount, int *subtitleCount);
|
||||||
|
|
||||||
extern "C" API int Transmux(const char *path, const char *outPath);
|
extern "C" API int Transmux(const char *path, const char *outPath);
|
||||||
|
@ -166,9 +166,14 @@ namespace Kyoo.InternalAPI
|
|||||||
string path = Path.Combine(Path.GetDirectoryName(episode.Path), "Subtitles");
|
string path = Path.Combine(Path.GetDirectoryName(episode.Path), "Subtitles");
|
||||||
if(Directory.Exists(path))
|
if(Directory.Exists(path))
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
foreach (string sub in Directory.EnumerateFiles(path, "", SearchOption.AllDirectories))
|
foreach (string sub in Directory.EnumerateFiles(path, "", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
string language = sub.Substring(Path.GetDirectoryName(sub).Length + Path.GetFileNameWithoutExtension(episode.Path).Length + 2, 3);
|
string episodeLink = Path.GetFileNameWithoutExtension(episode.Path);
|
||||||
|
|
||||||
|
if (sub.Contains(episodeLink))
|
||||||
|
{
|
||||||
|
string language = sub.Substring(Path.GetDirectoryName(sub).Length + episodeLink.Length + 2, 3);
|
||||||
bool isDefault = sub.Contains("default");
|
bool isDefault = sub.Contains("default");
|
||||||
bool isForced = sub.Contains("forced");
|
bool isForced = sub.Contains("forced");
|
||||||
|
|
||||||
@ -189,9 +194,12 @@ namespace Kyoo.InternalAPI
|
|||||||
|
|
||||||
Track track = new Track(Models.Watch.StreamType.Subtitle, null, language, isDefault, isForced, codec, false, sub) { episodeID = episode.id };
|
Track track = new Track(Models.Watch.StreamType.Subtitle, null, language, isDefault, isForced, codec, false, sub) { episodeID = episode.id };
|
||||||
libraryManager.RegisterTrack(track);
|
libraryManager.RegisterTrack(track);
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -16,25 +16,33 @@ namespace Kyoo.InternalAPI.TranscoderLink
|
|||||||
public extern static int Transmux(string path, string outPath);
|
public extern static int Transmux(string path, string outPath);
|
||||||
|
|
||||||
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
||||||
private extern static IntPtr ExtractSubtitles(string path, string outPath, out int streams);
|
[return:MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStruct, SizeParamIndex = 3)]
|
||||||
|
private extern static Stream[] ExtractSubtitles(string path, string outPath, out int arrayLength/*, out int trackCount*/);
|
||||||
|
|
||||||
public static void ExtractSubtitles(string path, string outPath, out Track[] tracks)
|
public static void ExtractSubtitles(string path, string outPath, out Track[] tracks)
|
||||||
{
|
{
|
||||||
int size = Marshal.SizeOf<Stream>();
|
//int size = Marshal.SizeOf<Stream>();
|
||||||
|
|
||||||
IntPtr streamsPtr = ExtractSubtitles(path, outPath, out int length);
|
Stream[] streamsPtr = ExtractSubtitles(path, outPath, out int count/*, out int trackCount*/);
|
||||||
if (length > 0)
|
|
||||||
{
|
|
||||||
tracks = new Track[length];
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
tracks[i] = Track.From(Marshal.PtrToStructure<Stream>(streamsPtr), StreamType.Subtitle);
|
|
||||||
streamsPtr += size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
tracks = null;
|
tracks = null;
|
||||||
|
//if (trackCount > 0)
|
||||||
|
//{
|
||||||
|
// tracks = new Track[trackCount];
|
||||||
|
|
||||||
|
// int j = 0;
|
||||||
|
// for (int i = 0; i < arrayLength; i++)
|
||||||
|
// {
|
||||||
|
// Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
|
||||||
|
// if (stream.Codec != null) //If the codec is null, the stream doesn't represent a subtitle.
|
||||||
|
// {
|
||||||
|
// tracks[j] = Track.From(stream, StreamType.Subtitle);
|
||||||
|
// j++;
|
||||||
|
// }
|
||||||
|
// streamsPtr += size;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
// tracks = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
<!-- Set this to true if you enable server-side prerendering -->
|
<!-- Set this to true if you enable server-side prerendering -->
|
||||||
<BuildServerSideRenderer>false</BuildServerSideRenderer>
|
<BuildServerSideRenderer>false</BuildServerSideRenderer>
|
||||||
|
<Company>SDG</Company>
|
||||||
|
<Authors>Anonymus-Raccoon</Authors>
|
||||||
|
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -62,11 +62,17 @@ namespace Kyoo.Models
|
|||||||
|
|
||||||
public static Track From(Stream stream)
|
public static Track From(Stream stream)
|
||||||
{
|
{
|
||||||
|
if (stream == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
return new Track(StreamType.Unknow, stream.Title, stream.Language, stream.IsDefault, stream.IsForced, stream.Codec, false, stream.Path);
|
return new Track(StreamType.Unknow, stream.Title, stream.Language, stream.IsDefault, stream.IsForced, stream.Codec, false, stream.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Track From(Stream stream, StreamType type)
|
public static Track From(Stream stream, StreamType type)
|
||||||
{
|
{
|
||||||
|
if (stream == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
return new Track(type, stream.Title, stream.Language, stream.IsDefault, stream.IsForced, stream.Codec, false, stream.Path);
|
return new Track(type, stream.Title, stream.Language, stream.IsDefault, stream.IsForced, stream.Codec, false, stream.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user