Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ---------------------------------------------------------------------------
- ** This software is in the public domain, furnished "as is", without technical
- ** support, and with no warranty, express or implied, as to its usefulness for
- ** any purpose.
- **
- ** SubRip Subtitles' FPS Converter.cpp
- ** This file contains the very whole code. Developed using the Dev-C++ IDE.
- **
- ** Author: jaggi
- ** Version: 1.2.0.0
- ** contact: [email protected]
- ** -------------------------------------------------------------------------*/
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- #include <string>
- #include <cmath>
- #include <cstdlib>
- #include <sstream>
- using namespace std;
- void convert(int& frame, float fps,unsigned long long ms) { frame=ceil( ms/(1000/fps) ); }
- template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
- void modify(string& line, unsigned long long ms, unsigned long long ms2, float fps)
- {
- string frame1, frame2;
- int frame;
- convert(frame, fps, ms);
- frame1=tostr(frame);
- convert(frame, fps, ms2);
- frame2=tostr(frame);
- line="{"+frame1+"}"+"{"+frame2+"}"+line;
- }
- float menu(string msg)
- {
- cout<<msg<<"\n1. 12 \n2. 15 \n3. 18\n4. 20\n5. 23.976 \n6. 24 \n7. 25 \n8. 29.97 \n9. 30\n";
- char choice=getch();
- switch(choice)
- {
- case '1':return 12;
- case '2':return 15;
- case '3':return 18;
- case '4':return 20;
- case '5':return 23.976;
- case '6':return 24;
- case '7':return 25;
- case '8':return 29.97;
- case '9':return 30;
- default: return 0;
- }
- }
- int count(const char* name)
- {
- string temp;
- int x=0;
- ifstream file1(name);
- while(getline(file1, temp)) x++;
- file1.close();
- return x;
- }
- void mainFunction(string* tab, int size, const char* name)
- {
- int var=-1, x=0;
- static unsigned int z=1;
- unsigned long long ms, ms2;
- float fps=menu("Movie FPS");
- string tmp;
- for(int i=0;i<size;i++)
- if( !tab[i].empty() && (tab[i][0]<'0' || tab[i][0]>'9') ) x++;
- string* sArray=new string[x];
- for(int i=0;i<size;i++)
- {
- int found=tab[i].find("-->");
- if(found!=string::npos)
- {
- int found2=tab[i].find(":");
- ms=atoi( (tab[i].substr(found2-2, 2)).c_str() )*3600000;
- ms+=atoi( (tab[i].substr(found2+1, 2)).c_str() )*60000;
- ms+=atoi( (tab[i].substr(found2+4, 2)).c_str() )*1000;
- ms+=atoi( (tab[i].substr(found2+7, 3)).c_str() );
- int found3=tab[i].rfind(":");
- ms2=atoi( (tab[i].substr(found3-5, 2)).c_str() )*3600000;
- ms2+=atoi( (tab[i].substr(found3-2, 2)).c_str() )*60000;
- ms2+=atoi( (tab[i].substr(found3+1, 2)).c_str() )*1000;
- ms2+=atoi( (tab[i].substr(found3+4, 3)).c_str() );
- var=1;
- continue;
- }
- if( tab[i].empty() ) { var=0; continue; }
- if(var==1)
- {
- if( tmp.empty() ) tmp=tab[i];
- else tmp=tmp+"|"+tab[i];
- if( (i+1)==size )
- {
- sArray[z]=tmp;
- modify(sArray[z], ms, ms2, fps);
- break;
- }
- continue;
- }
- if(var==0)
- {
- sArray[z]=tmp;
- modify(sArray[z], ms, ms2, fps);
- z++;
- tmp.clear();
- }
- }
- sArray[0]="{1}{1}"+tostr(fps);
- string label=name;
- label=label.erase(label.length()-4, 4)+"_.txt";
- ofstream file(label.c_str());
- for(int i=0;i<=z;i++)
- file<<sArray[i]<<endl;
- file.close();
- }
- int main(int argc, char** argv)
- {
- cout<<"SubRip Subtitles' Converter by jaggi.\nNo rights reserved :)\nEnjoy ;)\n";
- cout<<"contact ==> jaggi"<<"@"<<"interia.eu\n\n";
- if(argc==1)
- {
- cout<<"!Note!\nYou may drag your subtitles & drop on the converter's icon \nto skip typing filename.\n\n";
- cout<<"Enter filename (with extension). Be sure it is spelled correctly.\n";
- string name;
- cin>>name;
- int x=count(name.c_str());
- ifstream file(name.c_str());
- string* tab=new string[x];
- for(int i=0;i<x;i++)
- getline(file, tab[i]);
- mainFunction(tab, x, name.c_str());
- cout<<"\nDone :)\nOutput file is named "<<name.erase(name.length()-4, 4)<<"_.txt"<<".\nPress any key to exit.";
- getch();
- return 0;
- }
- int x=count(argv[1]);
- string name=argv[1];
- ifstream file(argv[1]);
- string* tab=new string[x];
- for(int i=0;i<x;i++)
- getline(file, tab[i]);
- mainFunction(tab, x, argv[1]);
- cout<<"\nDone :)\nOutput file is named "<<name.erase(name.length()-4, 4)<<"_.txt"<<".\nPress any key to exit.";
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment