Commit aa9957304cf85e9a2bd98e146fbbcbf8744a55e8
1 parent
a219d957
Exists in
master
and in
1 other branch
Ajustes no extratorSRT
Showing
11 changed files
with
165 additions
and
105 deletions
Show diff stats
extrator/src/extratorSRT.cpp
| 1 | 1 | #include "extratorSRT.h" |
| 2 | +#include <iostream> | |
| 2 | 3 | |
| 3 | 4 | ExtratorSRT::ExtratorSRT(){ |
| 4 | 5 | listeners = new list<ListenerSub*>(); |
| ... | ... | @@ -11,27 +12,10 @@ ExtratorSRT::ExtratorSRT(){ |
| 11 | 12 | ExtratorSRT::~ExtratorSRT(){ |
| 12 | 13 | listeners->clear(); |
| 13 | 14 | delete listeners; |
| 14 | - //if (bff_reader) delete bff_reader; | |
| 15 | 15 | if (file_io) delete file_io; |
| 16 | 16 | PRINTL(util::_DEBUG, "ExtratorSTR finalized!\n"); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -void ExtratorSRT::initialize(){ | |
| 20 | - | |
| 21 | - file = new lavidlib::File(filePath); | |
| 22 | - | |
| 23 | - try{ | |
| 24 | - file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
| 25 | - }catch(Exception ex){ | |
| 26 | - finish = true; | |
| 27 | - Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda não encontrado."); | |
| 28 | - throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | |
| 29 | - } | |
| 30 | - | |
| 31 | - this->Start(); | |
| 32 | -} | |
| 33 | - | |
| 34 | - | |
| 35 | 19 | void ExtratorSRT::addListener(ListenerSub* listener){ |
| 36 | 20 | listeners->push_back(listener); |
| 37 | 21 | } |
| ... | ... | @@ -49,18 +33,39 @@ void ExtratorSRT::notifyEndExtraction(int size) { |
| 49 | 33 | } |
| 50 | 34 | } |
| 51 | 35 | |
| 52 | -void ExtratorSRT::setFilePath(char* path){ | |
| 53 | - filePath = (char*) path; | |
| 54 | - string command1 = "perl -p -e 's/\r$//' < "; | |
| 55 | - command1.append(filePath).append(" > ").append(INPUT_SRT); | |
| 56 | - system(command1.c_str()); | |
| 57 | - | |
| 58 | - string command2 = "iconv -f"; | |
| 59 | - command2.append(" $(file --mime-encoding -b ") | |
| 60 | - .append(INPUT_SRT).append(")") | |
| 61 | - .append(" -t utf-8 ").append(INPUT_SRT).append(" > ").append(filePath) | |
| 62 | - .append(" && rm -f ").append(INPUT_SRT); | |
| 63 | - system(command2.c_str()); | |
| 36 | +void ExtratorSRT::encodingfiletoUTF8() { | |
| 37 | + string iconvcmd = "iconv -f"; //Recodifica o arquivo para utf-8 | |
| 38 | + | |
| 39 | + iconvcmd.append(" $(file --mime-encoding -b ") | |
| 40 | + .append(this->filePath).append(") -t utf-8 ") | |
| 41 | + .append(this->filePath).append(" > ").append(TEMP_SRT); | |
| 42 | + system(iconvcmd.c_str()); | |
| 43 | + | |
| 44 | + string perlcmd = "perl -p -e 's/\r$//' < "; //Formata a quebra de linha | |
| 45 | + | |
| 46 | + perlcmd.append(TEMP_SRT).append(" > ").append(this->filePath) | |
| 47 | + .append(" && rm -f ").append(TEMP_SRT); | |
| 48 | + system(perlcmd.c_str()); | |
| 49 | +} | |
| 50 | + | |
| 51 | +void ExtratorSRT::setFilePath(char* path) { | |
| 52 | + this->filePath = path; | |
| 53 | + encodingfiletoUTF8(); | |
| 54 | +} | |
| 55 | + | |
| 56 | +void ExtratorSRT::initialize(){ | |
| 57 | + | |
| 58 | + file = new lavidlib::File(this->filePath); | |
| 59 | + | |
| 60 | + try{ | |
| 61 | + file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
| 62 | + }catch(Exception &ex){ | |
| 63 | + finish = true; | |
| 64 | + Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda não encontrado."); | |
| 65 | + throw lavidlib::RuntimeException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); | |
| 66 | + } | |
| 67 | + this->Start(); | |
| 68 | + | |
| 64 | 69 | } |
| 65 | 70 | |
| 66 | 71 | bool ExtratorSRT::isFinished(){ |
| ... | ... | @@ -88,6 +93,7 @@ void ExtratorSRT::Run(){ |
| 88 | 93 | } |
| 89 | 94 | if(sub_index == 0) |
| 90 | 95 | notifyListeners((unsigned char*)"ARQUIVO_INVALIDO", 0); |
| 96 | + | |
| 91 | 97 | finish = true; |
| 92 | 98 | notifyEndExtraction(sub_index); |
| 93 | 99 | } |
| ... | ... | @@ -136,6 +142,7 @@ Subtitle* ExtratorSRT::next() { |
| 136 | 142 | sub->setSubtitleText(formatText(text_sub)); |
| 137 | 143 | seek_pos += (int64_t) text_sub.size() + SIZE_CSCAPE; |
| 138 | 144 | hasNextSub = false; |
| 145 | + delete(bff_reader); | |
| 139 | 146 | return sub; |
| 140 | 147 | } |
| 141 | 148 | sub->setSubtitleText(formatText(text_sub)); | ... | ... |
extrator/src/extratorTXT.cpp
| ... | ... | @@ -8,7 +8,7 @@ |
| 8 | 8 | * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * |
| 9 | 9 | * * |
| 10 | 10 | **************************************************************************/ |
| 11 | - | |
| 11 | + | |
| 12 | 12 | #include "extratorTXT.h" |
| 13 | 13 | |
| 14 | 14 | ExtratorTXT::ExtratorTXT(){ |
| ... | ... | @@ -17,7 +17,7 @@ ExtratorTXT::ExtratorTXT(){ |
| 17 | 17 | PRINTL(util::_DEBUG, "ExtratorTXT Done!\n"); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | -ExtratorTXT::~ExtratorTXT(){ | |
| 20 | +ExtratorTXT::~ExtratorTXT(){ | |
| 21 | 21 | listeners->clear(); |
| 22 | 22 | delete listeners; |
| 23 | 23 | delete file; |
| ... | ... | @@ -26,19 +26,6 @@ ExtratorTXT::~ExtratorTXT(){ |
| 26 | 26 | PRINTL(util::_DEBUG, "ExtratorTXT finalized!\n"); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | -void ExtratorTXT::initialize(){ | |
| 30 | - file = new lavidlib::File(filePath); | |
| 31 | - try{ | |
| 32 | - file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
| 33 | - bff_reader = new BufferedReader(file_io); | |
| 34 | - }catch(Exception &ex){ | |
| 35 | - finish = true; | |
| 36 | - Logging::instance()->writeLog("extratorTXT.cpp <Error>: Arquivo de texto não encontrado."); | |
| 37 | - throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); | |
| 38 | - } | |
| 39 | - this->Start(); | |
| 40 | -} | |
| 41 | - | |
| 42 | 29 | void ExtratorTXT::addListener(ListenerTXT* listener){ |
| 43 | 30 | listeners->push_back(listener); |
| 44 | 31 | } |
| ... | ... | @@ -46,7 +33,7 @@ void ExtratorTXT::addListener(ListenerTXT* listener){ |
| 46 | 33 | void ExtratorTXT::notifyListeners(unsigned char* line) { |
| 47 | 34 | for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){ |
| 48 | 35 | (*it)->notifyLine(line); |
| 49 | - } | |
| 36 | + } | |
| 50 | 37 | } |
| 51 | 38 | |
| 52 | 39 | void ExtratorTXT::notifyEndExtraction(int size) { |
| ... | ... | @@ -56,18 +43,37 @@ void ExtratorTXT::notifyEndExtraction(int size) { |
| 56 | 43 | } |
| 57 | 44 | } |
| 58 | 45 | |
| 46 | +void ExtratorTXT::encodingfiletoUTF8() { | |
| 47 | + string iconvcmd = "iconv -f"; //Recodifica o arquivo para utf-8 | |
| 48 | + | |
| 49 | + iconvcmd.append(" $(file --mime-encoding -b ") | |
| 50 | + .append(this->filePath).append(") -t utf-8 ") | |
| 51 | + .append(this->filePath).append(" > ").append(TEMP_TXT); | |
| 52 | + system(iconvcmd.c_str()); | |
| 53 | + | |
| 54 | + string perlcmd = "perl -p -e 's/\r$//' < "; //Formata a quebra de linha | |
| 55 | + | |
| 56 | + perlcmd.append(TEMP_TXT).append(" > ").append(this->filePath) | |
| 57 | + .append(" && rm -f ").append(TEMP_TXT); | |
| 58 | + system(perlcmd.c_str()); | |
| 59 | +} | |
| 60 | + | |
| 59 | 61 | void ExtratorTXT::setFilePath(char* path){ |
| 60 | - filePath = (char*) path; | |
| 61 | - string command1 = "perl -p -e 's/\r$//' < "; | |
| 62 | - command1.append(filePath).append(" > ").append(INPUT_TXT); | |
| 63 | - system(command1.c_str()); | |
| 62 | + this->filePath = path; | |
| 63 | + encodingfiletoUTF8(); | |
| 64 | +} | |
| 64 | 65 | |
| 65 | - string command2 = "iconv -f"; | |
| 66 | - command2.append(" $(file --mime-encoding -b ") | |
| 67 | - .append(INPUT_TXT).append(")") | |
| 68 | - .append(" -t utf-8 ").append(INPUT_TXT).append(" > ").append(filePath) | |
| 69 | - .append(" && rm -f ").append(INPUT_TXT); | |
| 70 | - system(command2.c_str()); | |
| 66 | +void ExtratorTXT::initialize(){ | |
| 67 | + file = new lavidlib::File(filePath); | |
| 68 | + try{ | |
| 69 | + file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
| 70 | + bff_reader = new BufferedReader(file_io); | |
| 71 | + }catch(Exception &ex){ | |
| 72 | + finish = true; | |
| 73 | + Logging::instance()->writeLog("extratorTXT.cpp <Error>: Arquivo de texto não encontrado."); | |
| 74 | + throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); | |
| 75 | + } | |
| 76 | + this->Start(); | |
| 71 | 77 | } |
| 72 | 78 | |
| 73 | 79 | bool ExtratorTXT::isFinished(){ |
| ... | ... | @@ -77,14 +83,14 @@ bool ExtratorTXT::isFinished(){ |
| 77 | 83 | void ExtratorTXT::Run(){ |
| 78 | 84 | PRINTL(util::_INFO, "Extraindo Texto...\n"); |
| 79 | 85 | int line_index = 0; |
| 80 | - bool hasNext = true; | |
| 86 | + bool hasNext = true; | |
| 81 | 87 | string line; |
| 82 | 88 | |
| 83 | 89 | while (hasNext) { |
| 84 | 90 | try{ |
| 85 | 91 | line = bff_reader->readLine(); |
| 86 | - if (line.length() > 0){ | |
| 87 | - notifyListeners((unsigned char*) line.c_str()); | |
| 92 | + if (line.length() > 0){ | |
| 93 | + notifyListeners((unsigned char*) line.c_str()); | |
| 88 | 94 | line_index++; |
| 89 | 95 | } |
| 90 | 96 | }catch (EOFException &ex){ |
| ... | ... | @@ -93,7 +99,7 @@ void ExtratorTXT::Run(){ |
| 93 | 99 | hasNext = false; |
| 94 | 100 | }catch (...){ |
| 95 | 101 | Logging::instance()->writeLog("extratorTXT.cpp <Error>: Erro durante a leitura do arquivo de texto."); |
| 96 | - throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); | |
| 102 | + throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); | |
| 97 | 103 | } |
| 98 | 104 | } |
| 99 | 105 | finish = true; | ... | ... |
extrator/src/extratorVTT.cpp
| ... | ... | @@ -9,21 +9,12 @@ ExtratorVTT::ExtratorVTT() { |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | ExtratorVTT::~ExtratorVTT() { |
| 12 | - listeners->clear(); | |
| 12 | + listeners->clear(); | |
| 13 | 13 | delete listeners; |
| 14 | - if (bff_reader) delete bff_reader; | |
| 15 | 14 | if (file_io) delete file_io; |
| 16 | 15 | PRINTL(util::_DEBUG, "ExtratorVTT finalized!\n"); |
| 17 | 16 | } |
| 18 | 17 | |
| 19 | -void ExtratorVTT::setFilePath(char* path) { | |
| 20 | - this->filePath = path; | |
| 21 | -} | |
| 22 | - | |
| 23 | -bool ExtratorVTT::isFinished() { | |
| 24 | - return this->finish; | |
| 25 | -} | |
| 26 | - | |
| 27 | 18 | void ExtratorVTT::addListener(ListenerSub* listener){ |
| 28 | 19 | listeners->push_back(listener); |
| 29 | 20 | } |
| ... | ... | @@ -31,7 +22,7 @@ void ExtratorVTT::addListener(ListenerSub* listener){ |
| 31 | 22 | void ExtratorVTT::notifyListeners(unsigned char* subtitle, uint64_t pts) { |
| 32 | 23 | for(list<ListenerSub*>::iterator it = listeners->begin(); it != listeners->end(); it++){ |
| 33 | 24 | (*it)->notifySubtitle(subtitle, pts); |
| 34 | - } | |
| 25 | + } | |
| 35 | 26 | } |
| 36 | 27 | |
| 37 | 28 | void ExtratorVTT::notifyEndExtraction(int size) { |
| ... | ... | @@ -41,12 +32,31 @@ void ExtratorVTT::notifyEndExtraction(int size) { |
| 41 | 32 | } |
| 42 | 33 | } |
| 43 | 34 | |
| 35 | +void ExtratorVTT::encodingfiletoUTF8() { | |
| 36 | + string iconvcmd = "iconv -f"; //Recodifica o arquivo para utf-8 | |
| 37 | + | |
| 38 | + iconvcmd.append(" $(file --mime-encoding -b ") | |
| 39 | + .append(this->filePath).append(") -t utf-8 ") | |
| 40 | + .append(this->filePath).append(" > ").append(TEMP_SRT); | |
| 41 | + system(iconvcmd.c_str()); | |
| 42 | + | |
| 43 | + string perlcmd = "perl -p -e 's/\r$//' < "; //Formata a quebra de linha | |
| 44 | + | |
| 45 | + perlcmd.append(TEMP_SRT).append(" > ").append(this->filePath) | |
| 46 | + .append(" && rm -f ").append(TEMP_SRT); | |
| 47 | + system(perlcmd.c_str()); | |
| 48 | +} | |
| 49 | + | |
| 50 | +void ExtratorVTT::setFilePath(char* path) { | |
| 51 | + this->filePath = path; | |
| 52 | + encodingfiletoUTF8(); | |
| 53 | +} | |
| 54 | + | |
| 44 | 55 | void ExtratorVTT::initialize() { |
| 45 | 56 | file = new lavidlib::File(this->filePath); |
| 46 | 57 | |
| 47 | 58 | try{ |
| 48 | 59 | file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); |
| 49 | - bff_reader = new BufferedReader(file_io); | |
| 50 | 60 | }catch(Exception &ex){ |
| 51 | 61 | finish = true; |
| 52 | 62 | Logging::instance()->writeLog("extratorVTT.cpp <Error>: Arquivo de legenda não encontrado."); |
| ... | ... | @@ -55,12 +65,24 @@ void ExtratorVTT::initialize() { |
| 55 | 65 | this->Start(); |
| 56 | 66 | } |
| 57 | 67 | |
| 68 | +bool ExtratorVTT::isFinished() { | |
| 69 | + return this->finish; | |
| 70 | +} | |
| 71 | + | |
| 58 | 72 | Subtitle* ExtratorVTT::nextCue() { |
| 59 | 73 | string line; |
| 60 | 74 | string cueText = ""; |
| 61 | 75 | int target_pos; |
| 62 | 76 | int64_t time_in; |
| 63 | 77 | |
| 78 | + file_io->seek(seekPos); | |
| 79 | + try{ | |
| 80 | + bff_reader = new BufferedReader(file_io); | |
| 81 | + }catch(Exception &ex){ | |
| 82 | + Logging::instance()->writeLog("extratorSRT.cpp <Error>: BufferedReader não inicializado."); | |
| 83 | + throw lavidlib::RuntimeException("O BufferedReader não foi inicializado."); | |
| 84 | + } | |
| 85 | + | |
| 64 | 86 | Subtitle* cue = new Subtitle(); |
| 65 | 87 | |
| 66 | 88 | try{ |
| ... | ... | @@ -82,11 +104,13 @@ Subtitle* ExtratorVTT::nextCue() { |
| 82 | 104 | cue->setSubtitleText(formatText(cueText)); |
| 83 | 105 | seekPos += (int64_t) cueText.size() + SIZE_SCAPE; |
| 84 | 106 | hasNextCue =false; |
| 107 | + delete(bff_reader); | |
| 85 | 108 | return cue; |
| 86 | 109 | } |
| 87 | 110 | |
| 88 | 111 | cue->setSubtitleText(formatText(cueText)); |
| 89 | 112 | seekPos += (int64_t) cueText.size() + SIZE_SCAPE; |
| 113 | + delete(bff_reader); | |
| 90 | 114 | return cue; |
| 91 | 115 | } |
| 92 | 116 | |
| ... | ... | @@ -113,7 +137,7 @@ int64_t ExtratorVTT::str_to_time(string str_time) { |
| 113 | 137 | |
| 114 | 138 | int index = 0; |
| 115 | 139 | int values [4]; // hh, mm, ss, ms |
| 116 | - char * str = strtok(tokens, ":,."); | |
| 140 | + char * str = strtok(tokens, ":,."); | |
| 117 | 141 | while (str != NULL) { |
| 118 | 142 | values[index] = atoi(str); |
| 119 | 143 | str = strtok(NULL, ":,."); |
| ... | ... | @@ -122,7 +146,7 @@ int64_t ExtratorVTT::str_to_time(string str_time) { |
| 122 | 146 | delete(tokens); |
| 123 | 147 | |
| 124 | 148 | /* calculate time */ |
| 125 | - ttime = /*hour to sec*/((((values[0] * 60) * 60) + | |
| 149 | + ttime = /*hour to sec*/((((values[0] * 60) * 60) + | |
| 126 | 150 | /*min to sec*/(values[1] * 60) +/*sec*/values[2])*1000) + values[3]; |
| 127 | 151 | |
| 128 | 152 | return ttime; |
| ... | ... | @@ -130,7 +154,7 @@ int64_t ExtratorVTT::str_to_time(string str_time) { |
| 130 | 154 | |
| 131 | 155 | void ExtratorVTT::Run() { |
| 132 | 156 | PRINTL(util::_INFO, "Extraindo Legendas...\n"); |
| 133 | - | |
| 157 | + | |
| 134 | 158 | int sub_index = 0; |
| 135 | 159 | string cue_text = ""; |
| 136 | 160 | while(hasNextCue){ |
| ... | ... | @@ -144,4 +168,4 @@ void ExtratorVTT::Run() { |
| 144 | 168 | notifyListeners((unsigned char*)"ARQUIVO_INVALIDO", 0); |
| 145 | 169 | this->finish = true; |
| 146 | 170 | notifyEndExtraction(sub_index); |
| 147 | -} | |
| 148 | 171 | \ No newline at end of file |
| 172 | +} | ... | ... |
extrator/src/include/extrator.h
| ... | ... | @@ -31,7 +31,7 @@ protected: |
| 31 | 31 | File* file; |
| 32 | 32 | FileIO* file_io; |
| 33 | 33 | BufferedReader* bff_reader; |
| 34 | - | |
| 34 | + | |
| 35 | 35 | public: |
| 36 | 36 | enum ExtratorType {SRT, TXT, VTT}; |
| 37 | 37 | |
| ... | ... | @@ -47,14 +47,17 @@ public: |
| 47 | 47 | */ |
| 48 | 48 | virtual void setFilePath(char* path) = 0; |
| 49 | 49 | |
| 50 | + /** Recodifica o arquivo para utf-8 */ | |
| 51 | + virtual void encodingfiletoUTF8() = 0; | |
| 52 | + | |
| 50 | 53 | /** Inicializa a extração do conteúdo. */ |
| 51 | 54 | virtual void initialize() = 0; |
| 52 | 55 | |
| 53 | - /** Indica o fim do processo de extração. | |
| 56 | + /** Indica o fim do processo de extração. | |
| 54 | 57 | * |
| 55 | 58 | * \return O status do do processo. |
| 56 | 59 | */ |
| 57 | 60 | virtual bool isFinished() = 0; |
| 58 | 61 | }; |
| 59 | 62 | |
| 60 | -#endif /* EXTRATOR_H */ | |
| 61 | 63 | \ No newline at end of file |
| 64 | +#endif /* EXTRATOR_H */ | ... | ... |
extrator/src/include/extratorSRT.h
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | #include <list> |
| 12 | 12 | #include <string.h> |
| 13 | 13 | #include <stdlib.h> |
| 14 | -#include <fstream> | |
| 14 | +#include <fstream> | |
| 15 | 15 | #include <stdio.h> |
| 16 | 16 | #include "jthread.h" |
| 17 | 17 | #include "extrator.h" |
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | #define TARGET_TIME "-->" |
| 24 | 24 | #define LESS_THAN "<" |
| 25 | 25 | #define MORE_THAN ">" |
| 26 | -#define INPUT_SRT "vlibras_user/inputSRT.srt" | |
| 26 | +#define TEMP_SRT "/tmp/tempsrt.srt" | |
| 27 | 27 | //#define MAX_LINE 1024 |
| 28 | 28 | |
| 29 | 29 | using namespace jthread; |
| ... | ... | @@ -38,14 +38,14 @@ using namespace sndesc; |
| 38 | 38 | * \headerfile extrator/src/include/extratorSRT.h |
| 39 | 39 | */ |
| 40 | 40 | class ExtratorSRT: public Extrator, public Thread { |
| 41 | - | |
| 41 | + | |
| 42 | 42 | public: |
| 43 | 43 | /** Construtor */ |
| 44 | 44 | ExtratorSRT(); |
| 45 | 45 | |
| 46 | 46 | /** Destrutor */ |
| 47 | 47 | ~ExtratorSRT(); |
| 48 | - | |
| 48 | + | |
| 49 | 49 | /** Adiciona ouvintes do extratorSRT. |
| 50 | 50 | * |
| 51 | 51 | * \param listener O ouvinte a ser registrado. |
| ... | ... | @@ -77,12 +77,12 @@ public: |
| 77 | 77 | */ |
| 78 | 78 | void initialize(); |
| 79 | 79 | |
| 80 | - /** Indica o fim do processo de extração das legendas. | |
| 80 | + /** Indica o fim do processo de extração das legendas. | |
| 81 | 81 | * |
| 82 | 82 | * \return O status do do processo. |
| 83 | 83 | */ |
| 84 | 84 | bool isFinished(); |
| 85 | - | |
| 85 | + | |
| 86 | 86 | /** Retorna o conteúdo da legenda extraída. |
| 87 | 87 | * |
| 88 | 88 | * \return Referência para um objeto Subtitle. |
| ... | ... | @@ -98,17 +98,18 @@ public: |
| 98 | 98 | |
| 99 | 99 | /** Este método é chamado quando a Thread for iniciada. */ |
| 100 | 100 | void Run(); |
| 101 | - | |
| 101 | + | |
| 102 | 102 | private: |
| 103 | 103 | list<ListenerSub*> *listeners; |
| 104 | 104 | |
| 105 | - Subtitle *subtitle; | |
| 105 | + Subtitle *subtitle; | |
| 106 | 106 | int64_t seek_pos; |
| 107 | 107 | bool hasNextSub; |
| 108 | - | |
| 108 | + | |
| 109 | + void encodingfiletoUTF8(); | |
| 109 | 110 | string formatText(string line); |
| 110 | 111 | uint64_t calcula_pts(double msec); |
| 111 | - int64_t str_to_time(std::string str_time); | |
| 112 | + int64_t str_to_time(std::string str_time); | |
| 112 | 113 | }; |
| 113 | 114 | |
| 114 | -#endif /* EXTRATORSRT_H */ | |
| 115 | 115 | \ No newline at end of file |
| 116 | +#endif /* EXTRATORSRT_H */ | ... | ... |
extrator/src/include/extratorTXT.h
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | #include "listenerTXT.h" |
| 15 | 15 | #include "extratorException.h" |
| 16 | 16 | |
| 17 | -#define INPUT_TXT "vlibras_user/inputTXT.txt" | |
| 17 | +#define TEMP_TXT "/tmp/temptxt.txt" | |
| 18 | 18 | |
| 19 | 19 | using namespace jthread; |
| 20 | 20 | using namespace std; |
| ... | ... | @@ -27,7 +27,7 @@ using namespace std; |
| 27 | 27 | * \headerfile extrator/src/include/extratorTXT.h |
| 28 | 28 | */ |
| 29 | 29 | class ExtratorTXT: public Extrator, public Thread { |
| 30 | - | |
| 30 | + | |
| 31 | 31 | public: |
| 32 | 32 | /** Construtor */ |
| 33 | 33 | ExtratorTXT(); |
| ... | ... | @@ -65,18 +65,18 @@ public: |
| 65 | 65 | */ |
| 66 | 66 | void initialize(); |
| 67 | 67 | |
| 68 | - /** Indica o fim do processo de extração do texto. | |
| 68 | + /** Indica o fim do processo de extração do texto. | |
| 69 | 69 | * |
| 70 | 70 | * \return O status do do processo. |
| 71 | 71 | */ |
| 72 | 72 | bool isFinished(); |
| 73 | - | |
| 73 | + | |
| 74 | 74 | /** Este método é chamado quando a Thread for iniciada. */ |
| 75 | 75 | void Run(); |
| 76 | 76 | |
| 77 | 77 | private: |
| 78 | - list<ListenerTXT*> *listeners; | |
| 78 | + list<ListenerTXT*> *listeners; | |
| 79 | + void encodingfiletoUTF8(); | |
| 79 | 80 | }; |
| 80 | 81 | |
| 81 | 82 | #endif /* EXTRATORTXT_H */ |
| 82 | - | ... | ... |
extrator/src/include/extratorVTT.h
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | #define LESS_THAN "<" |
| 17 | 17 | #define MORE_THAN ">" |
| 18 | 18 | #define SIZE_SCAPE 1 |
| 19 | +#define TEMP_SRT "/tmp/tempsrt.srt" | |
| 19 | 20 | |
| 20 | 21 | using namespace std; |
| 21 | 22 | using namespace sndesc; |
| ... | ... | @@ -45,8 +46,9 @@ private: |
| 45 | 46 | void notifyListeners(unsigned char* subtitle, uint64_t pts); |
| 46 | 47 | |
| 47 | 48 | Subtitle* nextCue(); |
| 49 | + void encodingfiletoUTF8(); | |
| 48 | 50 | string formatText(string line); |
| 49 | 51 | int64_t str_to_time(string str_time); |
| 50 | 52 | }; |
| 51 | 53 | |
| 52 | -#endif /* EXTRATORVTT_H */ | |
| 53 | 54 | \ No newline at end of file |
| 55 | +#endif /* EXTRATORVTT_H */ | ... | ... |
log/log
renderer/src/renderer.cpp
servico/src/serviceWindowGenerationFromSubtitle.cpp
| ... | ... | @@ -186,10 +186,17 @@ void ServiceWindowGenerationFromSubtitle::notifyTranslator(unsigned char* subtit |
| 186 | 186 | |
| 187 | 187 | void ServiceWindowGenerationFromSubtitle::notifySubtitle(unsigned char *subtitle, uint64_t pts){ |
| 188 | 188 | addPTS(pts); |
| 189 | - if (sub_language == 1) | |
| 189 | + if (sub_language == 1) { | |
| 190 | 190 | notifyTranslator(subtitle); |
| 191 | - else{ | |
| 192 | - string glosa(reinterpret_cast<char*>(subtitle)); | |
| 191 | + }else{ | |
| 192 | + string subt(reinterpret_cast<char*>(subtitle)); | |
| 193 | + | |
| 194 | + locale loc; | |
| 195 | + string glosa = ""; | |
| 196 | + for (string::size_type i=0; i< subt.length(); ++i) { | |
| 197 | + glosa += std::toupper(subt[i], loc); | |
| 198 | + } | |
| 199 | + cout << glosa << endl; | |
| 193 | 200 | notifyRenderer(glosa); |
| 194 | 201 | } |
| 195 | 202 | } | ... | ... |
servico/src/serviceWindowGenerationFromText.cpp
| ... | ... | @@ -91,14 +91,20 @@ void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | void ServiceWindowGenerationFromText::notifyTranslator(unsigned char* text) { |
| 94 | - tradutor->traduz(text); | |
| 94 | + tradutor->traduz(text); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | void ServiceWindowGenerationFromText::notifyLine(unsigned char* line){ |
| 98 | 98 | if (sub_language == 1) |
| 99 | 99 | notifyTranslator(line); |
| 100 | 100 | else{ |
| 101 | - string glosa(reinterpret_cast<char*>(line)); | |
| 101 | + string text(reinterpret_cast<char*>(line)); | |
| 102 | + | |
| 103 | + locale loc; | |
| 104 | + string glosa = ""; | |
| 105 | + for (string::size_type i=0; i< text.length(); ++i) { | |
| 106 | + glosa += std::toupper(text[i], loc); | |
| 107 | + } | |
| 102 | 108 | notifyRenderer(glosa); |
| 103 | 109 | } |
| 104 | 110 | } |
| ... | ... | @@ -137,7 +143,7 @@ bool ServiceWindowGenerationFromText::isFinished() { |
| 137 | 143 | void ServiceWindowGenerationFromText::initialize() { |
| 138 | 144 | PRINTL(util::_DEBUG, "Service Text Initialize.\n"); |
| 139 | 145 | setPathLibras(); |
| 140 | - extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(Extrator::TXT); | |
| 146 | + extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(Extrator::TXT); | |
| 141 | 147 | extratorTXT->addListener(this); |
| 142 | 148 | extratorTXT->setFilePath(path_input); |
| 143 | 149 | |
| ... | ... | @@ -148,9 +154,9 @@ void ServiceWindowGenerationFromText::initialize() { |
| 148 | 154 | |
| 149 | 155 | renderer = new Renderer(this->path_libras, this->user_id); |
| 150 | 156 | renderer->addListener(this); |
| 151 | - | |
| 157 | + | |
| 152 | 158 | try{ |
| 153 | - extratorTXT->initialize(); | |
| 159 | + extratorTXT->initialize(); | |
| 154 | 160 | }catch(ExtratorException ex){ |
| 155 | 161 | throw ServiceException(ex.getMessage().c_str()); |
| 156 | 162 | }catch(RuntimeException &ex){ |
| ... | ... | @@ -164,4 +170,4 @@ void ServiceWindowGenerationFromText::Run(){ |
| 164 | 170 | usleep(200000); |
| 165 | 171 | } |
| 166 | 172 | finish = true; |
| 167 | -} | |
| 168 | 173 | \ No newline at end of file |
| 174 | +} | ... | ... |