diff options
Diffstat (limited to 'songdbj/SongEntry.java')
-rw-r--r-- | songdbj/SongEntry.java | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/songdbj/SongEntry.java b/songdbj/SongEntry.java deleted file mode 100644 index cf6f887a7b..0000000000 --- a/songdbj/SongEntry.java +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
1 | import java.util.*; | ||
2 | import java.io.*; | ||
3 | import javax.sound.sampled.UnsupportedAudioFileException; | ||
4 | import java.lang.NumberFormatException; | ||
5 | import net.shredzone.ifish.ltr.LTR; | ||
6 | |||
7 | public class SongEntry extends Entry implements Comparable { | ||
8 | protected TagInfo info; | ||
9 | protected LTR tag; | ||
10 | protected ArtistEntry artist; | ||
11 | protected AlbumEntry album; | ||
12 | protected FileEntry file; | ||
13 | |||
14 | public SongEntry(FileEntry f) { | ||
15 | file=f; | ||
16 | file.setSongEntry(this); | ||
17 | readTagInfo(); | ||
18 | } | ||
19 | |||
20 | public void setAlbum(AlbumEntry a) { album=a; } | ||
21 | public void setArtist(ArtistEntry a) { artist=a; } | ||
22 | public AlbumEntry getAlbum() { return album; } | ||
23 | public ArtistEntry getArtist() { return artist; } | ||
24 | public FileEntry getFile() { return file; } | ||
25 | |||
26 | public int compareTo(Object o) { | ||
27 | return String.CASE_INSENSITIVE_ORDER.compare(getName(),((SongEntry)o).getName()); | ||
28 | } | ||
29 | |||
30 | public String getName() { | ||
31 | String title=tag.getTitle(); | ||
32 | if(title==null) | ||
33 | title = stripExt(file.getFile().getName()); | ||
34 | title=title.trim(); | ||
35 | if(title.equals("")) | ||
36 | title = stripExt(file.getFile().getName()); | ||
37 | return title; | ||
38 | } | ||
39 | |||
40 | public static String stripExt(String t) { | ||
41 | return t.substring(0,t.lastIndexOf('.')); | ||
42 | } | ||
43 | |||
44 | public String getAlbumTag() { | ||
45 | String album=tag.getAlbum(); | ||
46 | if(album==null) | ||
47 | album = "<no album tag>"; | ||
48 | album=album.trim(); | ||
49 | if(album.equals("")) | ||
50 | album = "<no album tag>"; | ||
51 | if(TagDatabase.getInstance().dirisalbumname&&album.equals("<no album tag>")) { | ||
52 | album = file.getFile().getParentFile().getName(); | ||
53 | } | ||
54 | return album; | ||
55 | } | ||
56 | |||
57 | public String getArtistTag() { | ||
58 | String artist=tag.getArtist(); | ||
59 | if(artist==null) | ||
60 | artist = "<no artist tag>"; | ||
61 | artist=artist.trim(); | ||
62 | if(artist.equals("")) | ||
63 | artist = "<no artist tag>"; | ||
64 | return artist; | ||
65 | } | ||
66 | |||
67 | public String getGenreTag() { | ||
68 | String genre=tag.getGenre(); | ||
69 | if(genre==null) | ||
70 | genre = "<no genre tag>"; | ||
71 | genre=genre.trim(); | ||
72 | if(genre.equals("")) | ||
73 | genre = "<no genre tag>"; | ||
74 | return genre; | ||
75 | } | ||
76 | |||
77 | public int getYear() { | ||
78 | try { | ||
79 | return Integer.parseInt(tag.getYear()); | ||
80 | } catch(NumberFormatException e) { | ||
81 | return 0; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | public int getTrack() { | ||
86 | try { | ||
87 | return Integer.parseInt(tag.getTrack()); | ||
88 | } catch(NumberFormatException e) { | ||
89 | return 0; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | public int getBitRate() { if(info==null) return -1; return info.getBitRate()/1000; } | ||
94 | |||
95 | public int getPlayTime() { if(info==null) return -1; return (int)info.getPlayTime(); } | ||
96 | |||
97 | public int getSamplingRate() { if(info==null) return -1; return info.getSamplingRate(); } | ||
98 | |||
99 | public int getFirstFrameOffset() { if(info==null) return 0; return info.getFirstFrameOffset(); } | ||
100 | |||
101 | public boolean gotTagInfo() { return tag!=null; } | ||
102 | |||
103 | protected void readTagInfo() { | ||
104 | // Check Mpeg format. | ||
105 | try | ||
106 | { | ||
107 | info = new MpegInfo(); | ||
108 | info.load(file.getFile()); | ||
109 | } | ||
110 | /* catch (IOException ex) | ||
111 | { | ||
112 | //ex.printStackTrace(); | ||
113 | System.out.println(ex); | ||
114 | info = null; | ||
115 | }*/ | ||
116 | catch (Exception ex) | ||
117 | { | ||
118 | // Error.. | ||
119 | info = null; | ||
120 | } | ||
121 | |||
122 | if (info == null) | ||
123 | { | ||
124 | // Check Ogg Vorbis format. | ||
125 | try | ||
126 | { | ||
127 | info = new OggVorbisInfo(); | ||
128 | info.load(file.getFile()); | ||
129 | } | ||
130 | /*catch (IOException ex) | ||
131 | { | ||
132 | //ex.printStackTrace(); | ||
133 | System.out.println(ex); | ||
134 | info = null; | ||
135 | }*/ | ||
136 | catch (Exception ex) | ||
137 | { | ||
138 | // Not Ogg Vorbis Format | ||
139 | //System.out.println("Failed reading tag for "+location.getAbsolutePath()+", tried mp3 and vorbis."); | ||
140 | info = null; | ||
141 | } | ||
142 | } | ||
143 | tag = LTR.create(file.getFile()); | ||
144 | } | ||
145 | |||
146 | public void write(DataOutputStream w) throws IOException { | ||
147 | String name=getName(); | ||
148 | w.writeBytes(name); | ||
149 | for(int x=TagDatabase.getInstance().songlen-name.length();x>0;x--) | ||
150 | w.write(0); | ||
151 | w.writeInt(artist.getOffset()); | ||
152 | w.writeInt(album.getOffset()); | ||
153 | w.writeInt(file.getOffset()); | ||
154 | w.writeBytes(getGenreTag()); | ||
155 | for(int x=TagDatabase.getInstance().genrelen-getGenreTag().length();x>0;x--) | ||
156 | w.write(0); | ||
157 | w.writeShort(getBitRate()); | ||
158 | w.writeShort(getYear()); | ||
159 | w.writeInt(getPlayTime()); | ||
160 | w.writeShort(getTrack()); | ||
161 | w.writeShort(getSamplingRate()); | ||
162 | } | ||
163 | public static int entrySize() { | ||
164 | TagDatabase td=TagDatabase.getInstance(); | ||
165 | return td.songlen+12+td.genrelen+12; | ||
166 | } | ||
167 | } \ No newline at end of file | ||