-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReader.java
More file actions
147 lines (131 loc) · 5.32 KB
/
Copy pathReader.java
File metadata and controls
147 lines (131 loc) · 5.32 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
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
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.ID3v1;
import com.mpatric.mp3agic.ID3v2;
import java.io.RandomAccessFile;
import com.mpatric.mp3agic.UnsupportedTagException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public class Reader{
private File folder;
public Reader(){
this.folder = new File(".");
showCurrentPath();
}
public Reader( String pathString ){
this.folder = new File(pathString);
showCurrentPath();
}
public void showCurrentPath(){
System.out.println("Curren path " + this.folder.getAbsolutePath() );
}
public String getCurrentPath(){
try{
return this.folder.getCanonicalPath();
} catch ( IOException ioe ){
return this.folder.getAbsolutePath();
}
}
public File[] getChildren(){
return this.folder.listFiles();
}
public void setCurrentPath( String newPath ){
this.folder = new File( getCurrentPath() + "/" + newPath );
showCurrentPath();
}
public void readDir(){
String[] fileNames = this.folder.list();
for(int i=0;i<fileNames.length;i++){
System.out.println( fileNames[i] );
}
}
public void goUp(){
if( this.folder.getParentFile() == null ){
this.folder = new File( folder.getAbsoluteFile().getParentFile().getParentFile().getAbsolutePath() );
} else {
this.folder = new File( folder.getAbsoluteFile().getParentFile().getAbsolutePath() );
}
showCurrentPath();
}
public void cleanDir() {
File[] files = this.folder.listFiles();
for(int i=0;i<files.length;i++){
if(files[i].isFile()){
try {
readMp3File( this.folder.getAbsolutePath() + "/" + files[i].getName() );
} catch (InvalidDataException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (UnsupportedTagException e) {
e.printStackTrace();
}
}
}
}
private void printId3v1Content( Mp3File mp3file ){
if( mp3file.hasId3v1Tag() ){
ID3v1 id3v1Tag = mp3file.getId3v1Tag();
System.out.println(
"Id3v1:"
+"\nTrack: " + id3v1Tag.getTrack()
+"\nArtist: " + id3v1Tag.getArtist()
+"\nTitle: " + id3v1Tag.getTitle()
+"\nAlbum: " + id3v1Tag.getAlbum()
+"\nYear: " + id3v1Tag.getYear()
+"\nGenre: " + id3v1Tag.getGenre()
+"\nComment: " + id3v1Tag.getComment()
+"\n"
);
waitSecs( 1.5 );
} else {
System.out.print("No Id3v1 tags were found. \n\n");
}
}
private void waitSecs( double seconds ){
double milisecs = seconds * 1000;
try {
Thread.sleep( (long)milisecs );
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void printId3v2Content( Mp3File mp3file ){
if (mp3file.hasId3v2Tag()) {
ID3v2 id3v2Tag = mp3file.getId3v2Tag();
System.out.print(
"Id3v2:"
+"\nTrack: " + id3v2Tag.getTrack()
+"\nArtist: " + id3v2Tag.getArtist()
+"\nTitle: " + id3v2Tag.getTitle()
+"\nAlbum: " + id3v2Tag.getAlbum()
+"\nYear: " + id3v2Tag.getYear()
+"\nGenre: " + id3v2Tag.getGenre() + " (" + id3v2Tag.getGenreDescription() + ")"
+"\nComment: " + id3v2Tag.getComment()
+"\nComposer: " + id3v2Tag.getComposer()
+"\nPublisher: " + id3v2Tag.getPublisher()
+"\nOriginal artist: " + id3v2Tag.getOriginalArtist()
+"\nAlbum artist: " + id3v2Tag.getAlbumArtist()
+"\nCopyright: " + id3v2Tag.getCopyright()
+"\nURL: " + id3v2Tag.getUrl()
+"\nEncoder: " + id3v2Tag.getEncoder()
+"\n"
+"\n"
);
waitSecs( 1.5 );
} else {
System.out.print("No Id3v2 tags were found. \n\n");
}
}
private void readMp3File(String route) throws InvalidDataException, IOException, UnsupportedTagException {
System.out.println( "File: " + route );
try{
Mp3File mp3file = new Mp3File( route );
printId3v1Content( mp3file );
printId3v2Content( mp3file );
} catch(InvalidDataException ide){
System.out.println("Error: " + ide.getMessage() );
}
}
}