Last active
November 26, 2016 17:09
-
-
Save undownding/ea29d1c6e18fda05a6da802f3bf1670b to your computer and use it in GitHub Desktop.
Baidu Music Api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.undownding.musicsdk.baidu | |
import me.undownding.musicsdk.baidu.bean.Album | |
import me.undownding.musicsdk.baidu.bean.ArtistInfo | |
import me.undownding.musicsdk.baidu.bean.BaiduMusicUtil | |
import me.undownding.musicsdk.baidu.bean.QueryResult | |
import me.undownding.musicsdk.baidu.response.ArtistAlbumListResp | |
import me.undownding.musicsdk.baidu.response.SongListResp | |
import me.undownding.musicsdk.baidu.response.SongPlayResp | |
import retrofit2.Retrofit | |
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory | |
import retrofit2.converter.gson.GsonConverterFactory | |
import retrofit2.http.GET | |
import retrofit2.http.Query | |
import rx.Observable | |
/** | |
* Created by undownding on 16-7-19. | |
*/ | |
interface BaiduMusicApi { | |
companion object { | |
val instance by lazy { | |
RetrofitFactory.create(BaiduMusicUtil.API_URL ,BaiduMusicApi::class.java) | |
} | |
private val API_FROM = "qianqian" | |
private val API_VERSION = "2.1.0" | |
private val API_FORMAT = "json" | |
private val METHOD_SEARCH_CATALOGSUG = "baidu.ting.search.catalogSug" | |
private val METHOD_SONG_LRC = "baidu.ting.song.lry " | |
private val METHOD_SONG_PLAY = "baidu.ting.song.play" | |
private val METHOD_GET_SONGINFO = "baidu.ting.song.getInfos" | |
private val METHOD_GET_ARTISTINFO = "baidu.ting.artist.getinfo" //获取歌手信息 | |
private val METHOD_GET_ARTISTSONGLIST = "baidu.ting.artist.getSongList" //获取歌手的歌曲列表 | |
private val METHOD_GET_ARTISTALUBMLIST = "baidu.ting.artist.getAlbumList" //获取歌手的专辑列表; | |
private val METHOD_GET_ALBUMINFO = "baidu.ting.album.getAlbumInfo" | |
private val METHOD_QUERY_MERGE = "baidu.ting.search.merge" | |
} | |
@GET("/v1/restserver/ting") | |
fun requestSongInfo( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_SONG_PLAY, | |
@Query("format") format: String = API_FORMAT, | |
@Query("songid") artistId: Int | |
): Observable<SongPlayResp> | |
@GET("/v1/restserver/ting") | |
fun requestMusicInfo( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_GET_SONGINFO, | |
@Query("format") format: String = API_FORMAT, | |
@Query("tinguid") artistId: Int | |
): Observable<ArtistInfo> | |
@GET("/v1/restserver/ting") | |
fun requestArtistInfo( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_GET_ARTISTINFO, | |
@Query("format") format: String = API_FORMAT, | |
@Query("tinguid") artistId: Int | |
): Observable<ArtistInfo> | |
@GET("/v1/restserver/ting") | |
fun requestAlbumByArtist( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_GET_ARTISTALUBMLIST, | |
@Query("format") format: String = API_FORMAT, | |
@Query("order") order: Int = 1, | |
@Query("tinguid") artistId: Int, | |
@Query("offset") offset: Int = 0, | |
@Query("limits") limits: Int = 30): Observable<ArtistAlbumListResp> | |
@GET("/v1/restserver/ting") | |
fun requestAlbumDetail( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_GET_ALBUMINFO, | |
@Query("format") format: String = API_FORMAT, | |
@Query("album_id") albumId: Long): Observable<Album> | |
@GET("/v1/restserver/ting") | |
fun requestSongListFromArtist( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_GET_ARTISTSONGLIST, | |
@Query("format") format: String = API_FORMAT, | |
@Query("order") order: Int = 1, | |
@Query("tinguid") artistId: Int, | |
@Query("offset") offset: Int = 0, | |
@Query("limits") limits: Int = 30): Observable<SongListResp> | |
@GET("/v1/restserver/ting") | |
fun search( | |
@Query("from") from: String = API_FROM, | |
@Query("version") version: String = API_VERSION, | |
@Query("method") method: String = METHOD_QUERY_MERGE, | |
@Query("format") format: String = API_FORMAT, | |
@Query("query") keyword: String, | |
@Query("page_no") page: Int = 1, | |
@Query("page_size") size: Int = 50, | |
@Query("type") queryType: Int = QueryResult.SEARCH_TYPE_ALL, | |
@Query("data_source") dataSource: Int = 0, | |
@Query("use_cluster") useCluster: Int = 1): Observable<QueryResult> | |
private class RetrofitFactory { | |
companion object { | |
fun <T> create(url: String, clz: Class<T>): T { | |
return Retrofit.Builder() | |
.baseUrl(url) | |
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build().create(clz) | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.undownding.musicsdk.baidu.bean; | |
/** | |
* 使用百度音乐API的工具类 | |
* | |
* @author Jayce | |
* @date 2015/6/11 | |
*/ | |
public class BaiduMusicUtil { | |
public static final String API_URL = "http://tingapi.ting.baidu.com"; | |
/** | |
* 通过歌曲Id获取歌曲下载地址 同在线播放的地址 | |
* | |
* @param songId | |
* @return | |
*/ | |
public static String getDownloadUrlBySongId(String songId) { | |
return "http://ting.baidu.com/data/music/links?songIds=" + songId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment