/** * Fetches all the tags from the local music file: - Artist - Album - Title - Genre * * @return Song filled with tags * @throws InvalidAudioFrameException * @throws ReadOnlyFileException * @throws CannotReadException * @throws TagException * @throws IOException */ public Song getSongTags() throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException { // create song Song song = new Song(); // instantiate audio file AudioFile audio = AudioFileIO.read(this.songFile); Tag tag = audio.getTag(); song.setArtist(tag.getFirst(FieldKey.ARTIST)); song.setAlbum(tag.getFirst(FieldKey.ALBUM)); song.setTitle(tag.getFirst(FieldKey.TITLE)); song.setGenre(tag.getFirst(FieldKey.GENRE)); return song; }
/** * Stores the local music library into the DTH. The key of the song will be the key in the DHT. * The value is this peers address. */ private void storeLocalMusicInDHT() { // fetch local song list HashSet<Song> songList = (HashSet<Song>) this.musicStorageWatcher.getMusicLibrary(); if (songList == null) { return; } for (Song song : songList) { // store song reference boolean success = this.overlay.addToTracker(song.getKey().toString()); if (!success) { logger.error("songhandler: couldn't add song to tracker: " + song.getKey()); } else { logger.info("songhandler: added song to tracker: " + song.getKey()); } // store song tags if (song != null) { try { this.overlay.lookupAndSendMessage( song.getArtist(), new VotingMessage( song.getArtist(), new SongTag[] {new SongTag(song.getGenre())}, song, SongTagger.UPVOTE)); this.overlay.lookupAndSendMessage( song.getGenre(), new VotingMessage( song.getGenre(), new SongTag[] {new SongTag(song.getArtist())}, song, SongTagger.UPVOTE)); } catch (Exception e) { // nothing to do here } } } }