com.mpatric.mp3agic.ID3v2 Java Examples

The following examples show how to use com.mpatric.mp3agic.ID3v2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dashController.java    From gramophy with GNU General Public License v3.0 4 votes vote down vote up
private void loadLibrary()
{
    io.log("Loading music library ...");

    File[] songsFiles = io.getFilesInFolder(config.get("music_lib_path"));

    ArrayList<HashMap<String,Object>> thisPlaylist = new ArrayList<>();

    for(File eachSong : songsFiles)
    {
        if(!eachSong.getName().endsWith(".mp3")) continue;

        try
        {
            Mp3File mp3File = new Mp3File(eachSong);

            ID3v1 id3v1 = mp3File.getId3v1Tag();
            HashMap<String, Object> songDetails = new HashMap<>();
            songDetails.put("location","local");
            songDetails.put("source",eachSong.toURI().toString().replace("file:",""));

            if(id3v1 == null)
            {
                ID3v2 id3v2 = mp3File.getId3v2Tag();

                if(id3v2.getTitle() == null)
                {
                    songDetails.put("title", eachSong.getName());
                }
                else
                {
                    songDetails.put("title", id3v2.getTitle());
                }

                if(id3v2.getArtist() == null)
                {
                    songDetails.put("artist", "Unknown");
                }
                else
                {
                    songDetails.put("artist", id3v2.getArtist());
                }

                if(id3v2.getAlbumImage() != null)
                {
                    songDetails.put("album_art", id3v2.getAlbumImage());
                }
            }
            else
            {
                if(id3v1.getTitle() == null)
                {
                    songDetails.put("title", eachSong.getName());
                }
                else
                {
                    songDetails.put("title", id3v1.getTitle());
                }

                if(id3v1.getArtist() == null)
                {
                    songDetails.put("artist", "Unknown");
                }
                else
                {
                    songDetails.put("artist", id3v1.getArtist());
                }
            }
            thisPlaylist.add(songDetails);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    cachedPlaylist.put("My Music",thisPlaylist);

}
 
Example #2
Source File: dashController.java    From gramophy with GNU General Public License v3.0 4 votes vote down vote up
private void loadRecents() throws Exception
{
    String[] recentsArr = io.readFileArranged("playlists/Recents","::");

    ArrayList<HashMap<String,Object>> newSongs = new ArrayList<>();

    for(String eachChunk : recentsArr)
    {
        if(eachChunk.equals("empty")) break;
        String[] eachSongArr = eachChunk.split("<>");

        HashMap<String,Object> eachSongDetails = new HashMap<>();

        eachSongDetails.put("location",eachSongArr[0]);
        eachSongDetails.put("source",eachSongArr[1]);

        if(eachSongArr[0].equals("local"))
        {
            File f = new File(URLDecoder.decode(eachSongArr[1],StandardCharsets.UTF_8));
            if(f.exists())
            {
                Mp3File mp3File = new Mp3File(f.getPath());

                ID3v1 id3v1 = mp3File.getId3v1Tag();

                if(id3v1 == null)
                {
                    ID3v2 id3v2 = mp3File.getId3v2Tag();
                    eachSongDetails.put("title", id3v2.getTitle());
                    eachSongDetails.put("artist", id3v2.getArtist());
                    eachSongDetails.put("album_art", id3v2.getAlbumImage());
                }
                else
                {
                    eachSongDetails.put("title", id3v1.getTitle());
                    eachSongDetails.put("artist", id3v1.getArtist());
                }
            }
            else
            {
                System.out.println("doesn't exist, skipping ...");
                continue;
            }
        }
        else
        {
            eachSongDetails.put("videoID",eachSongArr[1]);
            eachSongDetails.put("thumbnail",eachSongArr[2]);
            eachSongDetails.put("title",eachSongArr[3]);
            eachSongDetails.put("channelTitle",eachSongArr[4]);
        }

        newSongs.add(eachSongDetails);
    }

    cachedPlaylist.put("Recents",newSongs);
}
 
Example #3
Source File: dashController.java    From gramophy with GNU General Public License v3.0 4 votes vote down vote up
private void loadOtherPlaylists() throws Exception
{
    File[] playlistFiles = io.getFilesInFolder("playlists/");
    for(File eachPlaylistFile : playlistFiles)
    {
        if(eachPlaylistFile.getName().equals("Recents")) continue;

        String contentRaw = io.readFileRaw("playlists/"+eachPlaylistFile.getName());
        String[] contentArr = contentRaw.split("::");

        String playlistName = eachPlaylistFile.getName();
        ArrayList<HashMap<String,Object>> songs = new ArrayList<>();

        if(!contentRaw.equals("empty"))
        {
            for(int i =0;i<contentArr.length;i++)
            {
                String[] eachSongContentArr = contentArr[i].split("<>");
                HashMap<String,Object> sd = new HashMap<>();
                sd.put("location",eachSongContentArr[0]);
                sd.put("source",eachSongContentArr[1]);

                if(eachSongContentArr[0].equals("local"))
                {
                    File f = new File(URLDecoder.decode(eachSongContentArr[1],StandardCharsets.UTF_8));
                    if(f.exists())
                    {
                        Mp3File mp3File = new Mp3File(URLDecoder.decode(eachSongContentArr[1],StandardCharsets.UTF_8));

                        ID3v1 id3v1 = mp3File.getId3v1Tag();

                        if(id3v1 == null)
                        {
                            ID3v2 id3v2 = mp3File.getId3v2Tag();
                            sd.put("title", id3v2.getTitle());
                            sd.put("artist", id3v2.getArtist());
                            sd.put("album_art", id3v2.getAlbumImage());
                        }
                        else
                        {
                            sd.put("title", id3v1.getTitle());
                            sd.put("artist", id3v1.getArtist());
                        }
                    }
                    else
                    {
                        System.out.println("skipping "+eachSongContentArr[1]+" cuz not found ...");
                    }

                }
                else if(eachSongContentArr[0].equals("youtube"))
                {
                    sd.put("videoID",eachSongContentArr[1]);
                    sd.put("thumbnail",eachSongContentArr[2]);
                    sd.put("title",eachSongContentArr[3]);
                    sd.put("channelTitle",eachSongContentArr[4]);

                }

                songs.add(sd);
            }
        }


        cachedPlaylist.put(playlistName,songs);
    }
}