Package ch.rolandschaer.ascrblr.radio

Examples of ch.rolandschaer.ascrblr.radio.MetaData$Track


        if (!file.exists()) {
            System.err.println("Can't find " + path);
        } else {

            try {
                Track track = en.uploadTrack(file);
                track.waitForAnalysis(30000);
                if (track.getStatus() == Track.AnalysisStatus.COMPLETE) {
                    System.out.println("Tempo: " + track.getTempo());
                    System.out.println("Danceability: " + track.getDanceability());
                    System.out.println("Speechiness: " + track.getSpeechiness());
                    System.out.println("Liveness: " + track.getLiveness());
                    System.out.println("Energy: " + track.getEnergy());
                    System.out.println("Loudness: " + track.getLoudness());
                    System.out.println();
                    System.out.println("Beat start times:");
                   
                    TrackAnalysis analysis = track.getAnalysis();
                    for (TimedEvent beat : analysis.getBeats()) {
                        System.out.println("beat " + beat.getStart());
                    }
                } else {
                    System.err.println("Trouble analysing track " + track.getStatus());
                }
            } catch (IOException e) {
                System.err.println("Trouble uploading file");
            }
View Full Code Here


        List<Song> songs = en.searchSongs(p);
        for (Song song : songs) {
            System.out.printf("%s\n", song.getTitle());
            System.out.printf("   artist: %s\n", song.getArtistName());
            Track rdioTrack = song.getTrack("rdio-US");
            if (rdioTrack != null) {
                System.out.printf("Rdio FID %s\n", rdioTrack.getForeignID());
            }

            Track spotifyTrack = song.getTrack("spotify-WW");
            if (spotifyTrack != null) {
                System.out.printf("Spotify FID %s\n", spotifyTrack.getForeignID());
            }

            System.out.println();
        }
    }
View Full Code Here

        params.setLimit(true);
       
        Playlist playlist = en.createStaticPlaylist(params);

        for (Song song : playlist.getSongs()) {
            Track track = song.getTrack("spotify-WW");
            System.out.println(track.getForeignID() + " " + song.getTitle() + " by " + song.getArtistName());
        }
    }
View Full Code Here

                if (args.length == 1 && currentTrack != null) {
                    dumpTrack(currentTrack, false);
                } else {
                    for (int i = 1; i < args.length; i++) {
                        String id = args[i];
                        Track track = null;
                        if (id.startsWith("TR")) {
                            track = en.newTrackByID(id);
                        } else {
                            track = en.newTrackByMD5(id);
                        }
                        dumpTrack(track, false);
                    }
                }
                return "";
            }

            public String getHelp() {
                return "dumps tracks by ID or MD5";
            }
        });

        shell.add("trackDetails", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                if (args.length == 1 && currentTrack != null) {
                    dumpTrack(currentTrack, true);
                } else {
                    for (int i = 1; i < args.length; i++) {
                        String id = args[i];
                        Track track = null;
                        if (id.startsWith("TR")) {
                            track = en.newTrackByID(id);
                        } else {
                            track = en.newTrackByMD5(id);
                        }
                        dumpTrack(track, true);
                    }
                }
                return "";
            }

            public String getHelp() {
                return "dumps tracks by ID or MD5";
            }
        });

        shell.add("psearch_artists", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Params p = new Params();
                populateParams(p, args);
                List<Artist> artists = en.searchArtists(p);
                for (Artist artist : artists) {
                    System.out.println(artist.toString());
                }
                return "";
            }

            public String getHelp() {
                return "searches for artists (using params) ";
            }
        });

        shell.add("qbd", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                ArtistParams p = new ArtistParams();
                p.setResults(displayCount);
                p.sortBy(ArtistParams.SORT_HOTTTNESSS, false);
                // p.sortBy(ArtistParams.SORT_FAMILIARITY, false);

                String description = Shell.mash(args, 1);
                p.addDescription(description);
                List<Artist> artists = en.searchArtists(p);
                for (Artist artist : artists) {
                    System.out.println(artist.getName());
                }
                return "";
            }

            public String getHelp() {

                return "query by description";
            }
        });
        shell.add("psimilar_songs", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Params p = new Params();
                populateParams(p, args);

                List<Song> songs = en.similarSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                }
                return "";
            }

            public String getHelp() {
                return "finds similar songs to the seed song ";
            }
        });

        shell.add("most_danceable", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtistID(getArtist(Shell.mash(args, 1)).getID());
                p.sortBy(SongParams.SORT_DANCEABILITY, false);
                p.includeAudioSummary();

                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.printf("%.2f %s\n", song.getDanceability(), song
                            .getTitle());
                }
                return "";
            }

            public String getHelp() {
                return "finds most danceable songs by an artist ";
            }
        });

        shell.add("least_danceable", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtistID(getArtist(Shell.mash(args, 1)).getID());
                p.sortBy(SongParams.SORT_DANCEABILITY, true);
                p.includeAudioSummary();

                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.printf("%.2f %s\n", song.getDanceability(), song
                            .getTitle());
                }
                return "";
            }

            public String getHelp() {
                return "finds least danceable songs by an artist ";
            }
        });

        shell.add("most_energy", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtistID(getArtist(Shell.mash(args, 1)).getID());
                p.sortBy(SongParams.SORT_ENERGY, false);
                p.includeAudioSummary();

                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.printf("%.2f %s\n", song.getEnergy(), song
                            .getTitle());
                }
                return "";
            }

            public String getHelp() {
                return "finds most energetic songs by an artist ";
            }
        });

        shell.add("least_energy", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtistID(getArtist(Shell.mash(args, 1)).getID());
                p.sortBy(SongParams.SORT_ENERGY, true);
                p.includeAudioSummary();

                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.printf("%.2f %s\n", song.getEnergy(), song
                            .getTitle());
                }
                return "";
            }

            public String getHelp() {
                return "finds least danceable songs by an artist ";
            }
        });

        shell.add("psimilar_artists", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Params p = new Params();

                for (int i = 1; i < args.length; i++) {
                    String arg = args[i];
                    String[] pv = arg.split("=");
                    if (pv.length == 2) {
                        p.add(pv[0], pv[1]);
                    } else {
                        System.out.println("Don't understand " + arg);
                    }
                }
                List<Artist> artists = en.getSimilarArtists(p);
                for (Artist artist : artists) {
                    System.out.println(artist.toString());
                }
                return "";
            }

            public String getHelp() {
                return "searches for artists (using params) ";
            }
        });

        shell.add("get_songs", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Params p = new Params();

                for (int i = 1; i < args.length; i++) {
                    String arg = args[i];
                    String[] pv = arg.split("=");
                    if (pv.length == 2) {
                        p.add(pv[0], pv[1]);
                    } else {
                        System.out.println("Don't understand " + arg);
                    }
                }
                List<Song> songs = en.getSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                }
                return "";
            }

            public String getHelp() {
                return "gets info for a song ";
            }
        });
       
        shell.add("get_song", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setID(args[1]);
                List<Song> songs = en.getSongs(p);
                if (songs.size() >= 1) {
                    Song song = songs.get(0);
                    System.out.println(song.toString());

                }
                return "";
            }

            public String getHelp() {
                return "gets info for a song ";
            }
        });

        shell.add("hot_songs", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                boolean old_way = true;
                SongParams p = new SongParams();
                p.sortBy(SongParams.SORT_SONG_HOTTTNESSS, false);

                String description = Shell.mash(args, 1);

                if (old_way) {
                    p.addDescription(description);
                } else {
                    if (description.length() > 0) {
                        String[] fields = description.split(",");
                        for (String f : fields) {
                            p.addDescription(f.trim());
                        }
                    }
                }
                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                }
                return "";
            }

            public String getHelp() {
                return "show hot songs";
            }
        });

        shell.add("display_count", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                if (args.length == 2) {
                    displayCount = Integer.parseInt(args[1]);
                } else {
                    System.out.println("Display count: " + displayCount);
                }
                return "";
            }

            public String getHelp() {
                return "sets/gets the number of items to display";
            }
        });

        shell.add("get_similar", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Similarity for " + artist.getName());
                    List<Artist> artists = artist.getSimilar(displayCount);
                    for (Artist sartist : artists) {
                        System.out.printf("  %s\n", sartist.getName());
                    }

                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "finds similar artists";
            }
        });

        shell.add("get_blogs", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("blogs", artist.getBlogs());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets blogs for an artist";
            }
        });

        shell.add("get_images", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("images", artist.getImages());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets images for an artist";
            }
        });

        shell.add("get_audio", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("audio", artist.getAudio());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets audio for an artist";
            }
        });

        shell.add("get_bio", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("audio", artist.getBiographies());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets bios for an artist";
            }
        });

        shell.add("get_album_art", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtist(args[1]);
                p.setTitle(args[2]);
                p.includeTracks();
                p.setLimit(true);
                p.addIDSpace("7digital-US");
                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                    String url = song.getString("tracks[0].release_image");
                    System.out.println("release image" + url);
                }
                return "";
            }

            public String getHelp() {
                return "shows cover art for a song";
            }
        });


        shell.add("get_song_foreign_ids", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtist(args[1]);
                p.setTitle(args[2]);
                p.includeTracks();
                p.setLimit(true);
                p.addIDSpace("rdio-us-streaming");
                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                    String fid = song.getString("foreign_ids[0].foreign_id");
                    System.out.println("fid is " + fid);
                }
                return "";
            }

            public String getHelp() {
                return "demonstrate how to extract song foreign ids from a song";
            }
        });

        shell.add("get_urls", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("URLS for " + artist.getName());
                    Map<String, String> urlMap = artist.getUrls();
                    List<String> keys = new ArrayList<String>(urlMap.keySet());
                    Collections.sort(keys);
                    for (String key : keys) {
                        System.out.printf("%20s : %s\n", key, urlMap.get(key));
                    }
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets urls for an artist";
            }
        });

        shell.add("get_video", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("video", artist.getVideos());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets videos for an artist";
            }
        });

        shell.add("get_news", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("news", artist.getNews());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets news for an artist";
            }
        });

        shell.add("get_reviews", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("reviews", artist.getReviews());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets reviews for an artist";
            }
        });

        shell.add("get_artist_location", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    ArtistLocation location = artist.getArtistLocation();
                    System.out.println("Location is " + location.getLocation());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets location for an artist";
            }
        });

        shell.add("get_terms", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Terms for " + artist.getName());
                    List<Term> terms = artist.getTerms();
                    for (Term term : terms) {
                        System.out.printf("%.2f %s\n", term.getWeight(), term
                                .getName());
                    }
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets terms for an artist";
            }
        });

        shell.add("get_fam", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Familiarity for " + artist.getName()
                            + " " + artist.getFamiliarity());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets familiarity for an artist";
            }
        });

        shell.add("get_hot", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Hotttnesss for " + artist.getName()
                            + " " + artist.getHotttnesss());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets hotttnesss for an artist";
            }
        });

        shell.add("trackUpload", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                String arg = null;
                if (args.length >= 2) {
                    arg = Shell.mash(args, 1);
                } else {
                    arg = Utilities.createNewAudioFile("au").getAbsolutePath();
                }
                try {
                    Track track;
                    if (arg.startsWith("http:")) {
                        track = en.uploadTrack(new URL(arg), true);
                    } else {
                        System.out.println("md5 is " + Utilities.md5(arg));
                        track = en.uploadTrack(new File(arg));
                    }
                    track.waitForAnalysis(30000);
                    System.out.println("ID: " + track.getID() + " status "
                            + track.getStatus());

                    currentTrack = track;
                    System.out.println("Tempo is "
                            + track.getAnalysis().getTempo());
                } catch (IOException e) {
                    System.out.println("Trouble uploading");
                }
                return "";
            }

            public String getHelp() {
                return "uploads a track";
            }
        });

        shell.add("trackBeats", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                TrackAnalysis a = currentTrack.getAnalysis();
                List<TimedEvent> beats = a.getBeats();
                for (TimedEvent beat : beats) {
                    System.out.printf("%.6f, %.6f\n", beat.getStart(), beat
                            .getDuration());
                }
                return "";
            }

            public String getHelp() {
                return "uploads a track";
            }
        });

        shell.add("trackReanalyze", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                if (args.length == 2) {
                    Track track = en.newTrackByID(args[1]);
                    Track.AnalysisStatus status = track.reanalyze(true);
                    System.out.println("Analysis status " + status);
                } else {
                    System.out.println("trackReanalyze TRID");
                }
                return "";
View Full Code Here

TOP

Related Classes of ch.rolandschaer.ascrblr.radio.MetaData$Track

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.