update to latest BASTP version

This commit is contained in:
Adrian Ulrich committed 2013-03-24 10:57:01 +01:00
1 parent f31850174a
commit 9219cf1e3f
5 files changed
+70 -28

No files matched your search

@@ -66,7 +66,7 @@ import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Vector;
import ch.blinkenlights.bastp.Bastp;
@@ -576,7 +576,7 @@ public final class PlaybackService extends Service
}
private void applyReplayGain(MediaPlayer mp, String path) {
Hashtable tags = (new Bastp()).getTags(path);
HashMap tags = (new Bastp()).getTags(path);
float adjust = 1.0f;
if(tags.containsKey("REPLAYGAIN_TRACK_GAIN")) {
+35 -5
View File
@@ -1,10 +1,21 @@
/*****************************************************************
* This file is part of 'bastp!' - the BuggyAndSloppyTagParser! *
* *
* (C) 2012 Adrian Ulrich *
* *
* Released as 'Public Domain' software *
* *
* *
*****************************************************************/
package ch.blinkenlights.bastp;
import ch.blinkenlights.bastp.OggFile;
import ch.blinkenlights.bastp.FlacFile;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.util.Hashtable;
import java.util.HashMap;
public class Bastp {
@@ -12,8 +23,8 @@ public class Bastp {
public Bastp() {
}
public Hashtable getTags(String fname) {
Hashtable tags = new Hashtable();
public HashMap getTags(String fname) {
HashMap tags = new HashMap();
try {
RandomAccessFile ra = new RandomAccessFile(fname, "r");
tags = getTags(ra);
@@ -26,8 +37,8 @@ public class Bastp {
return tags;
}
public Hashtable getTags(RandomAccessFile s) {
Hashtable tags = new Hashtable();
public HashMap getTags(RandomAccessFile s) {
HashMap tags = new HashMap();
byte[] file_ff = new byte[4];
try {
@@ -39,6 +50,19 @@ public class Bastp {
else if(magic.equals("OggS")) {
tags = (new OggFile()).getTags(s);
}
else if(file_ff[0] == -1 && file_ff[1] == -5) { /* aka 0xfffb in real languages */
tags = (new LameHeader()).getTags(s);
}
else if(magic.substring(0,3).equals("ID3")) {
tags = (new ID3v2File()).getTags(s);
if(tags.containsKey("_hdrlen")) {
Long hlen = Long.parseLong( tags.get("_hdrlen").toString(), 10 );
HashMap lameInfo = (new LameHeader()).parseLameHeader(s, hlen);
/* add gain tags if not already present */
inheritTag("REPLAYGAIN_TRACK_GAIN", lameInfo, tags);
inheritTag("REPLAYGAIN_ALBUM_GAIN", lameInfo, tags);
}
}
tags.put("_magic", magic);
}
catch (IOException e) {
@@ -46,5 +70,11 @@ public class Bastp {
return tags;
}
private void inheritTag(String key, HashMap from, HashMap to) {
if(!to.containsKey(key) && from.containsKey(key)) {
to.put(key, from.get(key));
}
}
}
+26 -14
View File
@@ -1,8 +1,19 @@
/*****************************************************************
* This file is part of 'bastp!' - the BuggyAndSloppyTagParser! *
* *
* (C) 2012 Adrian Ulrich *
* *
* Released as 'Public Domain' software *
* *
* *
*****************************************************************/
package ch.blinkenlights.bastp;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Vector;
public class Common {
@@ -45,8 +56,8 @@ public class Common {
System.out.println("DBUG "+s);
}
public Hashtable parse_vorbis_comment(RandomAccessFile s, long offset, long payload_len) throws IOException {
Hashtable tags = new Hashtable();
public HashMap parse_vorbis_comment(RandomAccessFile s, long offset, long payload_len) throws IOException {
HashMap tags = new HashMap();
int comments = 0; // number of found comments
int xoff = 0; // offset within 'scratch'
int can_read = (int)(payload_len > MAX_PKT_SIZE ? MAX_PKT_SIZE : payload_len);
@@ -74,19 +85,20 @@ public class Common {
String[] tag_vec = tag_raw.split("=",2);
String tag_key = tag_vec[0].toUpperCase();
/* A key can have multiple values, so we need
** to store all child data in an array */
if(tags.containsKey(tag_key)) {
((Vector)tags.get(tag_key)).add(tag_vec[1]); // just add to existing vecotr
}
else {
Vector vx = new Vector();
vx.add(tag_vec[1]);
tags.put(tag_key, vx);
}
addTagEntry(tags, tag_key, tag_vec[1]);
}
return tags;
}
public void addTagEntry(HashMap tags, String key, String value) {
if(tags.containsKey(key)) {
((Vector)tags.get(key)).add(value); // just add to existing vector
}
else {
Vector vx = new Vector();
vx.add(value);
tags.put(key, vx);
}
}
}
+3 -3
View File
@@ -12,7 +12,7 @@ package ch.blinkenlights.bastp;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Enumeration;
@@ -22,11 +22,11 @@ public class FlacFile extends Common {
public FlacFile() {
}
public Hashtable getTags(RandomAccessFile s) throws IOException {
public HashMap getTags(RandomAccessFile s) throws IOException {
int xoff = 4; // skip file magic
int retry = 64;
int r[];
Hashtable tags = new Hashtable();
HashMap tags = new HashMap();
for(; retry > 0; retry--) {
r = parse_metadata_block(s, xoff);
+4 -4
View File
@@ -13,7 +13,7 @@ package ch.blinkenlights.bastp;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Hashtable;
import java.util.HashMap;
public class OggFile extends Common {
@@ -24,10 +24,10 @@ public class OggFile extends Common {
public OggFile() {
}
public Hashtable getTags(RandomAccessFile s) throws IOException {
public HashMap getTags(RandomAccessFile s) throws IOException {
long offset = 0;
int retry = 64;
Hashtable tags = new Hashtable();
HashMap tags = new HashMap();
for( ; retry > 0 ; retry-- ) {
long res[] = parse_ogg_page(s, offset);
@@ -88,7 +88,7 @@ public class OggFile extends Common {
/* In 'vorbiscomment' field is prefixed with \3vorbis in OGG files
** we check that this marker is present and call the generic comment
** parset with the correct offset (+7) */
private Hashtable parse_ogg_vorbis_comment(RandomAccessFile s, long offset, long pl_len) throws IOException {
private HashMap parse_ogg_vorbis_comment(RandomAccessFile s, long offset, long pl_len) throws IOException {
final int pfx_len = 7;
byte[] pfx = new byte[pfx_len];