Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <thread>
- #include <regex>
- #include <cstdio>
- using namespace std;
- int main(int argc,char* argv[])
- {
- if (argc < 2) {
- printf("filename not given\n");
- exit(-1);
- }
- int i = 1;
- while (i < argc) {
- string filename(argv[i++]);
- string line;
- ifstream in(filename);
- //把文件后缀.vtt换成.srt,
- regex name_pattern("(.*\\.)vtt");
- //regex name_pattern("(.*\\.)en.vtt");
- string replace = "$1srt";
- string newname = regex_replace(filename,name_pattern,replace);
- ofstream fout(newname);
- regex ecma_pattern("(\\d{2}):(\\d{2}).*");
- //regex basic_pattern("[0-9]\\{2\\}:[0-9]\\{2\\}.*",regex::basic);
- //用来把点号换成逗号
- regex replace_period("(\\d{2}:\\d{2}:\\d{2})\\.(\\d{3} --> )(\\d{2}:\\d{2}:\\d{2})\\.");
- string replace2 = "$1,$2$3,";
- int cnt = 1;
- int ignore = 0;
- while (std::getline(in,line)) {
- /*
- 前三行是这三行,忽略
- WEBVTT
- Kind: captions
- Language: en
- */
- if (ignore++ < 3) continue;
- if (regex_match(line,ecma_pattern)) {
- fout << cnt++ << endl;
- fout << regex_replace(line,replace_period,replace2) << endl;
- continue;
- }
- fout << line << endl;
- }
- in.close();
- fout.close();
- //std::remove(filename.c_str());//也许手工删除vtt文件要好
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement