-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.java
221 lines (209 loc) · 9.75 KB
/
Setup.java
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
import javax.sound.sampled.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Map;
/**
* Created by David on 04/01/2017.
*/
public class Setup {
public Setup(String user) {
System.out.println("USER SETUP: " + user);
songSetup(user);
videoSetup(user);
accountSetup(user);
}
public void accountSetup(String user)
{
try {
File fHtml = new File(System.getProperty("user.dir") + "\\src\\HTML\\manage_account_temp.html");
File fdata = new File(System.getProperty("user.dir") + "\\src\\Accounts\\" + user + "\\" + user + ".txt");
String html = null;
String data = null;
if (fHtml.exists()) {
FileReader fis = new FileReader(fHtml);
BufferedReader br = new BufferedReader(fis);
for(int i = 0; i < fHtml.length(); i++)
{
html += br.readLine();
html += "\r\n";
}
}
if (fHtml.exists()) {
FileReader fis = new FileReader(fdata);
BufferedReader br = new BufferedReader(fis);
for(int i = 0; i < fdata.length(); i++)
{
data += br.readLine();
data += "\r\n";
}
}
html = html.replace("null", "").trim();
data = data.replace("null", "").trim();
data += "\r\n";
System.out.println(html);
System.out.println(data);
System.out.println(data.indexOf("\r\n", data.indexOf("country")));
html = html.replace("\"Username\"", data.substring(data.indexOf("uname=")+"uname=".length(), data.indexOf("\r\n")));
html = html.replace("\"First Name\"", data.substring(data.indexOf("fname=")+"fname=".length(), data.indexOf("\r\n", + data.indexOf("fname"))));
html = html.replace("\"Second Name\"", data.substring(data.indexOf("sname=")+"sname=".length(), data.indexOf("\r\n", data.indexOf("sname"))));
html = html.replace("\"DATE\"", data.substring(data.indexOf("DOB=")+"DOB=".length(), data.indexOf("\r\n", data.indexOf("DOB"))));
html = html.replace("\"Address Line 1\"", data.substring(data.indexOf("addr1=")+"addr1=".length(), data.indexOf("\r\n", data.indexOf("addr1"))));
html = html.replace("\"Address Line 2\"", data.substring(data.indexOf("addr2=")+"addr2=".length(), data.indexOf("\r\n", data.indexOf("addr2"))));
html = html.replace("\"City\"", data.substring(data.indexOf("city=")+"city=".length(), data.indexOf("\r\n", data.indexOf("city"))));
html = html.replace("\"State\"", data.substring(data.indexOf("state=")+"state=".length(), data.indexOf("\r\n", data.indexOf("state"))));
html = html.replace("\"Country\"", data.substring(data.indexOf("country=")+"country=".length(), data.indexOf("\r\n", data.indexOf("country"))));
File fout = new File(System.getProperty("user.dir") + "\\src\\HTML\\manage_account.html");
FileWriter fw = new FileWriter(fout);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(html, 0, html.length());
bw.flush();
bw.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
public void songSetup(String user)
{
File f = new File(System.getProperty("user.dir") + "\\src\\Accounts\\" + user + "\\Audio");
File musicPlayer = new File(System.getProperty("user.dir")+"\\src\\HTML\\music_player.html");
File deleteFile = new File(System.getProperty("user.dir") + "\\src\\Accounts\\" + user + "\\Audio\\desktop.ini");
if(deleteFile.exists())
{
deleteFile.delete();
}
System.out.println(f);
if(f.exists())
{
System.out.println("ITS HERE");
}
else
{
System.out.println("File does not exist");
}
String htmlCode = "";
String input = "";
File[] files = null;
files = f.listFiles();
String[] songName = new String[files.length];
String[] songArtist = new String[files.length];
String[] songDuration = new String[files.length];
for(int i = 0; i < files.length; i++)
{
System.out.println(files[i]);
}
try{
for(int i = 0; i < files.length; i++) {
if (files[i].toString().contains("-")) {
songName[i] = files[i].toString().substring(files[i].toString().lastIndexOf("\\") + 1, files[i].toString().lastIndexOf("-"));
songArtist[i] = files[i].toString().substring(files[i].toString().lastIndexOf("-") + 1, files[i].toString().lastIndexOf(".mp3"));
AudioFileFormat baseFileFormat = new MpegAudioFileReader().getAudioFileFormat(files[i]);
Map properties = baseFileFormat.properties();
double duration = (long) properties.get("duration");
int minute = (int) ((duration / 1000) / 60) / 1000;
int seconds = (int) (60 * ((((duration / 1000) / 60) / 1000) - minute));
songDuration[i] = minute + ":" + seconds;
System.out.println(songName[i]);
System.out.println(songArtist[i]);
System.out.println(songDuration[i]);
}
}
FileReader fr = new FileReader(System.getProperty("user.dir")+"\\src\\HTML\\music_player.html");
BufferedReader br = new BufferedReader(fr);
do {
input=br.readLine()+"\r\n";
htmlCode+=input;
}while(!htmlCode.contains("<tbody>") && input != null);
for(int j = 0; j < files.length; j++)
{
htmlCode+=("\t\t\t\t<tr>\r\n");
htmlCode+=("\t\t\t\t\t<td>"+(j+1)+"</td>\r\n" +
" \t\t\t\t\t<td>"+songName[j]+"</td>\r\n" +
" \t\t\t\t\t<td>"+songArtist[j]+"</td>\r\n" +
" \t\t\t\t\t<td>"+songDuration[j]+"</td>\r\n" +
" \t\t\t\t\t<td><button type=\"button\" id=\"btn"+j+"\" class=\"btn btn-active btn-xs\" onclick=\"loadDoc('"+songName[j].replace(" ", "@")+"-"+songArtist[j].replace(" ", "@")+"', '"+j+"')\">Play</button><td>\r\n");
htmlCode+=("\t\t\t\t</tr>\r\n");
}
do {
input = br.readLine();
}while(!input.contains("</tbody>") && input != null);
htmlCode+=input+"\r\n";
do{
input = br.readLine()+"\r\n";
htmlCode+=input;
} while(!htmlCode.contains("</html>") && input != null);
//System.out.println(htmlCode);
br.close();
FileWriter fw = new FileWriter(musicPlayer);
PrintWriter pw = new PrintWriter(fw);
htmlCode.replace("null", "");
pw.write(htmlCode);
pw.flush();
pw.close();
}catch(Exception ee)
{
ee.printStackTrace();
}
}
public void videoSetup(String user)
{
File f = new File(System.getProperty("user.dir") + "\\src\\Accounts\\" + user + "\\Videos");
File musicPlayer = new File(System.getProperty("user.dir")+"\\src\\HTML\\theatre.html");
File deleteFile = new File(System.getProperty("user.dir") + "\\src\\Accounts\\" + user + "\\Videos\\desktop.ini");
if(deleteFile.exists())
{
deleteFile.delete();
}
String htmlCode = "";
String input = "";
File[] files = null;
files = f.listFiles();
String[] videoTitle= new String[files.length];
for(int i = 0; i < files.length; i++)
{
System.out.println(files[i]);
}
try{
for(int i = 0; i < files.length; i++) {
videoTitle[i] = files[i].toString().substring(files[i].toString().lastIndexOf("\\") + 1, files[i].toString().lastIndexOf(".mp4"));
System.out.println(files[i].toString());
}
FileReader fr = new FileReader(System.getProperty("user.dir")+"\\src\\HTML\\theatre.html");
BufferedReader br = new BufferedReader(fr);
do {
input=br.readLine()+"\r\n";
htmlCode+=input;
}while(!htmlCode.contains("<tbody>") && input != null);
System.out.println(files.length);
for(int j = 0; j < files.length; j++)
{
htmlCode+=("\t\t\t\t<tr>\r\n");
htmlCode+=("\t\t\t\t\t<td>"+(j+1)+"</td>\r\n" +
" \t\t\t\t\t<td>"+videoTitle[j]+"</td>\r\n" +
" \t\t\t\t\t<td><button type=\"button\" id=\"btn"+j+"\" class=\"btn btn-active btn-sm\" onclick=\"loadDoc('"+videoTitle[j]+"', '"+j+"')\">Play<span class=\"glyphicon glyphicon-play\"></span></button><td>\r\n");
htmlCode+=("\t\t\t\t</tr>\r\n");
}
do {
input = br.readLine();
}while(!input.contains("</tbody>") && input != null);
htmlCode+=input+"\r\n";
do{
input = br.readLine()+"\r\n";
htmlCode+=input;
} while(!htmlCode.contains("</html>") && input != null);
//System.out.println(htmlCode);
br.close();
FileWriter fw = new FileWriter(musicPlayer);
PrintWriter pw = new PrintWriter(fw);
htmlCode.replace("null", "");
pw.write(htmlCode);
pw.flush();
pw.close();
}catch(Exception ee)
{
ee.printStackTrace();
}
}
}