Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <thread>
  5. #include <regex>
  6. #include <cstdio>
  7.  
  8. using namespace std;
  9.  
  10. int main(int argc,char* argv[])
  11. {
  12. if (argc < 2) {
  13. printf("filename not given\n");
  14. exit(-1);
  15. }
  16. int i = 1;
  17. while (i < argc) {
  18. string filename(argv[i++]);
  19. string line;
  20. ifstream in(filename);
  21.  
  22. //把文件后缀.vtt换成.srt,
  23. regex name_pattern("(.*\\.)vtt");
  24. //regex name_pattern("(.*\\.)en.vtt");
  25. string replace = "$1srt";
  26. string newname = regex_replace(filename,name_pattern,replace);
  27.  
  28. ofstream fout(newname);
  29.  
  30. regex ecma_pattern("(\\d{2}):(\\d{2}).*");
  31. //regex basic_pattern("[0-9]\\{2\\}:[0-9]\\{2\\}.*",regex::basic);
  32.  
  33. //用来把点号换成逗号
  34. regex replace_period("(\\d{2}:\\d{2}:\\d{2})\\.(\\d{3} --> )(\\d{2}:\\d{2}:\\d{2})\\.");
  35. string replace2 = "$1,$2$3,";
  36.  
  37. int cnt = 1;
  38. int ignore = 0;
  39. while (std::getline(in,line)) {
  40. /*
  41. 前三行是这三行,忽略
  42. WEBVTT
  43. Kind: captions
  44. Language: en
  45. */
  46. if (ignore++ < 3) continue;
  47.  
  48. if (regex_match(line,ecma_pattern)) {
  49. fout << cnt++ << endl;
  50. fout << regex_replace(line,replace_period,replace2) << endl;
  51. continue;
  52. }
  53. fout << line << endl;
  54. }
  55.  
  56. in.close();
  57. fout.close();
  58. //std::remove(filename.c_str());//也许手工删除vtt文件要好
  59. }
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement