Commit aa9957304cf85e9a2bd98e146fbbcbf8744a55e8

Authored by Wesnydy Ribeiro
1 parent a219d957
Exists in master and in 1 other branch devel

Ajustes no extratorSRT

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