
org.jmusixmatch.MusixMatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jMusixMatch Show documentation
Show all versions of jMusixMatch Show documentation
Java MusixMatch API by Sachin Handiekar
package org.jmusixmatch;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import org.jmusixmatch.config.Constants;
import org.jmusixmatch.config.Methods;
import org.jmusixmatch.config.StatusCode;
import org.jmusixmatch.entity.error.ErrorMessage;
import org.jmusixmatch.entity.lyrics.Lyrics;
import org.jmusixmatch.entity.lyrics.get.LyricsGetMessage;
import org.jmusixmatch.entity.track.Track;
import org.jmusixmatch.entity.track.TrackData;
import org.jmusixmatch.entity.track.get.TrackGetMessage;
import org.jmusixmatch.entity.track.search.TrackSeachMessage;
import org.jmusixmatch.http.MusixMatchRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MusixMatch {
/**
* A musiXmatch API Key.
*/
private final String apiKey;
/**
* MusixMatch Constructor with API-Key.
*
* @param apiKey
* A musiXmatch API Key.
*/
public MusixMatch(String apiKey) {
this.apiKey = apiKey;
}
/**
* Get Lyrics for the specific trackID.
*
* @param trackID
* @return
* @throws MusixMatchException
*/
public Lyrics getLyrics(int trackID) throws MusixMatchException {
Lyrics lyrics = null;
LyricsGetMessage message = null;
Map params = new HashMap();
params.put(Constants.API_KEY, apiKey);
params.put(Constants.TRACK_ID, new String("" + trackID));
String response = null;
response = MusixMatchRequest.sendRequest(Helper.getURLString(
Methods.TRACK_LYRICS_GET, params));
Gson gson = new Gson();
try {
message = gson.fromJson(response, LyricsGetMessage.class);
} catch (JsonParseException jpe) {
handleErrorResponse(response);
}
lyrics = message.getContainer().getBody().getLyrics();
return lyrics;
}
/**
* Search tracks using the given criteria.
*
* @param q
* search into every available field
* (track_name,artist_name,lyrics)
* @param q_artist
* search for text string among artist names
* @param q_track
* search for text string among track names
* @param page
* request specific result page
* @param pageSize
* specify number of items per result page
* @param f_has_lyrics
* specify number of items per result page
* @return a list of tracks.
* @throws MusixMatchException
* if any error occur
*/
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy