My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.echonest.api.v4.examples;

import java.util.Collections;
import java.util.List;

import com.echonest.api.v4.Artist;
import com.echonest.api.v4.Audio;
import com.echonest.api.v4.Biography;
import com.echonest.api.v4.Blog;
import com.echonest.api.v4.EchoNestAPI;
import com.echonest.api.v4.EchoNestException;
import com.echonest.api.v4.Image;
import com.echonest.api.v4.News;
import com.echonest.api.v4.Params;
import com.echonest.api.v4.Review;
import com.echonest.api.v4.Video;

public class ArtistExamples {

private EchoNestAPI en;
private static boolean trace = false;

public ArtistExamples() throws EchoNestException {
en = new EchoNestAPI();
en.setTraceSends(trace);
en.setTraceRecvs(trace);
en.setMinCommandTime(0);
}

public void dumpArtist(Artist artist) throws EchoNestException {
System.out.printf("%s\n", artist.getName());
System.out.printf(" hottt %.3f\n", artist.getHotttnesss());
System.out.printf(" fam %.3f\n", artist.getFamiliarity());

System.out.println(" ========= urls ======== ");
for (String key : artist.getUrls().keySet()) {
System.out.printf(" %10s %s\n", key, artist.getUrls().get(key));
}

System.out.println(" ========= audio ======== ");
List<Audio> audioList = artist.getAudio();
for (int i = 0; i < audioList.size(); i++) {
System.out.printf(" == audio %d == \n", i + 1);
Audio audio = audioList.get(i);
audio.dump();
}

System.out.println(" ========= audio2 ======== ");
List<Audio> audioList2 = artist.getAudio(10, 40);
for (int i = 0; i < audioList2.size(); i++) {
System.out.printf(" == audio2 %d == \n", i + 1);
Audio audio = audioList2.get(i);
audio.dump();
}

System.out.println(" ========= bios ======== ");
List<Biography> bios = artist.getBiographies();
for (int i = 0; i < bios.size(); i++) {
Biography bio = bios.get(i);
bio.dump();
}

System.out.println(" ========= blogs ======== ");
List<Blog> blogs = artist.getBlogs();
for (int i = 0; i < blogs.size(); i++) {
Blog blog = blogs.get(i);
blog.dump();
}

System.out.println(" ========= images ======== ");
List<Image> images = artist.getImages();
for (int i = 0; i < images.size(); i++) {
Image image = images.get(i);
image.dump();
}

System.out.println(" ========= news ======== ");
List<News> newsList = artist.getNews();
for (int i = 0; i < newsList.size(); i++) {
News news = newsList.get(i);
news.dump();
}

System.out.println(" ========= reviews ======== ");
List<Review> reviews = artist.getReviews();
for (int i = 0; i < reviews.size(); i++) {
Review review = reviews.get(i);
review.dump();
}

System.out.println(" ========= videos ======== ");
List<Video> videos = artist.getVideos();
for (int i = 0; i < videos.size(); i++) {
Video video = videos.get(i);
video.dump
();
}
}

public void searchArtistByName(String name, int results)
throws EchoNestException {
Params p = new Params();
p.add("query", name);
p.add("rows", results);

List<Artist> artists = en.searchArtists(p);
for (Artist artist : artists) {
dumpArtist(artist);
System.out.println();
}
}

public void randomWalk(String seedName, int count) throws EchoNestException {
List<Artist> artists = en.searchArtists(seedName);
if (artists.size() > 0) {
Artist seed = artists.get(0);
for (int i = 0; i < count; i++) {
dumpArtist(seed);
List<Artist> sims = seed.getSimilar(10);
if (sims.size() > 0) {
Collections.shuffle(sims);
seed = sims.get(0);
} else {
break;
}
}
}
}

public void stats() {
en.showStats();
}

public static void main(String[] args) throws EchoNestException {
ArtistExamples sse = new ArtistExamples();
long start = System.currentTimeMillis();
try {
sse.searchArtistByName("weezer", 10);
System.out.println("Random walk");
sse.randomWalk("weezer", 10);
} finally {
System.out.println("Runtime " + (System.currentTimeMillis() - start));
sse.stats();
}
}
}

Change log

r61 by paul.lamere on Mar 21, 2011   Diff
Added suggest interface
Improved tests
Go to: 
Project members, sign in to write a code review

Older revisions

r21 by paul.lamere on Apr 23, 2010   Diff
testing scripts and docs
r6 by paul.lamere on Apr 21, 2010   Diff
More song and track tests
r4 by paul.lamere on Apr 21, 2010   Diff
initial revision
All revisions of this file

File info

Size: 4045 bytes, 146 lines
Powered by Google Project Hosting