public static Library parse(InputStream in, long fileLength) throws IOException, ItlException { Input di = new InputImpl(in); Hdfm hdr = Hdfm.read(di, fileLength); ParseLibrary pl = new ParseLibrary(); String path = pl.drain(inputFor(hdr.fileData), hdr.fileData.length); // for (InputRange ir : pl.diagnostics) { // System.out.println(ir); // } Library library = new Library(hdr, path, pl.playlists, pl.podcasts, pl.tracks, pl.resourcesWithArtwork); return library; }
private void readHptm(Input di, int length) throws IOException, ItlException { byte[] unknown = new byte[16]; di.readFully(unknown); int key = di.readInt(); // System.out.println(" Key: " + key); if (currentPlaylist == null) { throw new ItlException("Playlist item outside playlist content"); } currentPlaylist.addItem(key); di.skipBytes(length - 28); }
static String readGenericHohm(Input di) throws IOException, ItlException { byte[] unknown = new byte[12]; di.readFully(unknown); int dataLength = di.readInt(); expectZeroBytes(di, 8, " in HOHM block"); byte[] data = new byte[dataLength]; di.readFully(data); return toString(data, unknown[11]); }
public static void main(String[] args) throws IOException, ItlException { if (args.length != 1) { System.err.println("Usage: ExportRatings <library.itl>"); System.exit(5); } Library lib = ParseLibrary.parse(new File(args[0])); for (Track t : lib.getTracks()) { if(t.getLocation() != null) { System.out.println(t.getLocation() + "," + t.getRating()); } } } }
private void readHpim(Input di, int length) throws IOException, ItlException { int unknownA = di.readInt(); int unknownB = di.readInt(); int itemCount = di.readInt(); // System.out.println("HPIM items: " + itemCount); // System.out.printf("0x%04x%04x", unknownA, unknownB); // System.out.println(""); byte[] remaining = new byte[length - 20]; di.readFully(remaining); byte[] ppid = new byte[8]; System.arraycopy(remaining, 420, ppid, 0, ppid.length); currentPlaylistItems = new PlaylistRawItems(itemCount); }
public File getCache(Library l, Artwork art) { byte[] artId = art.getPersistentId(); return get(l, ArtworkFile.Directory.Cache, artId); }
public File getDownload(Library l, Track t) { byte[] artId = t.getAlbumPersistentId(); get(l, ArtworkFile.Directory.Cache, artId); return get(l, ArtworkFile.Directory.Download, artId); }
static void expectZeroBytes(Input di, int count, String where) throws IOException, ItlException { byte[] ba = new byte[count]; di.readFully(ba); for (int i = 0; i < ba.length; i++) { byte b = ba[i]; if (b != 0x00) { throw new ItlException("Expected " + count + " zero bytes" + where + ". Was: 0x" + Integer.toHexString(b) + " at offset " + i); } } }
static Input inputFor(byte[] fileData) { InputStream in = new ByteArrayInputStream(fileData); if (fileData.length >= 4 && Arrays.equals(flippedHdsm, Arrays.copyOfRange(fileData, 0, 4))) { return new FlippedInputImpl(in); } else { return new InputImpl(in); } }
public Collection<Artwork> getArtwork() { return copy(artwork); } }
static void hexDumpBytes(Input di, int count) throws IOException { for (int i = 0; i < count; i++) { int v = di.readUnsignedByte(); // System.out.printf("%3d 0x%02x %4s\n", i, v, (v == 0 ? ' ' : (char) v)); } }
static void expectZeroBytes(Input di, int count) throws IOException, ItlException { expectZeroBytes(di, count, ""); }
public void write(DataOutput o) throws IllegalArgumentException, IOException, ItlException { write(o, fileData); }
static byte[] readPersistentId(Input di) throws IOException { byte[] id = new byte[8]; di.readFully(id); if (!Arrays.equals(id, BLANK_ID)) { return id; } else { return null; } } }
public InputImpl(InputStream in) { this.in = new CountingInputStream(in); this.di = new DataInputStream(this.in); }
@Override public int readInt() throws IOException { return Integer.reverseBytes(super.readInt()); } }
public Collection<Podcast> getPodcasts() { return copy(podcasts); }
public Collection<Playlist> getPlaylists() { return copy(playlists); }
public Collection<Track> getTracks() { return copy(tracks); }