diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index 7805189d..cf203c64 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -604,7 +604,7 @@ public class MediaBindingBean { @Define("pn") public Integer getPartCount() { if (infoObject instanceof AudioTrack) - return getMusic().getTrackCount(); + return getMusic().getTrackCount() != null ? getMusic().getTrackCount() : Integer.parseInt(getMediaInfo(StreamKind.General, 0, "Track/Position_Total")); if (infoObject instanceof MoviePart) return ((MoviePart) infoObject).getPartCount(); diff --git a/source/net/sourceforge/filebot/web/ID3Lookup.java b/source/net/sourceforge/filebot/web/ID3Lookup.java index 473d49a4..75700024 100644 --- a/source/net/sourceforge/filebot/web/ID3Lookup.java +++ b/source/net/sourceforge/filebot/web/ID3Lookup.java @@ -4,6 +4,9 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.Icon; @@ -33,13 +36,42 @@ public class ID3Lookup implements MusicIdentificationService { throw new IOException("MediaInfo failed to open file: " + f); } - String artist = mediaInfo.get(StreamKind.General, 0, "Performer"); - String title = mediaInfo.get(StreamKind.General, 0, "Title"); - String album = mediaInfo.get(StreamKind.General, 0, "Album"); - mediaInfo.close(); + try { + String artist = mediaInfo.get(StreamKind.General, 0, "Performer"); + String title = mediaInfo.get(StreamKind.General, 0, "Title"); + String album = mediaInfo.get(StreamKind.General, 0, "Album"); - if (artist.length() > 0 && title.length() > 0 && album.length() > 0) { - info.put(f, new AudioTrack(artist, title, album)); + // extra info if available + String albumArtist = null, trackTitle = null; + Date albumReleaseDate = null; + Integer mediumIndex = null, mediumCount = null, trackIndex = null, trackCount = null; + + try { + int year = new Scanner(mediaInfo.get(StreamKind.General, 0, "Recorded_Date")).useDelimiter("\\D+").nextInt(); + albumReleaseDate = new Date(year, 1, 1); + } catch (Exception e) { + // ignore + } + + try { + trackIndex = Integer.parseInt(mediaInfo.get(StreamKind.General, 0, "Track/Position")); + } catch (Exception e) { + // ignore + } + + try { + trackCount = Integer.parseInt(mediaInfo.get(StreamKind.General, 0, "Track/Position_Total")); + } catch (Exception e) { + // ignore + } + + if (artist.length() > 0 && title.length() > 0 && album.length() > 0) { + info.put(f, new AudioTrack(artist, title, album, albumArtist, trackTitle, albumReleaseDate, mediumIndex, mediumCount, trackIndex, trackCount)); + } + } catch (Throwable e) { + Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.getMessage(), e); + } finally { + mediaInfo.close(); } }