public void testWriteFile() { Exception exceptionCaught = null; try { File testFile = AbstractTestCase.copyAudioToTmp("test1.wma", new File("testwrite1.wma")); AudioFile f = AudioFileIO.read(testFile); assertEquals("32", f.getAudioHeader().getBitRate()); assertEquals( "ASF (audio): 0x0161 (Windows Media Audio (ver 7,8,9))", f.getAudioHeader().getEncodingType()); assertEquals("2", f.getAudioHeader().getChannels()); assertEquals("32000", f.getAudioHeader().getSampleRate()); assertFalse(f.getAudioHeader().isVariableBitRate()); assertTrue(f.getTag() instanceof AsfTag); AsfTag tag = (AsfTag) f.getTag(); // Write some new values and save tag.setField(FieldKey.ARTIST, "artist2"); tag.setField(FieldKey.ALBUM, "album2"); tag.setField(FieldKey.TITLE, "tracktitle2"); tag.setField(FieldKey.COMMENT, "comments2"); tag.addField(FieldKey.YEAR, "1972"); tag.setField(FieldKey.GENRE, "genre2"); tag.setField(FieldKey.TRACK, "4"); tag.setCopyright("copyright"); tag.setRating("rating"); tag.setField(tag.createField(FieldKey.URL_LYRICS_SITE, "http://www.lyrics.fly.com")); tag.setField(tag.createField(FieldKey.URL_DISCOGS_ARTIST_SITE, "http://www.discogs1.com")); tag.setField(tag.createField(FieldKey.URL_DISCOGS_RELEASE_SITE, "http://www.discogs2.com")); tag.setField(tag.createField(FieldKey.URL_OFFICIAL_ARTIST_SITE, "http://www.discogs3.com")); tag.setField(tag.createField(FieldKey.URL_OFFICIAL_RELEASE_SITE, "http://www.discogs4.com")); tag.addField(tag.createField(FieldKey.URL_WIKIPEDIA_ARTIST_SITE, "http://www.discogs5.com")); tag.addField(tag.createField(FieldKey.URL_WIKIPEDIA_RELEASE_SITE, "http://www.discogs6.com")); tag.setField(tag.createField(FieldKey.DISC_TOTAL, "3")); tag.setField(tag.createField(FieldKey.TRACK_TOTAL, "11")); // setField the IsVbr value (can be modified for now) tag.setField(tag.createField(AsfFieldKey.ISVBR, Boolean.TRUE.toString())); f.commit(); f = AudioFileIO.read(testFile); tag = (AsfTag) f.getTag(); assertTrue(f.getAudioHeader().isVariableBitRate()); assertEquals("artist2", tag.getFirst(FieldKey.ARTIST)); assertEquals("album2", tag.getFirst(FieldKey.ALBUM)); assertEquals("tracktitle2", tag.getFirst(FieldKey.TITLE)); assertEquals("comments2", tag.getFirst(FieldKey.COMMENT)); assertEquals("1972", tag.getFirst(FieldKey.YEAR)); assertEquals("4", tag.getFirst(FieldKey.TRACK)); assertEquals("genre2", tag.getFirst(FieldKey.GENRE)); assertEquals("copyright", tag.getFirstCopyright()); assertEquals("rating", tag.getFirstRating()); assertEquals("http://www.lyrics.fly.com", tag.getFirst(FieldKey.URL_LYRICS_SITE)); assertEquals("http://www.discogs1.com", tag.getFirst(FieldKey.URL_DISCOGS_ARTIST_SITE)); assertEquals("http://www.discogs2.com", tag.getFirst(FieldKey.URL_DISCOGS_RELEASE_SITE)); assertEquals("http://www.discogs3.com", tag.getFirst(FieldKey.URL_OFFICIAL_ARTIST_SITE)); assertEquals("http://www.discogs4.com", tag.getFirst(FieldKey.URL_OFFICIAL_RELEASE_SITE)); assertEquals("http://www.discogs5.com", tag.getFirst(FieldKey.URL_WIKIPEDIA_ARTIST_SITE)); assertEquals("http://www.discogs6.com", tag.getFirst(FieldKey.URL_WIKIPEDIA_RELEASE_SITE)); assertEquals("3", tag.getFirst(FieldKey.DISC_TOTAL)); assertEquals("11", tag.getFirst(FieldKey.TRACK_TOTAL)); AudioFileIO.delete(f); f = AudioFileIO.read(testFile); tag = (AsfTag) f.getTag(); assertFalse(f.getAudioHeader().isVariableBitRate()); assertTrue(tag.isEmpty()); } catch (Exception e) { e.printStackTrace(); exceptionCaught = e; } assertNull(exceptionCaught); }
/** * File metadata was set with Media Monkey 3 * * <p>Checking our fields match the fields used by media Monkey 3 (Defacto Standard) by ensuring * we can read fields written in Media Monkey */ public void testReadFileFromMediaMonkey3() { Exception exceptionCaught = null; try { File testFile = AbstractTestCase.copyAudioToTmp("test1.wma"); AudioFile f = AudioFileIO.read(testFile); assertEquals("32", f.getAudioHeader().getBitRate()); assertEquals( "ASF (audio): 0x0161 (Windows Media Audio (ver 7,8,9))", f.getAudioHeader().getEncodingType()); assertEquals("2", f.getAudioHeader().getChannels()); assertEquals("32000", f.getAudioHeader().getSampleRate()); assertFalse(f.getAudioHeader().isVariableBitRate()); assertTrue(f.getTag() instanceof AsfTag); AsfTag tag = (AsfTag) f.getTag(); System.out.println(tag); // Ease of use methods for common fields assertEquals("artist", tag.getFirst(FieldKey.ARTIST)); assertEquals("album", tag.getFirst(FieldKey.ALBUM)); assertEquals("tracktitle", tag.getFirst(FieldKey.TITLE)); assertEquals("comments", tag.getFirst(FieldKey.COMMENT)); assertEquals("1971", tag.getFirst(FieldKey.YEAR)); assertEquals("3", tag.getFirst(FieldKey.TRACK)); assertEquals("genre", tag.getFirst(FieldKey.GENRE)); assertEquals("artist", tag.getFirst(FieldKey.ARTIST)); assertEquals("artist", tag.getFirst(AsfFieldKey.AUTHOR.getFieldName())); assertEquals("album", tag.getFirst(FieldKey.ALBUM)); assertEquals("album", tag.getFirst(AsfFieldKey.ALBUM.getFieldName())); assertEquals("tracktitle", tag.getFirst(FieldKey.TITLE)); assertEquals("tracktitle", tag.getFirst(AsfFieldKey.TITLE.getFieldName())); assertEquals("genre", tag.getFirst(FieldKey.GENRE)); assertEquals("genre", tag.getFirst(AsfFieldKey.GENRE.getFieldName())); assertEquals("3", tag.getFirst(FieldKey.TRACK)); assertEquals("1971", tag.getFirst(FieldKey.YEAR)); assertEquals("genre", tag.getFirst(FieldKey.GENRE)); assertEquals("comments", tag.getFirst(FieldKey.COMMENT)); assertEquals("albumartist", tag.getFirst(FieldKey.ALBUM_ARTIST)); assertEquals("composer", tag.getFirst(FieldKey.COMPOSER)); assertEquals("grouping", tag.getFirst(FieldKey.GROUPING)); assertEquals("2", tag.getFirst(FieldKey.DISC_NO)); assertEquals("lyrics for song", tag.getFirst(FieldKey.LYRICS)); assertEquals("encoder", tag.getFirst(FieldKey.ENCODER)); assertEquals("isrc", tag.getFirst(FieldKey.ISRC)); assertEquals("publisher", tag.getFirst(FieldKey.RECORD_LABEL)); assertEquals("Lyricist", tag.getFirst(FieldKey.LYRICIST)); assertEquals("conductor", tag.getFirst(FieldKey.CONDUCTOR)); assertEquals("Mellow", tag.getFirst(FieldKey.MOOD)); // Media Monkey does not currently support these fields ... // assertEquals("is_compilation", tag.getFirst(FieldKey.IS_COMPILATION)); // assertEquals("artist_sort", tag.getFirst(FieldKey.ARTIST_SORT)); // assertEquals("album_artist_sort", tag.getFirst(FieldKey.ALBUM_ARTIST_SORT)); // assertEquals("album_sort", tag.getFirst(FieldKey.ALBUM_SORT)); // assertEquals("title_sort", tag.getFirst(FieldKey.TITLE_SORT)); // assertEquals("barcode", tag.getFirst(FieldKey.BARCODE)); // assertEquals("catalogno", tag.getFirst(FieldKey.CATALOG_NO)); // assertEquals("media", tag.getFirst(FieldKey.MEDIA)); // assertEquals("remixer", tag.getFirst(FieldKey.REMIXER)); // Now } catch (Exception e) { e.printStackTrace(); exceptionCaught = e; } assertNull(exceptionCaught); }
/** * File metadata was set with PicardQt * * <p>Checking our fields match the fields used by picard Qt3 (Defacto Standard for Musicbrainz * fields) by ensuring we can read fields written in Picard Qt */ public void testReadFileFromPicardQt() { File orig = new File("testdata", "test2.wma"); if (!orig.isFile()) { System.err.println("Unable to test file - not available"); return; } Exception exceptionCaught = null; try { File testFile = AbstractTestCase.copyAudioToTmp("test2.wma"); AudioFile f = AudioFileIO.read(testFile); assertEquals("128", f.getAudioHeader().getBitRate()); assertEquals( "ASF (audio): 0x0162 (Windows Media Audio 9 series (Professional))", f.getAudioHeader().getEncodingType()); assertEquals("2", f.getAudioHeader().getChannels()); assertEquals("44100", f.getAudioHeader().getSampleRate()); assertFalse(f.getAudioHeader().isVariableBitRate()); assertTrue(f.getTag() instanceof AsfTag); AsfTag tag = (AsfTag) f.getTag(); System.out.println(tag); // Ease of use methods for common fields assertEquals("Sonic Youth", tag.getFirst(FieldKey.ARTIST)); assertEquals("Sister", tag.getFirst(FieldKey.ALBUM)); assertEquals("(I Got a) Catholic Block", tag.getFirst(FieldKey.TITLE)); assertEquals("1987", tag.getFirst(FieldKey.YEAR)); assertEquals("2", tag.getFirst(FieldKey.TRACK)); // NOTE:track can have seroes or not assertEquals("no wave", tag.getFirst(FieldKey.GENRE)); assertEquals("Sonic Youth", tag.getFirst(FieldKey.ARTIST)); assertEquals("Sonic Youth", tag.getFirst(AsfFieldKey.AUTHOR.getFieldName())); assertEquals("Sister", tag.getFirst(FieldKey.ALBUM)); assertEquals("Sister", tag.getFirst(AsfFieldKey.ALBUM.getFieldName())); assertEquals("(I Got a) Catholic Block", tag.getFirst(FieldKey.TITLE)); assertEquals("(I Got a) Catholic Block", tag.getFirst(AsfFieldKey.TITLE.getFieldName())); assertEquals("no wave", tag.getFirst(FieldKey.GENRE)); assertEquals("no wave", tag.getFirst(AsfFieldKey.GENRE.getFieldName())); assertEquals("2", tag.getFirst(FieldKey.TRACK)); assertEquals("2", tag.getFirst(AsfFieldKey.TRACK.getFieldName())); assertEquals("1987", tag.getFirst(FieldKey.YEAR)); assertEquals("1987", tag.getFirst(AsfFieldKey.YEAR.getFieldName())); assertEquals("Sonic Youth", tag.getFirst(FieldKey.ALBUM_ARTIST)); assertEquals("Sonic Youth", tag.getFirst(AsfFieldKey.ALBUM_ARTIST.getFieldName())); assertEquals("Blast First", tag.getFirst(FieldKey.RECORD_LABEL)); assertEquals("Blast First", tag.getFirst(AsfFieldKey.RECORD_LABEL.getFieldName())); assertEquals("Sonic Youth", tag.getFirst(FieldKey.ARTIST_SORT)); assertEquals("Sonic Youth", tag.getFirst(AsfFieldKey.ARTIST_SORT.getFieldName())); assertEquals("Sonic Youth", tag.getFirst(FieldKey.ARTIST_SORT)); assertEquals("Sonic Youth", tag.getFirst(AsfFieldKey.ARTIST_SORT.getFieldName())); assertEquals("Sonic Youth", tag.getFirst(FieldKey.ALBUM_ARTIST_SORT)); assertEquals("Sonic Youth", tag.getFirst(AsfFieldKey.ALBUM_ARTIST_SORT.getFieldName())); assertEquals("official", tag.getFirst(FieldKey.MUSICBRAINZ_RELEASE_STATUS)); assertEquals("official", tag.getFirst(AsfFieldKey.MUSICBRAINZ_RELEASE_STATUS.getFieldName())); assertEquals("album", tag.getFirst(FieldKey.MUSICBRAINZ_RELEASE_TYPE)); assertEquals("album", tag.getFirst(AsfFieldKey.MUSICBRAINZ_RELEASE_TYPE.getFieldName())); assertEquals("GB", tag.getFirst(FieldKey.MUSICBRAINZ_RELEASE_COUNTRY)); assertEquals("GB", tag.getFirst(AsfFieldKey.MUSICBRAINZ_RELEASE_COUNTRY.getFieldName())); assertEquals( "5cbef01b-cc35-4f52-af7b-d0df0c4f61b9", tag.getFirst(FieldKey.MUSICBRAINZ_RELEASEARTISTID)); assertEquals( "5cbef01b-cc35-4f52-af7b-d0df0c4f61b9", tag.getFirst(AsfFieldKey.MUSICBRAINZ_RELEASEARTISTID.getFieldName())); assertEquals( "f8ece8ad-0ef1-45c0-9d20-a58a10052d5c", tag.getFirst(FieldKey.MUSICBRAINZ_TRACK_ID)); assertEquals( "f8ece8ad-0ef1-45c0-9d20-a58a10052d5c", tag.getFirst(AsfFieldKey.MUSICBRAINZ_TRACK_ID.getFieldName())); assertEquals( "ca16e36d-fa43-4b49-8c71-d98bd70b341f", tag.getFirst(FieldKey.MUSICBRAINZ_RELEASEID)); assertEquals( "ca16e36d-fa43-4b49-8c71-d98bd70b341f", tag.getFirst(AsfFieldKey.MUSICBRAINZ_RELEASEID.getFieldName())); assertEquals( "5cbef01b-cc35-4f52-af7b-d0df0c4f61b9", tag.getFirst(FieldKey.MUSICBRAINZ_ARTISTID)); assertEquals( "5cbef01b-cc35-4f52-af7b-d0df0c4f61b9", tag.getFirst(AsfFieldKey.MUSICBRAINZ_ARTISTID.getFieldName())); // This example doesnt populate these fields // assertEquals("Sonic Youth", tag.getFirst(FieldKey.COMPOSER)); // assertEquals("grouping", tag.getFirst(FieldKey.GROUPING)); // assertEquals("2", tag.getFirst(FieldKey.DISC_NO)); // assertEquals("lyrics for song", tag.getFirst(FieldKey.LYRICS)); // assertEquals("encoder", tag.getFirst(FieldKey.ENCODER)); // assertEquals("isrc", tag.getFirst(FieldKey.ISRC)); // assertEquals("Lyricist", tag.getFirst(FieldKey.LYRICIST)); // assertEquals("conductor", tag.getFirst(FieldKey.CONDUCTOR)); // assertEquals("Mellow", tag.getFirst(FieldKey.INVOLVED_PEOPLE)); // assertEquals("5cbef01b-cc35-4f52-af7b-d0df0c4f61b9", tag.getFirst(FieldKey.MUSICIP_ID)); // Picard Qt does not currently support these fields ... // assertEquals("is_compilation", tag.getFirst(FieldKey.IS_COMPILATION)); // assertEquals("album_sort", tag.getFirst(FieldKey.ALBUM_SORT)); // assertEquals("title_sort", tag.getFirst(FieldKey.TITLE_SORT)); // assertEquals("barcode", tag.getFirst(FieldKey.BARCODE)); // assertEquals("catalogno", tag.getFirst(FieldKey.CATALOG_NO)); // assertEquals("media", tag.getFirst(FieldKey.MEDIA)); // assertEquals("remixer", tag.getFirst(FieldKey.REMIXER)); // Now } catch (Exception e) { e.printStackTrace(); exceptionCaught = e; } assertNull(exceptionCaught); }