* added lots of extra metadata bindings for music processing

This commit is contained in:
Reinhard Pointner 2013-01-23 18:15:53 +00:00
parent 2a8e9a91b7
commit 631a81ec4e
5 changed files with 149 additions and 27 deletions

View File

@ -516,6 +516,9 @@ public class CmdlineOperations implements CmdlineInterface {
for (Entry<File, AudioTrack> match : service.lookup(audioFiles).entrySet()) {
File file = match.getKey();
AudioTrack music = match.getValue();
if (music == null)
continue;
String newName = (format != null) ? format.format(new MediaBindingBean(music, file)) : validateFileName(music.toString());
renameMap.put(file, getDestinationFile(file, newName, outputDir));

View File

@ -70,7 +70,7 @@ public class MediaBindingBean {
if (infoObject instanceof Movie)
return getMovie().getName();
if (infoObject instanceof AudioTrack)
return getMusic().getArtist();
return getAlbumArtist() != null ? getAlbumArtist() : getArtist();
return null;
}
@ -83,7 +83,7 @@ public class MediaBindingBean {
if (infoObject instanceof Movie)
return getMovie().getYear();
if (infoObject instanceof AudioTrack)
return new Scanner(getMediaInfo(StreamKind.General, 0, "Recorded_Date")).useDelimiter("\\D+").nextInt();
return getReleaseDate() != null ? ((Date) getReleaseDate()).getYear() : new Scanner(getMediaInfo(StreamKind.General, 0, "Recorded_Date")).useDelimiter("\\D+").nextInt();
return null;
}
@ -126,7 +126,7 @@ public class MediaBindingBean {
@Define("t")
public String getTitle() {
if (infoObject instanceof AudioTrack) {
return getMusic().getTitle();
return getMusic().getTrackTitle() != null ? getMusic().getTrackTitle() : getMusic().getTitle();
}
// single episode format
@ -151,6 +151,9 @@ public class MediaBindingBean {
if (infoObject instanceof Movie) {
return getMetaInfo().getProperty("released");
}
if (infoObject instanceof AudioTrack) {
return getMusic().getAlbumReleaseDate();
}
// no date info for the model
return null;
@ -528,9 +531,9 @@ public class MediaBindingBean {
}
@Define("title")
public String getSongTitle() {
return getMusic().getTitle();
@Define("albumArtist")
public String getAlbumArtist() {
return getMusic().getAlbumArtist();
}
@ -567,7 +570,7 @@ public class MediaBindingBean {
@Define("pi")
public Integer getPart() {
if (infoObject instanceof AudioTrack)
return Integer.parseInt(getMediaInfo(StreamKind.General, 0, "Track/Position"));
return getMusic().getTrack() != null ? getMusic().getTrack() : Integer.parseInt(getMediaInfo(StreamKind.General, 0, "Track/Position"));
if (infoObject instanceof MoviePart)
return ((MoviePart) infoObject).getPartIndex();
@ -577,7 +580,12 @@ public class MediaBindingBean {
@Define("pn")
public Integer getPartCount() {
return ((MoviePart) infoObject).getPartCount();
if (infoObject instanceof AudioTrack)
return getMusic().getTrackCount();
if (infoObject instanceof MoviePart)
return ((MoviePart) infoObject).getPartCount();
return null;
}

View File

@ -33,4 +33,4 @@ music.example[1]: {n} - {album} - {t}
# artist - title [crc32]
music.example[2]: {n} - {t} {[crc32]}
# artist - title [2ch, 128000]
music.example[3]: {n} - {t} {[af, audio.BitRate]}
music.example[3]: {pi.pad(2)} {n} - {t} {[af, audio.BitRate]}

View File

@ -65,7 +65,7 @@ public class AcoustID implements MusicIdentificationService {
public AudioTrack lookup(String duration, String fingerprint) throws IOException, InterruptedException {
// http://api.acoustid.org/v2/lookup?client=8XaBELgH&meta=recordings+releasegroups+compress&duration=641&fingerprint=AQABz0qUkZK4oOfhL-CPc4e5C_wW2H2QH9uDL4cvoT8UNQ-eHtsE8cceeFJx-LiiHT-aPzhxoc-Opj_eI5d2hOFyMJRzfDk-QSsu7fBxqZDMHcfxPfDIoPWxv9C1o3yg44d_3Df2GJaUQeeR-cb2HfaPNsdxHj2PJnpwPMN3aPcEMzd-_MeB_Ej4D_CLP8ghHjkJv_jh_UDuQ8xnILwunPg6hF2R8HgzvLhxHVYP_ziJX0eKPnIE1UePMByDJyg7wz_6yELsB8n4oDmDa0Gv40hf6D3CE3_wH6HFaxCPUD9-hNeF5MfWEP3SCGym4-SxnXiGs0mRjEXD6fgl4LmKWrSChzzC33ge9PB3otyJMk-IVC6R8MTNwD9qKQ_CC8kPv4THzEGZS8GPI3x0iGVUxC1hRSizC5VzoamYDi-uR7iKPhGSI82PkiWeB_eHijvsaIWfBCWH5AjjCfVxZ1TQ3CvC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hihgEChFCAAWEIEYwIJYwViAAlHCBIGEIEAEIQAoBwwgwiEBAEEEOoEwBY4wRwxAhBgAcKAESIQAwwIowRFhoBhAE
URL url = new URL("http://api.acoustid.org/v2/lookup?client=" + apikey + "&meta=recordings+releasegroups+compress&duration=" + duration + "&fingerprint=" + fingerprint);
URL url = new URL("http://api.acoustid.org/v2/lookup?client=" + apikey + "&meta=recordings+releasegroups+releases+tracks+compress&duration=" + duration + "&fingerprint=" + fingerprint);
Cache cache = Cache.getCache("web-datasource");
AudioTrack audioTrack = cache.get(url, AudioTrack.class);
@ -82,23 +82,73 @@ public class AcoustID implements MusicIdentificationService {
throw new IOException("acoustid responded with error: " + data.get("status"));
}
try {
Map<?, ?> recording = (Map<?, ?>) ((List<?>) ((Map<?, ?>) ((List<?>) data.get("results")).get(0)).get("recordings")).get(0);
String artist = (String) ((Map<?, ?>) ((List<?>) recording.get("artists")).get(0)).get("name");
String title = (String) recording.get("title");
String album = null;
try {
album = (String) ((Map<?, ?>) ((List<?>) recording.get("releasegroups")).get(0)).get("title");
} catch (Exception e) {
// allow album to be null
for (Object result : (List<?>) data.get("results")) {
try {
Map<?, ?> recording = (Map<?, ?>) ((List<?>) ((Map<?, ?>) result).get("recordings")).get(0);
String artist = (String) ((Map<?, ?>) ((List<?>) recording.get("artists")).get(0)).get("name");
String title = (String) recording.get("title");
audioTrack = new AudioTrack(artist, title, null);
try {
Map<?, ?> releaseGroup = (Map<?, ?>) ((List<?>) recording.get("releasegroups")).get(0);
List<?> releases = (List<?>) releaseGroup.get("releases");
for (Object it : releases) {
try {
AudioTrack thisRelease = new AudioTrack(artist, title, null);
Map<?, ?> release = (Map<?, ?>) it;
Map<?, ?> date = (Map<?, ?>) release.get("date");
try {
thisRelease.albumReleaseDate = new Date(Integer.parseInt(date.get("year").toString()), Integer.parseInt(date.get("month").toString()), Integer.parseInt(date.get("day").toString()));
} catch (Exception e) {
// ignore
}
if (thisRelease.albumReleaseDate == null || thisRelease.albumReleaseDate.getTimeStamp() >= (audioTrack.albumReleaseDate == null ? Long.MAX_VALUE : audioTrack.albumReleaseDate.getTimeStamp())) {
continue;
}
Map<?, ?> medium = (Map<?, ?>) ((List<?>) release.get("mediums")).get(0);
thisRelease.mediumIndex = new Integer(medium.get("position").toString());
thisRelease.mediumCount = new Integer(release.get("medium_count").toString());
Map<?, ?> track = (Map<?, ?>) ((List<?>) medium.get("tracks")).get(0);
thisRelease.trackIndex = new Integer(track.get("position").toString());
thisRelease.trackCount = new Integer(medium.get("track_count").toString());
try {
thisRelease.album = release.get("title").toString();
} catch (Exception e) {
thisRelease.album = (String) releaseGroup.get("title");
}
try {
thisRelease.albumArtist = (String) ((Map<?, ?>) ((List<?>) releaseGroup.get("artists")).get(0)).get("name");
} catch (Exception e) {
thisRelease.albumArtist = null;
}
thisRelease.trackTitle = (String) track.get("title");
if (!"Various Artists".equalsIgnoreCase(thisRelease.albumArtist) && (thisRelease.album == null || !thisRelease.album.contains("Greatest Hits"))) {
audioTrack = thisRelease;
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
// allow album to be null
}
cache.put(url, audioTrack);
return audioTrack;
} catch (Exception e) {
}
}
audioTrack = new AudioTrack(artist, title, album);
cache.put(url, audioTrack);
return audioTrack;
} catch (Exception e) {
// no results
return null;
}
return null;
}

View File

@ -7,9 +7,21 @@ import java.io.Serializable;
public class AudioTrack implements Serializable {
private String artist;
private String title;
private String album;
protected String artist;
protected String title;
protected String album;
protected String albumArtist;
protected String trackTitle;
protected Date albumReleaseDate;
protected Integer mediumIndex;
protected Integer mediumCount;
protected Integer trackIndex;
protected Integer trackCount;
protected AudioTrack() {
}
public AudioTrack(String artist, String title, String album) {
@ -19,6 +31,20 @@ public class AudioTrack implements Serializable {
}
public AudioTrack(String artist, String title, String album, String albumArtist, String trackTitle, Date albumReleaseDate, Integer mediumIndex, Integer mediumCount, Integer trackIndex, Integer trackCount) {
this.artist = artist;
this.title = title;
this.album = album;
this.albumArtist = albumArtist;
this.trackTitle = trackTitle;
this.albumReleaseDate = albumReleaseDate;
this.mediumIndex = mediumIndex;
this.mediumCount = mediumCount;
this.trackIndex = trackIndex;
this.trackCount = trackCount;
}
public String getArtist() {
return artist;
}
@ -34,6 +60,41 @@ public class AudioTrack implements Serializable {
}
public String getAlbumArtist() {
return albumArtist;
}
public String getTrackTitle() {
return trackTitle;
}
public Date getAlbumReleaseDate() {
return albumReleaseDate;
}
public Integer getMedium() {
return mediumIndex;
}
public Integer getMediumCount() {
return mediumCount;
}
public Integer getTrack() {
return trackIndex;
}
public Integer getTrackCount() {
return trackCount;
}
@Override
public String toString() {
return String.format("%s - %s", getArtist(), getTitle());