-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvert.java
More file actions
66 lines (66 loc) · 1.76 KB
/
Convert.java
File metadata and controls
66 lines (66 loc) · 1.76 KB
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
import java.io.*;
import java.util.*;
class Convert{
public static void main(String args[]) throws IOException{
BufferedReader brr=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter File Name Format : Videoid.json");
String fileName=brr.readLine();
String out_file="subs_"+fileName.substring(0,fileName.indexOf('.'))+".srt.sjson";
System.out.println(out_file);
FileReader fr=null;
try{
fr=new FileReader(fileName);
}
catch(Exception e){
System.out.println(e);
}
BufferedReader br=new BufferedReader(fr);
StringTokenizer st=new StringTokenizer(br.readLine(),":");
int i=1;
st.nextToken();
int size=(int)Math.ceil((st.countTokens()+1)/3.0);
int[] starts=new int[size];
int s=0,e=0,t=0;
int[] ends=new int[size];
String texts[]=new String[size];
while(st.hasMoreTokens()){
String token=st.nextToken();
StringTokenizer sub=null;
String str=null;
if((i%3)!=0)
{sub=new StringTokenizer(token,",");
str=sub.nextToken();}
if(i%3==1) starts[s++]=Integer.parseInt(str);
else if(i%3==2) ends[e++]=Integer.parseInt(str);
else {
StringTokenizer sub3=new StringTokenizer(token,"}");
str=sub3.nextToken();
texts[t++]=str;
}
i++;
}
fr.close();
FileWriter fw=null;
try{
fw=new FileWriter(out_file);
}
catch(Exception ex){
System.out.println(ex);
}
int j=0;
fw.write("{\n \"start\": [\n");
for(j=0;j<s-1;j++)
fw.write(" "+starts[j]+",\n");
fw.write(" "+starts[j]+"\n");
fw.write(" ]\n \"end\": [\n");
for(j=0;j<e-1;j++)
fw.write(" "+ends[j]+",\n");
fw.write(" "+ends[j]+"\n");
fw.write(" ]\n \"text\": [\n");
for(j=0;j<t-1;j++)
fw.write(" "+texts[j]+",\n");
fw.write(" "+texts[j]+"\n");
fw.write(" ]\n}");
fw.close();
}
}