博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java解析虾米音乐
阅读量:5916 次
发布时间:2019-06-19

本文共 4157 字,大约阅读时间需要 13 分钟。

import java.io.UnsupportedEncodingException;import java.net.URLDecoder;import java.util.HashMap;import java.util.Map;import blade.kit.http.HttpRequest;import blade.kit.json.JSONArray;import blade.kit.json.JSONObject;public class XiaMi {
private static final String UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53"; public static Map
getXiaMiData(String id) {
Map
map = new HashMap
(); String url = "http://www.xiami.com/song/playlist/id/"+ id +"/object_id/0/cat/json"; String content = HttpRequest.get(url) .userAgent(UA) .referer("http://www.xiami.com/song/playlist/id/" + id).body(); try {
JSONObject jsonObject = new JSONObject(content); if(null == jsonObject || !jsonObject.getBoolean("status")){
return map; } JSONObject data = jsonObject.getJSONObject("data"); if(null == data){
return map; } JSONArray trackList = data.getJSONArray("trackList"); if(null == trackList){
return map; } JSONObject track = trackList.getJSONObject(0); String songurl = track.getString("location"); songurl = xiamidecode(songurl); String songpic = track.getString("album_pic").replace(".jpg", "_2.jpg"); String title = track.getString("title"); String singer = track.getString("artist"); String lyricurl = track.getString("lyric"); map.put("id", id); map.put("songurl", songurl); map.put("songpic", songpic); map.put("title", title); map.put("singer", singer); map.put("lyricurl", lyricurl); } catch (UnsupportedEncodingException e) {
e.printStackTrace(); } return map; } private static String xiamidecode(String location) throws UnsupportedEncodingException {
int _local10; int _local2 = Integer.parseInt(location.substring(0, 1)); String _local3 = location.substring(1, location.length()); double _local4 = Math.floor(_local3.length() / _local2); int _local5 = _local3.length() % _local2; String[] _local6 = new String[_local2]; int _local7 = 0; while (_local7 < _local5) {
if (_local6[_local7] == null) {
_local6[_local7] = ""; } _local6[_local7] = _local3.substring((((int) _local4 + 1) * _local7), (((int) _local4 + 1) * _local7) + ((int) _local4 + 1)); _local7++; } _local7 = _local5; while (_local7 < _local2) {
_local6[_local7] = _local3 .substring((((int) _local4 * (_local7 - _local5)) + (((int) _local4 + 1) * _local5)), (((int) _local4 * (_local7 - _local5)) + (((int) _local4 + 1) * _local5))+(int) _local4); _local7++; } String _local8 = ""; _local7 = 0; while (_local7 < ((String) _local6[0]).length()) {
_local10 = 0; while (_local10 < _local6.length) {
if (_local7 >= _local6[_local10].length()) {
break; } _local8 = (_local8 + _local6[_local10].charAt(_local7)); _local10++; } _local7++; } _local8 = URLDecoder.decode(_local8, "utf8"); String _local9 = ""; _local7 = 0; while (_local7 < _local8.length()) {
if (_local8.charAt(_local7) == '^'){
_local9 = (_local9 + "0"); } else {
_local9 = (_local9 + _local8.charAt(_local7)); }; _local7++; } _local9 = _local9.replace("+", " "); return _local9; } }

转载地址:http://lotpx.baihongyu.com/

你可能感兴趣的文章
前缀中缀后缀表达式
查看>>
前端HTML-CSS规范
查看>>
iOS开发UI篇—UIScrollView控件介绍
查看>>
IIS Express魔法堂:解除localhost域名的锁定
查看>>
django 快速实现注册
查看>>
AKKA文档(java版)——什么是AKKA?
查看>>
swift关于UIView设置frame值的extension
查看>>
zfs performance tuning basic
查看>>
遵守 TDD 实现一个精简版的 HashMap
查看>>
Swift 开源项目精选导图
查看>>
java流
查看>>
# 学习笔记-性能测试 #
查看>>
工作流 springboot activiti mybatis 后台框架平台 集成代码生成器 shiro 权限
查看>>
开源大数据周刊-第60期
查看>>
个人对于flux、redux及vuex的理解
查看>>
双向通信之websocket
查看>>
Flutter如何添加第三方库?
查看>>
同源策略和一些跨域方法的记录
查看>>
分布式架构springcloud+redis+springmvc+springboot
查看>>
Webpack3之Vue-loader配置简述
查看>>