use of com.google.gson.JsonParser in project MusicDNA by harjot-oberai.
the class Genius method search.
public static ArrayList<Lyrics> search(String query) {
ArrayList<Lyrics> results = new ArrayList<>();
query = Normalizer.normalize(query, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
JsonObject response = null;
try {
URL queryURL = new URL(String.format("http://api.genius.com/search?q=%s", URLEncoder.encode(query, "UTF-8")));
Connection connection = Jsoup.connect(queryURL.toExternalForm()).header("Authorization", "Bearer " + Config.GENIUS).timeout(0).ignoreContentType(true);
Document document = connection.userAgent(Net.USER_AGENT).get();
response = new JsonParser().parse(document.text()).getAsJsonObject();
} catch (JsonSyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (response == null || response.getAsJsonObject("meta").get("status").getAsInt() != 200)
return results;
JsonArray hits = response.getAsJsonObject("response").getAsJsonArray("hits");
int processed = 0;
while (processed < hits.size()) {
JsonObject song = hits.get(processed).getAsJsonObject().getAsJsonObject("result");
String artist = song.getAsJsonObject("primary_artist").get("name").getAsString();
String title = song.get("title").getAsString();
String url = "http://genius.com/songs/" + song.get("id").getAsString();
Lyrics l = new Lyrics(Lyrics.SEARCH_ITEM);
l.setArtist(artist);
l.setTitle(title);
l.setURL(url);
l.setSource("Genius");
results.add(l);
processed++;
}
return results;
}
use of com.google.gson.JsonParser in project MusicDNA by harjot-oberai.
the class MetalArchives method fromMetaData.
@Reflection
public static Lyrics fromMetaData(String artist, String title) {
String baseURL = "http://www.metal-archives.com/search/ajax-advanced/searching/songs/?bandName=%s&songTitle=%s&releaseType[]=1&exactSongMatch=1&exactBandMatch=1";
String urlArtist = artist.replaceAll("\\s", "+");
String urlTitle = title.replaceAll("\\s", "+");
String url;
String text;
try {
String response = Net.getUrlAsString(String.format(baseURL, urlArtist, urlTitle));
JsonObject jsonResponse = new JsonParser().parse(response).getAsJsonObject();
JsonArray track = jsonResponse.getAsJsonArray("aaData").get(0).getAsJsonArray();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < track.size(); i++) builder.append(track.get(i).getAsString());
Document trackDocument = Jsoup.parse(builder.toString());
url = trackDocument.getElementsByTag("a").get(1).attr("href");
String id = trackDocument.getElementsByClass("viewLyrics").get(0).id().substring(11);
text = Jsoup.connect("http://www.metal-archives.com/release/ajax-view-lyrics/id/" + id).get().body().html();
} catch (JsonParseException | IndexOutOfBoundsException e) {
return new Lyrics(NO_RESULT);
} catch (Exception e) {
return new Lyrics(ERROR);
}
Lyrics lyrics = new Lyrics(POSITIVE_RESULT);
lyrics.setArtist(artist);
lyrics.setTitle(title);
lyrics.setText(text);
lyrics.setSource(domain);
lyrics.setURL(url);
return lyrics;
}
use of com.google.gson.JsonParser in project MusicDNA by harjot-oberai.
the class Bollywood method search.
public static ArrayList<Lyrics> search(String query) {
ArrayList<Lyrics> results = new ArrayList<>();
String searchUrl = "https://api.quicklyric.be/bollywood/search?q=%s";
try {
String jsonText;
jsonText = Net.getUrlAsString(String.format(searchUrl, URLEncoder.encode(query, "utf-8")));
JsonObject jsonResponse = new JsonParser().parse(jsonText).getAsJsonObject();
JsonArray lyricsResults = jsonResponse.getAsJsonArray("lyrics");
if (lyricsResults != null)
for (int i = 0; i < lyricsResults.size(); ++i) {
JsonObject lyricsResult = lyricsResults.get(i).getAsJsonObject();
JsonArray tags = lyricsResult.get("tags").getAsJsonArray();
Lyrics lyrics = new Lyrics(Lyrics.SEARCH_ITEM);
lyrics.setTitle(lyricsResult.get("name").getAsString());
for (int j = 0; j < tags.size(); ++j) {
JsonObject tag = tags.get(j).getAsJsonObject();
if (tag.get("tag_type").getAsString().equals("Singer")) {
lyrics.setArtist(tag.get("name").getAsString().trim());
break;
}
}
lyrics.setURL("https://api.quicklyric.be/bollywood/get?id=" + lyricsResult.get("id").getAsInt());
results.add(lyrics);
}
} catch (IOException | JsonParseException e) {
e.printStackTrace();
}
return results;
}
use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.
the class UserConnectedToGlobalAudio method fromJson.
public static UserConnectedToGlobalAudio fromJson(String message) {
JsonParser parser = new JsonParser();
JsonObject obj = (JsonObject) parser.parse(message);
if (obj.has("header") && obj.has("payload")) {
JsonObject header = (JsonObject) obj.get("header");
JsonObject payload = (JsonObject) obj.get("payload");
if (header.has("name")) {
String messageName = header.get("name").getAsString();
if (messageName == USER_CONNECTED_TO_GLOBAL_AUDIO) {
if (payload.has(Constants.VOICE_CONF) && payload.has(Constants.USER_ID) && payload.has(Constants.NAME)) {
String voiceConf = payload.get(Constants.VOICE_CONF).getAsString();
String userid = payload.get(Constants.USER_ID).getAsString();
String name = payload.get(Constants.NAME).getAsString();
return new UserConnectedToGlobalAudio(voiceConf, userid, name);
}
}
}
}
return null;
}
use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.
the class UserDisconnectedFromGlobalAudio method fromJson.
public static UserDisconnectedFromGlobalAudio fromJson(String message) {
JsonParser parser = new JsonParser();
JsonObject obj = (JsonObject) parser.parse(message);
if (obj.has("header") && obj.has("payload")) {
JsonObject header = (JsonObject) obj.get("header");
JsonObject payload = (JsonObject) obj.get("payload");
if (header.has("name")) {
String messageName = header.get("name").getAsString();
if (messageName == USER_DISCONNECTED_FROM_GLOBAL_AUDIO) {
if (payload.has(Constants.VOICE_CONF) && payload.has(Constants.USER_ID) && payload.has(Constants.NAME)) {
String voiceConf = payload.get(Constants.VOICE_CONF).getAsString();
String userid = payload.get(Constants.USER_ID).getAsString();
String name = payload.get(Constants.NAME).getAsString();
return new UserDisconnectedFromGlobalAudio(voiceConf, userid, name);
}
}
}
}
return null;
}
Aggregations