Initial commit retro music app
This commit is contained in:
parent
ab332473bc
commit
fe890632fd
932 changed files with 83126 additions and 0 deletions
|
@ -0,0 +1,76 @@
|
|||
package code.name.monkey.retromusic.rest;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import code.name.monkey.retromusic.Constants;
|
||||
import code.name.monkey.retromusic.RetroApplication;
|
||||
import code.name.monkey.retromusic.rest.service.KuGouApiService;
|
||||
import java.io.File;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
* Created by hemanths on 23/08/17.
|
||||
*/
|
||||
|
||||
public class KogouClient {
|
||||
|
||||
private static final String BASE_URL = Constants.BASE_API_URL_KUGOU;
|
||||
|
||||
private KuGouApiService apiService;
|
||||
|
||||
public KogouClient() {
|
||||
this(createDefaultOkHttpClientBuilder().build());
|
||||
}
|
||||
|
||||
public KogouClient(@NonNull Call.Factory client) {
|
||||
Retrofit restAdapter = new Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.callFactory(client)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
|
||||
apiService = restAdapter.create(KuGouApiService.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Cache createDefaultCache(Context context) {
|
||||
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
|
||||
if (cacheDir.mkdirs() || cacheDir.isDirectory()) {
|
||||
return new Cache(cacheDir, 1024 * 1024 * 10);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Interceptor createCacheControlInterceptor() {
|
||||
return chain -> {
|
||||
Request modifiedRequest = chain.request().newBuilder()
|
||||
.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000))
|
||||
.build();
|
||||
return chain.proceed(modifiedRequest);
|
||||
};
|
||||
}
|
||||
|
||||
public static OkHttpClient.Builder createDefaultOkHttpClientBuilder() {
|
||||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
|
||||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(interceptor)
|
||||
.cache(createDefaultCache(RetroApplication.getInstance()))
|
||||
.addInterceptor(createCacheControlInterceptor());
|
||||
}
|
||||
|
||||
public KuGouApiService getApiService() {
|
||||
return apiService;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package code.name.monkey.retromusic.rest;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import code.name.monkey.retromusic.rest.service.LastFMService;
|
||||
import java.io.File;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
|
||||
public class LastFMRestClient {
|
||||
|
||||
public static final String BASE_URL = "http://ws.audioscrobbler.com/2.0/";
|
||||
|
||||
private LastFMService apiService;
|
||||
|
||||
public LastFMRestClient(@NonNull Context context) {
|
||||
this(createDefaultOkHttpClientBuilder(context).build());
|
||||
}
|
||||
|
||||
public LastFMRestClient(@NonNull Call.Factory client) {
|
||||
Retrofit restAdapter = new Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.callFactory(client)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
|
||||
apiService = restAdapter.create(LastFMService.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Cache createDefaultCache(Context context) {
|
||||
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
|
||||
if (cacheDir.mkdirs() || cacheDir.isDirectory()) {
|
||||
return new Cache(cacheDir, 1024 * 1024 * 10);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Interceptor createCacheControlInterceptor() {
|
||||
return chain -> {
|
||||
Request modifiedRequest = chain.request().newBuilder()
|
||||
.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000))
|
||||
.build();
|
||||
return chain.proceed(modifiedRequest);
|
||||
};
|
||||
}
|
||||
|
||||
public static OkHttpClient.Builder createDefaultOkHttpClientBuilder(Context context) {
|
||||
return new OkHttpClient.Builder()
|
||||
.cache(createDefaultCache(context))
|
||||
.addInterceptor(createCacheControlInterceptor());
|
||||
}
|
||||
|
||||
public LastFMService getApiService() {
|
||||
return apiService;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package code.name.monkey.retromusic.rest.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by hefuyi on 2017/1/20.
|
||||
*/
|
||||
|
||||
public class KuGouRawLyric {
|
||||
|
||||
private static final String CHARSET = "charset";
|
||||
private static final String CONTENT = "content";
|
||||
private static final String FMT = "fmt";
|
||||
private static final String INFO = "info";
|
||||
private static final String STATUS = "status";
|
||||
|
||||
@SerializedName(CHARSET)
|
||||
public String charset;
|
||||
|
||||
@SerializedName(CONTENT)
|
||||
public String content;
|
||||
|
||||
@SerializedName(FMT)
|
||||
public String fmt;
|
||||
@SerializedName(INFO)
|
||||
public String info;
|
||||
@SerializedName(STATUS)
|
||||
public int status;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KuGouRawLyric{" +
|
||||
"charset='" + charset + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", fmt='" + fmt + '\'' +
|
||||
", info='" + info + '\'' +
|
||||
", status=" + status +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package code.name.monkey.retromusic.rest.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by hefuyi on 2017/1/20.
|
||||
*/
|
||||
|
||||
public class KuGouSearchLyricResult {
|
||||
|
||||
private static final String INFO = "info";
|
||||
private static final String STATUS = "status";
|
||||
private static final String PROPOSAL = "proposal";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String CANDIDATES = "candidates";
|
||||
|
||||
@SerializedName(INFO)
|
||||
public String info;
|
||||
|
||||
@SerializedName(STATUS)
|
||||
public int status;
|
||||
|
||||
@SerializedName(PROPOSAL)
|
||||
public String proposal;
|
||||
|
||||
@SerializedName(KEYWORD)
|
||||
public String keyword;
|
||||
|
||||
@SerializedName(CANDIDATES)
|
||||
public List<Candidates> candidates;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KuGouSearchLyricResult{" +
|
||||
"info='" + info + '\'' +
|
||||
", status=" + status +
|
||||
", proposal='" + proposal + '\'' +
|
||||
", keyword='" + keyword + '\'' +
|
||||
", candidates=" + candidates +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class Candidates {
|
||||
private static final String NICKNAME = "nickname";
|
||||
private static final String ACCESSKEY = "accesskey";
|
||||
private static final String SCORE = "score";
|
||||
private static final String DURATION = "duration";
|
||||
private static final String UID = "uid";
|
||||
private static final String SONG = "song";
|
||||
private static final String ID = "id";
|
||||
private static final String SINGER = "singer";
|
||||
private static final String LANGUAGE = "language";
|
||||
@SerializedName(NICKNAME)
|
||||
public String nickname;
|
||||
@SerializedName(ACCESSKEY)
|
||||
public String accesskey;
|
||||
@SerializedName(SCORE)
|
||||
public int score;
|
||||
@SerializedName(DURATION)
|
||||
public long duration;
|
||||
@SerializedName(UID)
|
||||
public String uid;
|
||||
@SerializedName(SONG)
|
||||
public String songName;
|
||||
@SerializedName(ID)
|
||||
public String id;
|
||||
@SerializedName(SINGER)
|
||||
public String singer;
|
||||
@SerializedName(LANGUAGE)
|
||||
public String language;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Candidates{" +
|
||||
"nickname='" + nickname + '\'' +
|
||||
", accesskey='" + accesskey + '\'' +
|
||||
", score=" + score +
|
||||
", duration=" + duration +
|
||||
", uid='" + uid + '\'' +
|
||||
", songName='" + songName + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
", singer='" + singer + '\'' +
|
||||
", language='" + language + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package code.name.monkey.retromusic.rest.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LastFmAlbum {
|
||||
@Expose
|
||||
private Album album;
|
||||
|
||||
public Album getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public void setAlbum(Album album) {
|
||||
this.album = album;
|
||||
}
|
||||
|
||||
public static class Album {
|
||||
@Expose
|
||||
private Tags tags;
|
||||
@Expose
|
||||
private List<Image> image = new ArrayList<>();
|
||||
@Expose
|
||||
private Wiki wiki;
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Wiki getWiki() {
|
||||
return wiki;
|
||||
}
|
||||
|
||||
public void setWiki(Wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
}
|
||||
|
||||
public Tags getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public static class Image {
|
||||
@SerializedName("#text")
|
||||
@Expose
|
||||
private String Text;
|
||||
@Expose
|
||||
private String size;
|
||||
|
||||
public String getText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
public void setText(String Text) {
|
||||
this.Text = Text;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
public class Tags {
|
||||
@Expose
|
||||
private List<Tag> tag = null;
|
||||
|
||||
public List<Tag> getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
public class Tag {
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
@Expose
|
||||
private String url;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public class Wiki {
|
||||
@Expose
|
||||
private String content;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package code.name.monkey.retromusic.rest.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LastFmArtist {
|
||||
@Expose
|
||||
private Artist artist;
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(Artist artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public static class Artist {
|
||||
@Expose
|
||||
private List<Image> image = new ArrayList<>();
|
||||
@Expose
|
||||
private Bio bio;
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Bio getBio() {
|
||||
return bio;
|
||||
}
|
||||
|
||||
public void setBio(Bio bio) {
|
||||
this.bio = bio;
|
||||
}
|
||||
|
||||
public class Bio {
|
||||
@Expose
|
||||
private String content;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Image {
|
||||
@SerializedName("#text")
|
||||
@Expose
|
||||
private String Text;
|
||||
@Expose
|
||||
private String size;
|
||||
|
||||
public String getText() {
|
||||
return Text;
|
||||
}
|
||||
|
||||
public void setText(String Text) {
|
||||
this.Text = Text;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package code.name.monkey.retromusic.rest.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by hemanths on 15/06/17.
|
||||
*/
|
||||
|
||||
public class LastFmTrack {
|
||||
|
||||
@Expose
|
||||
private Track track;
|
||||
|
||||
public Track getTrack() {
|
||||
return track;
|
||||
}
|
||||
|
||||
public void setTrack(Track track) {
|
||||
this.track = track;
|
||||
}
|
||||
|
||||
public static class Track {
|
||||
@SerializedName("name")
|
||||
@Expose
|
||||
private String name;
|
||||
@Expose
|
||||
private Album album;
|
||||
@Expose
|
||||
private Wiki wiki;
|
||||
@Expose
|
||||
private Toptags toptags;
|
||||
@Expose
|
||||
private Artist artist;
|
||||
|
||||
public Album getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public Wiki getWiki() {
|
||||
return wiki;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Toptags getToptags() {
|
||||
return toptags;
|
||||
}
|
||||
|
||||
public static class Artist {
|
||||
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Wiki {
|
||||
@Expose
|
||||
private String published;
|
||||
|
||||
public String getPublished() {
|
||||
return published;
|
||||
}
|
||||
|
||||
public void setPublished(String published) {
|
||||
this.published = published;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Toptags {
|
||||
@Expose
|
||||
private List<Tag> tag = null;
|
||||
|
||||
|
||||
public List<Tag> getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static class Tag {
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Album {
|
||||
@Expose
|
||||
private String artist;
|
||||
@Expose
|
||||
private List<Image> image = null;
|
||||
@Expose
|
||||
private String title;
|
||||
@SerializedName("@attr")
|
||||
@Expose
|
||||
private Attr attr;
|
||||
|
||||
public Attr getAttr() {
|
||||
return attr;
|
||||
}
|
||||
|
||||
public void setAttr(Attr attr) {
|
||||
this.attr = attr;
|
||||
}
|
||||
|
||||
public String getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(String artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<Image> getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(List<Image> image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public static class Attr {
|
||||
@Expose
|
||||
private String position;
|
||||
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
public class Image {
|
||||
|
||||
@SerializedName("#text")
|
||||
@Expose
|
||||
private String text;
|
||||
@Expose
|
||||
private String size;
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package code.name.monkey.retromusic.rest.service;
|
||||
|
||||
import code.name.monkey.retromusic.rest.model.KuGouRawLyric;
|
||||
import code.name.monkey.retromusic.rest.model.KuGouSearchLyricResult;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* Created by hemanths on 28/07/17.
|
||||
*/
|
||||
|
||||
public interface KuGouApiService {
|
||||
|
||||
@GET("search?ver=1&man=yes&client=pc")
|
||||
Observable<KuGouSearchLyricResult> searchLyric(@Query("keyword") String songName, @Query("duration") String duration);
|
||||
|
||||
@GET("download?ver=1&client=pc&fmt=lrc&charset=utf8")
|
||||
Observable<KuGouRawLyric> getRawLyric(@Query("id") String id, @Query("accesskey") String accesskey);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package code.name.monkey.retromusic.rest.service;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import code.name.monkey.retromusic.BuildConfig;
|
||||
import code.name.monkey.retromusic.rest.model.LastFmAlbum;
|
||||
import code.name.monkey.retromusic.rest.model.LastFmArtist;
|
||||
import code.name.monkey.retromusic.rest.model.LastFmTrack;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
|
||||
|
||||
public interface LastFMService {
|
||||
String API_KEY = "bd9c6ea4d55ec9ed3af7d276e5ece304";
|
||||
//String API_KEY = BuildConfig.LASTFM_API_KEY;
|
||||
//String BASE_QUERY_PARAMETERS = "?format=json&autocorrect=1&api_key=" + API_KEY;
|
||||
String BASE_QUERY_PARAMETERS = "?format=json&autocorrect=1&api_key=" + API_KEY;
|
||||
String METHOD_TRACK = "track.getInfo";
|
||||
|
||||
@GET(BASE_QUERY_PARAMETERS + "&method=album.getinfo")
|
||||
Observable<LastFmAlbum> getAlbumInfo(@Query("album") String albumName, @Query("artist") String artistName, @Nullable @Query("lang") String language);
|
||||
|
||||
@GET("?api_key=" + BuildConfig.LASTFM_API_KEY + "&format=json&autocorrect=1" + "&method=" + METHOD_TRACK)
|
||||
Observable<LastFmTrack> getTrackInfo(@Query("artist") String artist, @Query("track") String track);
|
||||
|
||||
@GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo")
|
||||
Call<LastFmArtist> getArtistInfo(@Query("artist") String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue