My initial commit

Removed Google play dependencies
This commit is contained in:
Muntashir Al-Islam 2020-06-17 22:50:30 +06:00
parent fd582fff69
commit 301ac10570
430 changed files with 2210 additions and 3137 deletions

View file

@ -0,0 +1,69 @@
package io.github.muntashirakon.music.rest
import io.github.muntashirakon.music.App
import io.github.muntashirakon.music.rest.service.LastFMService
import com.google.gson.Gson
import okhttp3.Cache
import okhttp3.ConnectionPool
import okhttp3.Interceptor
import okhttp3.Interceptor.Chain
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.io.File
import java.util.concurrent.TimeUnit
object LastFmClient {
private const val baseUrl = "https://ws.audioscrobbler.com/2.0/"
private var lastFMService: LastFMService
fun getApiService(): LastFMService {
return lastFMService
}
init {
lastFMService = Retrofit.Builder()
.baseUrl(baseUrl)
.callFactory(createDefaultOkHttpClientBuilder().build())
.addConverterFactory(GsonConverterFactory.create(Gson()))
.build()
.create(LastFMService::class.java)
}
private fun createDefaultOkHttpClientBuilder(): OkHttpClient.Builder {
return OkHttpClient.Builder()
.connectionPool(ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
.retryOnConnectionFailure(true)
.connectTimeout(1, TimeUnit.MINUTES) // connect timeout
.writeTimeout(1, TimeUnit.MINUTES) // write timeout
.readTimeout(1, TimeUnit.MINUTES) // read timeout
.cache(createDefaultCache())
.addInterceptor(createCacheControlInterceptor())
.addInterceptor(createLogInterceptor())
}
private fun createLogInterceptor(): Interceptor {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BASIC
return interceptor
}
private fun createCacheControlInterceptor(): Interceptor {
return Interceptor { chain: Chain ->
val modifiedRequest = chain.request().newBuilder()
.addHeader("Cache-Control", "max-age=31536000, max-stale=31536000")
.build()
chain.proceed(modifiedRequest)
}
}
private fun createDefaultCache(): Cache? {
val cacheDir = File(App.getContext().cacheDir.absolutePath, "/okhttp-lastfm/")
if (cacheDir.mkdirs() || cacheDir.isDirectory) {
return Cache(cacheDir, 1024 * 1024 * 10)
}
return null
}
}

View file

@ -0,0 +1,173 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package io.github.muntashirakon.music.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
public String listeners;
@Expose
public String playcount;
@Expose
private List<Image> image = new ArrayList<>();
@Expose
private String name;
@Expose
private Tags tags;
@Expose
private Wiki wiki;
public List<Image> getImage() {
return image;
}
public void setImage(List<Image> image) {
this.image = image;
}
public String getListeners() {
return listeners;
}
public void setListeners(final String listeners) {
this.listeners = listeners;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getPlaycount() {
return playcount;
}
public void setPlaycount(final String playcount) {
this.playcount = playcount;
}
public Tags getTags() {
return tags;
}
public Wiki getWiki() {
return wiki;
}
public void setWiki(Wiki wiki) {
this.wiki = wiki;
}
public static class Image {
@SerializedName("#text")
@Expose
private String Text;
@Expose
private String size;
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getText() {
return Text;
}
public void setText(String Text) {
this.Text = Text;
}
}
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;
@Expose
private String published;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPublished() {
return published;
}
public void setPublished(final String published) {
this.published = published;
}
}
}
}

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package io.github.muntashirakon.music.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
public Stats stats;
@Expose
private Bio bio;
@Expose
private List<Image> image = new ArrayList<>();
public Bio getBio() {
return bio;
}
public void setBio(Bio bio) {
this.bio = bio;
}
public List<Image> getImage() {
return image;
}
public void setImage(List<Image> image) {
this.image = image;
}
public static class Image {
@SerializedName("#text")
@Expose
private String Text;
@Expose
private String size;
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getText() {
return Text;
}
public void setText(String Text) {
this.Text = Text;
}
}
public static class Stats {
@Expose
public String listeners;
@Expose
public String playcount;
public String getListeners() {
return listeners;
}
public void setListeners(final String listeners) {
this.listeners = listeners;
}
public String getPlaycount() {
return playcount;
}
public void setPlaycount(final String playcount) {
this.playcount = playcount;
}
}
public class Bio {
@Expose
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
}
}

View file

@ -0,0 +1,188 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package io.github.muntashirakon.music.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;
}
}
}
}
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package io.github.muntashirakon.music.rest.service
import io.github.muntashirakon.music.rest.model.LastFmAlbum
import io.github.muntashirakon.music.rest.model.LastFmArtist
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query
/**
* Created by hemanths on 2019-11-26.
*/
interface LastFMService {
companion object {
private const val API_KEY = "c679c8d3efa84613dc7dcb2e8d42da4c"
const val BASE_QUERY_PARAMETERS = "?format=json&autocorrect=1&api_key=$API_KEY"
}
@GET("$BASE_QUERY_PARAMETERS&method=artist.getinfo")
suspend fun artistInfo(
@Query("artist") artistName: String,
@Query("lang") language: String?,
@Header("Cache-Control") cacheControl: String?
): LastFmArtist
@GET("$BASE_QUERY_PARAMETERS&method=album.getinfo")
suspend fun albumInfo(
@Query("artist") artistName: String,
@Query("album") albumName: String
): LastFmAlbum
}