mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Merge pull request #1 from AnonymusRaccoon/beta
Test with a c style array.
This commit is contained in:
commit
0bd3a30064
@ -17,6 +17,9 @@ extern "C" struct Stream
|
||||
bool isForced;
|
||||
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)
|
||||
: 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;
|
||||
|
||||
if (open_input_context(&inputContext, path) != 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;
|
||||
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());
|
||||
|
||||
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;
|
||||
|
||||
AVFormatContext *outputContext = NULL;
|
||||
@ -337,6 +341,7 @@ Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount
|
||||
|
||||
delete[] outputList;
|
||||
|
||||
*streamCount = subtitleStreams->size();
|
||||
return subtitleStreams->data();
|
||||
return subtitleStreams;
|
||||
//*streamCount = subtitleStreams->size();
|
||||
//return subtitleStreams->data();
|
||||
}
|
@ -12,6 +12,6 @@
|
||||
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.
|
||||
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);
|
||||
|
@ -166,9 +166,14 @@ namespace Kyoo.InternalAPI
|
||||
string path = Path.Combine(Path.GetDirectoryName(episode.Path), "Subtitles");
|
||||
if(Directory.Exists(path))
|
||||
{
|
||||
bool ret = false;
|
||||
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 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 };
|
||||
libraryManager.RegisterTrack(track);
|
||||
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -16,25 +16,33 @@ namespace Kyoo.InternalAPI.TranscoderLink
|
||||
public extern static int Transmux(string path, string outPath);
|
||||
|
||||
[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)
|
||||
{
|
||||
int size = Marshal.SizeOf<Stream>();
|
||||
//int size = Marshal.SizeOf<Stream>();
|
||||
|
||||
IntPtr streamsPtr = ExtractSubtitles(path, outPath, out int length);
|
||||
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
|
||||
Stream[] streamsPtr = ExtractSubtitles(path, outPath, out int count/*, out int trackCount*/);
|
||||
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 -->
|
||||
<BuildServerSideRenderer>false</BuildServerSideRenderer>
|
||||
<Company>SDG</Company>
|
||||
<Authors>Anonymus-Raccoon</Authors>
|
||||
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -62,11 +62,17 @@ namespace Kyoo.Models
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user