-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathProgram.cs
74 lines (62 loc) · 2.33 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Collections;
namespace LyndaCaptionToSrtConvertor
{
class Program
{
static void Main(string[] args)
{
string folderPath = "";
int index = 0;
foreach (string arg in args)
{
if (string.IsNullOrWhiteSpace(arg))
{
index++;
continue;
}
switch (arg.ToUpper())
{
case "/D": // Directory
folderPath = args[index + 1];
Console.WriteLine("Directory with captions: " + folderPath);
break;
}
}
//directory with srt files, will get from console in real use case
if (String.IsNullOrEmpty(folderPath))
{
folderPath = "..\\tests";
Console.WriteLine("defaulting to ..\\tests directory. Please input full subtitle folder path in the /D parameter.");
}
if (!Directory.Exists(folderPath))
{
Console.WriteLine("Directory not found. Press any key to exit");
// Console app
Console.ReadKey();
System.Environment.Exit(1);
}
foreach (string entry in Directory.EnumerateFiles(folderPath, "*.caption", SearchOption.AllDirectories))
{
string filePath = entry;
if (!File.Exists(filePath))
throw new FileNotFoundException();
string filename = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)) + ".srt";
CaptionToSrt aCaption = new CaptionToSrt(filePath);
//got list of timestamps here and list of texts, start building the .srt file
aCaption.OutFile = filename;
aCaption.convertToSrt();
Console.WriteLine("Done " + filename);
}
Console.WriteLine("Press any key to exit the program...");
Console.ReadKey();
}
}
}