Skip to content

Commit d5f4fbb

Browse files
Updaed ArtistInfo to use the LastFM GetArtistInfo method rather than the
now redundant EchoNest API which was retired by Spotify with no equivalent Spotify replacement API method.
1 parent e2768cd commit d5f4fbb

File tree

14 files changed

+162
-12
lines changed

14 files changed

+162
-12
lines changed

com.upnp.mediaplayer/Notes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,5 +280,8 @@ Build script not able to log onto Raspi SSH
280280
KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
281281
sudo /etc/init.d/ssh restart
282282
http://stackoverflow.com/questions/26424621/algorithm-negotiation-fail-ssh-in-jenkins
283+
http://stackoverflow.com/questions/21524609/ant-sshexec-failing-with-algorithm-negotitation-fail-error
284+
285+
283286

284287

com.upnp.mediaplayer/PlayList.xml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
2.75 KB
Binary file not shown.
2.74 KB
Binary file not shown.

com.upnp.mediaplayer/plugins/Fullscreen/Fullscreen.jar renamed to com.upnp.mediaplayer/plugins/Fullscreen/Fullscreen.jar.DISABLE

File renamed without changes.

com.upnp.mediaplayer/src/org/rpi/config/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public String toString() {
4343

4444
public class Config {
4545

46-
private String version = "0.0.9.0";
46+
private String version = "0.0.9.1";
4747

4848
private Logger log = Logger.getLogger(this.getClass());
4949

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package org.rpi.web.longpolling;
2+
3+
import java.io.BufferedReader;
4+
import java.io.DataOutputStream;
5+
import java.io.InputStreamReader;
6+
import java.io.StringReader;
7+
import java.net.URL;
8+
import java.net.URLEncoder;
9+
10+
import org.apache.log4j.Logger;
11+
12+
import java.net.HttpURLConnection;
13+
14+
import javax.json.Json;
15+
import javax.json.JsonArray;
16+
import javax.json.JsonObject;
17+
import javax.json.JsonReader;
18+
19+
public class LastFMUtils {
20+
21+
private String lastfrm_api_key = "003dc9a812e87f5058f53439dd26038e";
22+
private Logger log = Logger.getLogger(LastFMUtils.class);
23+
24+
public ArtistInfo searchArtistByName(String artist) {
25+
ArtistInfo info = new ArtistInfo();
26+
27+
try {
28+
// artist = java.net.URLEncoder.encode(artist, "UTF-8");
29+
String USER_AGENT = "Mozilla/5.0";
30+
String url = "http://ws.audioscrobbler.com/2.0/?";
31+
// String parameters =
32+
// "method=artist.getinfo&artist=%1$s&api_key=%2$s&format=json";
33+
String parameters = "method=artist.getinfo&artist=%1$s&api_key=%2$s&format=json";
34+
// String parameters =
35+
// "apikey=8e8ff105f5380c9f4d75e4d1518cf50750167cf5&application=SmartHome&event=%1$s&description=%2$s&priority=%3$s";
36+
parameters = String.format(parameters, URLEncoder.encode(artist, "UTF-8"), lastfrm_api_key);
37+
38+
URL obj = new URL(url + parameters);
39+
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
40+
41+
// add reuqest header
42+
con.setRequestMethod("POST");
43+
con.setRequestProperty("User-Agent", USER_AGENT);
44+
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
45+
46+
// String urlParameters =
47+
// "sn=C02G8416DRJM&cn=&locale=&caller=&num=12345";
48+
49+
// Send post request
50+
con.setDoOutput(true);
51+
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
52+
// wr.writeBytes(urlParameters);
53+
wr.flush();
54+
wr.close();
55+
56+
int responseCode = con.getResponseCode();
57+
log.debug("Sending 'POST' request to URL : " + url);
58+
// log.debug("Post parameters : " + urlParameters);
59+
log.debug("Response Code : " + responseCode);
60+
61+
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
62+
String inputLine;
63+
StringBuffer response = new StringBuffer();
64+
65+
while ((inputLine = in.readLine()) != null) {
66+
response.append(inputLine);
67+
}
68+
in.close();
69+
log.debug(response.toString());
70+
// info.setBiography(response.toString());
71+
info = getBioInfo(response.toString());
72+
} catch (Exception e) {
73+
log.error(" ", e);
74+
}
75+
76+
return info;
77+
}
78+
79+
private ArtistInfo getBioInfo(String info) {
80+
ArtistInfo artistInfo = new ArtistInfo();
81+
JsonReader reader = Json.createReader(new StringReader(info));
82+
JsonObject jsonObject = reader.readObject();
83+
reader.close();
84+
if (jsonObject.containsKey("artist")) {
85+
JsonObject artist = jsonObject.getJsonObject("artist");
86+
if (artist.containsKey("bio")) {
87+
JsonObject bio = artist.getJsonObject("bio");
88+
//log.debug("Bio: " + bio);
89+
90+
if (bio.containsKey("content")) {
91+
String content = bio.getString("content");
92+
93+
if (!content.equals("")) {
94+
artistInfo.setBiography(content);
95+
} else {
96+
if (bio.containsKey("summary")) {
97+
String summary = bio.getString("summary");
98+
artistInfo.setBiography(summary);
99+
}
100+
}
101+
}
102+
}
103+
if (artist.containsKey("image")) {
104+
JsonArray images = artist.getJsonArray("image");
105+
if (images != null) {
106+
for (Object o : images) {
107+
if (o instanceof JsonObject) {
108+
JsonObject image = (JsonObject) o;
109+
if (image.containsKey("size")) {
110+
String size = image.getString("size");
111+
String url = image.getString("#text");
112+
if (!url.equals("")) {
113+
artistInfo.setImageURL(url);
114+
if (size.equalsIgnoreCase("LARGE")) {
115+
break;
116+
}
117+
}
118+
}
119+
}
120+
}
121+
//log.debug("Images");
122+
}
123+
124+
}
125+
/*
126+
* for (JsonValue jsonValue : body) { if (jsonValue.getValueType()
127+
* == ValueType.OBJECT) { JsonObject object = (JsonObject)
128+
* jsonValue; if (object.containsKey("artist")) {
129+
* log.debug("ContainsArtist"); } if (object.containsKey("name")) {
130+
* //name = object.getString("name"); } if
131+
* (object.containsKey("type")) { //type = object.getString("type");
132+
* } if (object.containsKey("time")) { //time =
133+
* object.getString("time"); } if (object.containsKey("volume")) {
134+
* //volume = object.getInt("volume"); } if
135+
* (object.containsKey("channel")) { //channel =
136+
* object.getString("channel"); } if (object.containsKey("shuffle"))
137+
* { //shuffle = object.getBoolean("shuffle"); }
138+
*
139+
* } }
140+
*/
141+
142+
}
143+
return artistInfo;
144+
}
145+
146+
}

com.upnp.mediaplayer/src/org/rpi/web/longpolling/WorkqeueEvents.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,11 @@ private ArtistInfo GetArtistInfo(String artist) {
405405
if (artist.equalsIgnoreCase("SOON"))
406406
return info;
407407
try {
408-
JenUttils util = new JenUttils();
408+
//JenUttils util = new JenUttils();
409+
LastFMUtils util = new LastFMUtils();
409410
info = util.searchArtistByName(artist);
410-
} catch (EchoNestException e1) {
411-
log.error(e1);
411+
} catch (Exception e1) {
412+
log.error("Error Getting ArtistInfo form EchoNest",e1);
412413
}
413414
mArtistInfo.put(artist.toUpperCase(), info);
414415

com.upnp.mediaplayer/web/AlarmPage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ <h1 id="header">
6464

6565
<div data-role="footer" class="footer-docs" data-theme="c">
6666
<p class="jqm-version"></p>
67-
<p>&copy; 2014 Pete Hoyle</p>
67+
<p>&copy; 2017 Pete Hoyle</p>
6868
</div>
6969

7070
<div data-role="panel" id="leftpanel1" data-position="left" data-display="reveal" data-dismissible="true" data-theme="a">

com.upnp.mediaplayer/web/MainPage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ <h1 id="header">
198198

199199
<div data-role="footer" class="footer-docs" data-theme="c">
200200
<p class="jqm-version"></p>
201-
<p>&copy; 2014 Pete Hoyle</p>
201+
<p>&copy; 2017 Pete Hoyle</p>
202202
</div>
203203

204204
<div data-role="panel" id="leftpanel1" data-position="left"

0 commit comments

Comments
 (0)