1 5 package com.dotmarketing.portlets.files.model; 6 7 import java.io.IOException ; 8 import java.lang.reflect.InvocationTargetException ; 9 10 import org.apache.commons.beanutils.BeanUtils; 11 import org.farng.mp3.AbstractMP3Tag; 12 import org.farng.mp3.TagException; 13 14 import com.dotmarketing.portlets.files.factories.FileFactory; 15 import com.dotmarketing.util.UtilMethods; 16 17 21 public class MP3File extends File { 22 23 26 27 String [] genres = new String [] { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", 28 "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", 29 "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", 30 "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", 31 "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", 32 "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", 33 "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", 34 "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", 35 "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", 36 "Hard Rock", "Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", 37 "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", 38 "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", 39 "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", 40 "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", 41 "Duet", "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall" }; 42 43 private static final long serialVersionUID = 1L; 44 45 String title; 46 47 String artist; 48 49 String album; 50 51 String year; 52 53 int bitrate; 54 55 double frequency; 56 57 long duration; 58 59 String genre; 60 61 public MP3File(File file) throws IOException , IllegalAccessException , InvocationTargetException , TagException { 62 63 if (!file.getFileName().toLowerCase().endsWith("mp3")) { 64 throw new IOException ("Not an mp3 file"); 65 } 66 BeanUtils.copyProperties(this, file); 67 68 java.io.File ioFile = new java.io.File (FileFactory.getRealAssetPath(file)); 69 org.farng.mp3.MP3File mp3 = new org.farng.mp3.MP3File(ioFile); 70 71 if (ioFile.length() > 0 && mp3.getBitRate() > 0) { 72 duration = (long) ((double) ioFile.length() / ((double) mp3.getBitRate() / 8.0)); 73 } 74 bitrate = mp3.getBitRate(); 75 frequency = mp3.getFrequency(); 76 AbstractMP3Tag tag = null; 78 if (mp3.hasID3v1Tag()) { 79 tag = mp3.getID3v1Tag(); 80 81 title = tag.getSongTitle(); 82 if(!"New Artist".equals( tag.getLeadArtist())){ 83 artist = tag.getLeadArtist(); 84 } 85 if(!"New Title".equals( tag.getAlbumTitle())){ 86 album = tag.getAlbumTitle(); 87 } 88 year = tag.getYearReleased(); 89 genre = lookupGenre(tag.getSongGenre()); 90 91 } 92 if (mp3.hasID3v2Tag()) { 93 tag = mp3.getID3v2Tag(); 94 if (title == null) 95 title = tag.getSongTitle(); 96 if (artist == null && !"New Artist".equals( tag.getLeadArtist())) 97 artist = tag.getLeadArtist(); 98 if (album == null && !"New Title".equals( tag.getAlbumTitle())) 99 album = tag.getAlbumTitle(); 100 if (year == null) 101 year = tag.getYearReleased(); 102 if (genre == null) 103 genre = lookupGenre(tag.getSongGenre()); 104 105 } 106 } 107 108 public String getAlbum() { 109 return album; 110 } 111 112 public void setAlbum(String album) { 113 this.album = album; 114 } 115 116 public String getArtist() { 117 return artist; 118 } 119 120 public void setArtist(String artist) { 121 this.artist = artist; 122 } 123 124 public long getDuration() { 125 return duration; 126 } 127 128 public void setDuration(long duration) { 129 this.duration = duration; 130 } 131 132 public int getBitrate() { 133 return bitrate; 134 } 135 136 public void setBitrate(int bitrate) { 137 this.bitrate = bitrate; 138 } 139 140 public double getFrequency() { 141 return frequency; 142 } 143 144 public void setFrequency(double frequency) { 145 this.frequency = frequency; 146 } 147 148 public String getGenre() { 149 return genre; 150 } 151 152 public void setGenre(String genre) { 153 this.genre = genre; 154 } 155 156 public String getTitle() { 157 return title; 158 } 159 160 public void setTitle(String title) { 161 this.title = title; 162 } 163 164 public String getYear() { 165 return year; 166 } 167 168 public void setYear(String year) { 169 this.year = year; 170 } 171 172 private String lookupGenre(String x) { 173 174 try { 175 x = x.replaceAll("[()]", ""); 176 int y = Integer.parseInt(x); 177 return genres[y]; 178 } catch (Exception e) { 179 return null; 180 } 181 } 182 183 } 184 | Popular Tags |