Jump to content



Greeklish subtitles


Dr.Paneas

Recommended Posts

Πηγα διακοπες με τον φορητο και τον εξωτερικο σκληρο δισκο γεμάτο με divX συμπιεσμένες ταινίες που τις εχω αγοράσει νομιμα για να μην κουβαλάω τα αυθεντικα DVD που μπορει και να χαλάσουν στις διακοπές. Ο βλάκας όμως, στο encoding ξεχασα να ενσωματώσω τους υπότιτλους ....

Και μαντεψτε ; Ειχα 4 λειτουργικα πανω (λινουξ) και ειχα ξεχασει να βαλω ελληνικη υποστηριξη. Με αποτελεσμα τα αρχεια srt των υποτιτλων να μην εμφανιζονται (δεν ελεγε να δουλεξει το ατοιμο το encoding ) με αποτελεσμα να βλεπω μονο τελιες και ερωτηματικα. Ετσι, αφου δεν ειχα ιντερνετ επρεπε να βρω μια λυση. Η λυση ηταν να κατσω να γραψω ολο το αρχειο με τους υποτιτλους απο τα ελληνικα στα greeklish. Πολυ χρονοβορο ομως... Οποτε εφτιαξα ενα προγραμμα να το κανει αυτο αντι για μενα. Δεν ειναι τιποτα σπουδαιο απλα το παραθετω ως ιδεα. πχ βαζεις το αρχειο srt σε ενα φακελο μαζι με τον source, κανεις compile. Στην αρχη σου ζηταει ενα ονομα, οπου δινει το ονομα του αρχειο που εχεις στον φακελο μαζι με τον κωδικο, πχ SexAndTheCity.srt και στην συνεχεια δινεις ενα ονομα για το καινουριο αρχειο με τα greeklish πχ SexGreek.srt. και voila


#include <fstream>
#include <iostream>
#include <string.h>
#include <cstdlib>
using namespace std;

int main()
{
char phrasi[100];
char Source[80], Target[80];
cout << "Greek2Lish Converter (by BlackSlash)\n" << endl;
cout << "Dose to onoma tou arxeiou iso-8859-7: ";
cin >> Source;
cout << "Dose to onoma tou arxeiou Greeklish: ";
cin >> Target;

ifstream fin(Source);
ofstream fout(Target);
cout << "Convertion started . . .";
char ch;
while( fin.get(ch) )
{
if(int(ch) == -31 || int(ch) == -36 ) {
fout << "a";
} else if( int(ch) == -63 || int(ch) == -74) {
fout << "A";
} else if ( int(ch) == -30) {
fout << "b";
} else if ( int(ch) == -62 ) {
fout << "B";
} else if ( int(ch) == -61 ) {
fout << "G";
} else if ( int(ch) == -29 ) {
fout << "g";
} else if ( int(ch) == -28 ) {
fout << "d";
} else if ( int(ch) == -60 ) {
fout << "D";
} else if ( int(ch) == -27 || int(ch) == -35 ) {
fout << "e";
} else if ( int(ch) == -59 || int(ch) == -72 ) {
fout << "E";
} else if ( int(ch) == -26 ) {
fout << "z";
} else if ( int(ch) == -58 ) {
fout << "Z";
} else if ( int(ch) == -25 || int(ch) == -34 || int(ch) == -23 || int(ch) == -33) {
fout << "i";
} else if ( int(ch) == -57 || int(ch) == -71 || int(ch) == -55 || int(ch) == -70) {
fout << "I";
} else if ( int(ch) == -24 || int(ch) == -56 ) {
fout << "th";
} else if ( int(ch) == -22 ) {
fout << "k";
} else if ( int(ch) == -54 ) {
fout << "K";
} else if ( int(ch) == -21 ) {
fout << "l";
} else if ( int(ch) == -53 ) {
fout << "L";
} else if ( int(ch) == -20 ) {
fout << "m";
} else if ( int(ch) == -52 ) {
fout << "M";
} else if ( int(ch) == -19 ) {
fout << "n";
} else if ( int(ch) == -51 ) {
fout << "N";
} else if ( int(ch) == -18 ) {
fout << "ks";
} else if ( int(ch) == -50 ) {
fout << "Ks";
} else if ( int(ch) == -17 || int(ch) == -4 ) {
fout << "o";
} else if ( int(ch) == -49 || int(ch) == -68 ) {
fout << "O";
} else if ( int(ch) == -16 ) {
fout << "p";
} else if ( int(ch) == -48 ) {
fout << "P";
} else if ( int(ch) == -15 ) {
fout << "r";
} else if ( int(ch) == -47 ) {
fout << "R";
} else if ( int(ch) == -13 || int(ch) == -14 ) {
fout << "s";
} else if ( int(ch) == -45 ) {
fout << "S";
} else if ( int(ch) == -12 ) {
fout << "t";
} else if ( int(ch) == -44 ) {
fout << "T";
} else if ( int(ch) == -11 || int(ch) == -3 ) {
fout << "u";
} else if ( int(ch) == -43 || int(ch) == -66 ) {
fout << "Y";
} else if ( int(ch) == -10 ) {
fout << "f";
} else if ( int(ch) == -42 ) {
fout << "F";
} else if ( int(ch) == -9 ) {
fout << "x";
} else if ( int(ch) == -41 ) {
fout << "X";
} else if ( int(ch) == -8 ) {
fout << "ps";
} else if ( int(ch) == -40 ) {
fout << "Ps";
} else if ( int(ch) == -7 || int(ch) == -2 ) {
fout << "o";
} else if ( int(ch) == -39 || int(ch) == -65 ) {
fout << "O";
} else {
fout << ch;
}

}
cout <<"Job done.***\n";
fin.close();
return 0;
}

Link to comment
Share on other sites

καλή φάση :happy:, έκανα και ένα μικρό refactoring με switch αντί παραδοσιακού else if

#include <fstream>
#include <iostream>
#include <string.h>
#include <cstdlib>
using namespace std;

int main()
{
char phrasi[100];
char Source[80], Target[80];
cout << "Greek2Lish Converter (by BlackSlash)\n" << endl;
cout << "Dose to onoma tou arxeiou iso-8859-7: ";
cin >> Source;
cout << "Dose to onoma tou arxeiou Greeklish: ";
cin >> Target;

ifstream fin(Source);
ofstream fout(Target);
cout << "Convertion started . . .";
char ch;
while( fin.get(ch) )
{
switch(int(ch)){
case -31:
case -36:
fout << "a"; break;
case -63 :
case -74 :
fout << "A"; break;
case -30:
fout << "b"; break;
case -62:
fout << "B"; break;

case -61:
fout << "G"; break;
case -29:
fout << "g"; break;
case -28:
fout << "d"; break;
case -60:
fout << "D"; break;
case -27:
case -35:
fout << "e"; break;
case -59:
case -72:
fout << "E"; break;
case -26:
fout << "z"; break;
case -58:
fout << "Z"; break;
case -25:
case -34:
case -23:
case -33:
fout << "i"; break;
case -57:
case -71:
case -55:
case -70:
fout << "I"; break;
case -24:
case -56:
fout << "th"; break;
case -22:
fout << "k"; break;
case -54:
fout << "K"; break;
case -21:
fout << "l"; break;
case -53:
fout << "L"; break;
case -20:
fout << "m"; break;
case -52:
fout << "M"; break;
case -19:
fout << "n"; break;
case -51:
fout << "N"; break;
case -18:
fout << "ks"; break;
case -50:
fout << "Ks"; break;
case -17:
case -4:
fout << "o"; break;
case -49:
case -68:
fout << "O"; break;
case -16:
fout << "p"; break;
case -48:
fout << "P"; break;
case -15:
fout << "r"; break;
case -47:
fout << "R"; break;
case -13:
case -14:
fout << "s"; break;
case -45:
fout << "S"; break;
case -12:
fout << "t"; break;
case -44:
fout << "T"; break;
case -11:
case -3:
fout << "u"; break;
case -43:
case -66:
fout << "Y"; break;
case -10:
fout << "f"; break;
case -42:
fout << "F"; break;
case -9:
fout << "x"; break;
case -41:
fout << "X"; break;
case -8:
fout << "ps"; break;
case -40:
fout << "Ps"; break;
case -7:
case -2:
fout << "o"; break;
case -39:
case -65:
fout << "O"; break;
default:
fout << ch; break;
}

}
cout <<"Job done.***\n";
fin.close();
return 0;
}

δεν έχω c compiler να δω αν δουλεύει μόνο...

Link to comment
Share on other sites

Αν και το είδα αργά... ωραία ιδέα... :T:

Το ίδιο πράγμα αλλά σε C και με πιο γρήγορο execution, λιγότερα libraries και lookup table...

#include <stdio.h>
int main (int argc, char * argv[])
{
FILE * fd, *fd2;
signed char c;
char *eng[]={".",".","w","y","o","y","i","w","ps","x","f","y","t","s","s","r","p","o","ks","n","m","l","k","i","th","h","z","e","d",
"g","b","a","y","i","h","e","a","Y","I","W","Ps","X","F","Y","T","S",".","R","P","O","Ks","N","M","L","K","I","Th","H","Z",
"E","D","G","B","A","i","W","Y",".","O",".",".","H","E",".",".",".",".",".",".",".",".",".",".",".",".",".",".",".",".",".",
".",".",".",".","A"};

if (argc != 3) {
printf("Error syntax. Try \"subtitle.exe target_file dest_file\" and filenames bigger than 5 chars.\r\n");
return -1;
}
fd = fopen (argv[1],"r");
if (fd!=NULL)
{
fd2 = fopen(argv[2], "w");
do {
c = (signed char) fgetc(fd);
if (c < 0)
fprintf(fd2,"%s", eng[-c]);
else
fputc(c, fd2);
} while (c != EOF);
fclose (fd);
fclose (fd2);
printf("Finished. The new filename is: \"%s\".\r\n", argv[2]);
} else {
printf("Could not read/find file \"%s.\".\r\n", argv[1]);
return -1;
}
return 0;
}

Αν το πρόγραμμα λέγεται "subtitle.exe" και το αρχείο των υπότιτλων είναι "movie.srt" η σύνταξη θα είναι...:

subtitle.exe movie.srt result_movie.srt

ή σε linux

./subtitle movie.srt result_movie.srt

Εδώ το link με το executable για windows...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Δημιουργία...

Important Information

Ο ιστότοπος theLab.gr χρησιμοποιεί cookies για να διασφαλίσει την καλύτερη εμπειρία σας κατά την περιήγηση. Μπορείτε να προσαρμόσετε τις ρυθμίσεις των cookies σας , διαφορετικά θα υποθέσουμε ότι είστε εντάξει για να συνεχίσετε.