From 1ce584d087f0dfceb32e4bfc7f5d4ceae566f477 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 17 Sep 2019 01:09:07 +0200 Subject: [PATCH] Finishing the c++ library for extracting subtitles. --- Kyoo.Transcoder/src/Stream.h | 7 +++--- Kyoo.Transcoder/src/Transcoder.cpp | 24 +++++++++---------- .../src/app/player/player.component.html | 4 ++-- .../LibraryManager/LibraryManager.cs | 2 +- Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs | 3 +-- Kyoo/Models/Track.cs | 14 +++++++++-- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Kyoo.Transcoder/src/Stream.h b/Kyoo.Transcoder/src/Stream.h index a40fc1d4..8e8f48a6 100644 --- a/Kyoo.Transcoder/src/Stream.h +++ b/Kyoo.Transcoder/src/Stream.h @@ -6,6 +6,7 @@ #endif #include +#include extern "C" struct Stream { @@ -14,8 +15,8 @@ extern "C" struct Stream const char* codec; bool isDefault; bool isForced; - const char* path; + char* path; - Stream(const char* title, const char* languageCode, const char* codec, bool isDefault, bool isForced, const char* path) - : title(title), language(languageCode), codec(codec), isDefault(isDefault), isForced(isForced), path(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) { } }; \ No newline at end of file diff --git a/Kyoo.Transcoder/src/Transcoder.cpp b/Kyoo.Transcoder/src/Transcoder.cpp index d8fae579..05a4c777 100644 --- a/Kyoo.Transcoder/src/Transcoder.cpp +++ b/Kyoo.Transcoder/src/Transcoder.cpp @@ -54,22 +54,18 @@ Stream* ExtractSubtitles(const char* path, const char* outPath, int* streamCount else { //Get metadata for file name - Stream stream("title", //title + Stream stream(NULL, //title av_dict_get(inputStream->metadata, "language", NULL, 0)->value, //language avcodec_get_name(inputCodecpar->codec_id), //format inputStream->disposition & AV_DISPOSITION_DEFAULT, //isDefault inputStream->disposition & AV_DISPOSITION_FORCED, //isForced - NULL); //The path is assigned afterward. + NULL); //Path builder references - subtitleStreams->push_back(stream); - - std::cout << "Stream #" << i << "(" << stream.language << "), stream type: " << inputCodecpar->codec_type << " codec: " << stream.codec << std::endl; - - //Create output folder - std::stringstream outStream; + //Create the language subfolder + std::stringstream outStream /*= new std::stringstream()*/; outStream << outPath << (char)std::filesystem::path::preferred_separator << stream.language; std::filesystem::create_directory(outStream.str()); - + //Get file name std::string fileName(path); size_t lastSeparator = fileName.find_last_of((char)std::filesystem::path::preferred_separator); @@ -83,14 +79,16 @@ Stream* ExtractSubtitles(const char* path, const char* outPath, int* streamCount if (stream.isForced) outStream << ".forced"; - if (stream.codec == "subrip") + if (strcmp(stream.codec, "subrip") == 0) outStream << ".srt"; - else if(stream.codec == "ass") + else if (strcmp(stream.codec, "ass") == 0) outStream << ".ass"; - std::string outStr = outStream.str(); - stream.path = outStr.c_str(); + stream.path = _strdup(outStream.str().c_str()); + + subtitleStreams->push_back(stream); + std::cout << "Stream #" << i << "(" << stream.language << "), stream type: " << inputCodecpar->codec_type << " codec: " << stream.codec << std::endl; AVFormatContext* outputContext = NULL; if (avformat_alloc_output_context2(&outputContext, NULL, NULL, stream.path) < 0) diff --git a/Kyoo/ClientApp/src/app/player/player.component.html b/Kyoo/ClientApp/src/app/player/player.component.html index ecb8a314..21c4b91a 100644 --- a/Kyoo/ClientApp/src/app/player/player.component.html +++ b/Kyoo/ClientApp/src/app/player/player.component.html @@ -61,10 +61,10 @@

{{this.minutes | number: '2.0-0'}}:{{this.seconds | number: '2.0-0'}} / {{this.maxMinutes | number: '2.0-0'}}:{{this.maxSeconds | number: '2.0-0'}}

- -