Skip to content

Commit

Permalink
v1.9.0, fix xiami collect api bug
Browse files Browse the repository at this point in the history
  • Loading branch information
listen1 committed Dec 5, 2018
1 parent 5eda26d commit fb93e2e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 54 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Listen 1 (Chrome Extension) V1.8.1
Listen 1 (Chrome Extension) V1.9.0
==========
最后更新于2018年08月25日
最后更新于2018年12月5日

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)

Expand Down Expand Up @@ -45,6 +45,9 @@ Firefox打包安装
更新日志
-------

`2018-12-05`
* 完全修复虾米音乐歌单访问的问题

`2018-08-25`
* 修复虾米音乐无法播放的bug

Expand Down
4 changes: 2 additions & 2 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function hack_referer_header(details) {
referer_value = "http://music.163.com/";
}

if (details.url.indexOf(".xiami.com/") != -1) {
referer_value = "http://www.xiami.com/";
if (details.url.indexOf("api.xiami.com/") != -1 || details.url.indexOf('.xiami.com/song/playlist/id/') != -1) {
referer_value = "https://www.xiami.com/";
}

if ((details.url.indexOf("y.qq.com/") != -1) ||
Expand Down
137 changes: 91 additions & 46 deletions js/provider/xiami.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,65 @@ var xiami = (function() {
return s;
}

var xm_show_playlist = function(url, hm) {
var offset = getParameterByName("offset",url)
var page = offset/30 + 1
function xm_ensure_cookie(callback){
var domain = 'https://www.xiami.com';
var name = 'xm_sg_tk';
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
if (cookie == null) {
var xhr = new XMLHttpRequest();

xhr.open("GET", "https://www.xiami.com", false);
xhr.send();

var result = xhr.responseText;
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
callback(cookie.value);
});
}
else {
callback(cookie.value);
}
});
}

function xm_get_api_url(api, params, token) {
var params_string = JSON.stringify(params);
var origin = token.split('_')[0] + '_xmMain_' + api + '_' + params_string;
var sign = MD5(origin);
var baseUrl = 'https://www.xiami.com';
return encodeURI(baseUrl + api + '?_q=' + params_string + '&_s=' + sign);
}

var target_url = 'http://www.xiami.com/collect/recommend/page/' + page;
var xm_show_playlist = function(url, hm) {
var offset = getParameterByName("offset",url);
var page = offset/30 + 1;
var pageSize = 60;

return {
success: function(fn) {
var result = [];
hm.get(target_url).then(function(response) {
var data = response.data;
data = $.parseHTML(data);
$(data).find('.block_list ul li').each(function(){
var default_playlist = {
'cover_img_url' : '',
'title': '',
'id': '',
'source_url': ''
};
default_playlist.cover_img_url = handleProtocolRelativeUrl($(this).find('img')[0].src);
default_playlist.title = $(this).find('h3 a')[0].title;
var xiami_url = $(this).find('h3 a')[0].href;
var list_id = xiami_url.split('?')[0].split('/').pop()
default_playlist.id = 'xmplaylist_' + list_id;
default_playlist.source_url = 'http://www.xiami.com/collect/' + list_id;
result.push(default_playlist);
xm_ensure_cookie(function(token){
var api = '/api/list/collect';
var params = {"pagingVO":{"page":page,"pageSize":pageSize},"dataType":"system"};
var url = xm_get_api_url(api, params, token);
hm.get(url).then(function(response) {
for(var i=0; i<response.data.result.data.collects.length; i++) {
var d = response.data.result.data.collects[i];
var default_playlist = {
'cover_img_url' : '',
'title': '',
'id': '',
'source_url': ''
};
default_playlist.cover_img_url = d.collectLogo;
default_playlist.title = d.collectName;
var list_id = d.listId;
default_playlist.id = 'xmplaylist_' + list_id;
default_playlist.source_url = 'http://www.xiami.com/collect/' + list_id;
result.push(default_playlist);
}
return fn({"result":result});
});
return fn({"result":result});
});
}
};
Expand All @@ -81,31 +112,25 @@ var xiami = (function() {

return {
success: function(fn) {
var target_url = 'http://api.xiami.com/web?v=2.0&app_key=1&id=' + list_id +
'&callback=jsonp122&r=collect/detail';
hm({
url:target_url,
method: 'GET',
transformResponse: undefined
})
.then(function(response) {
var data = response.data;
data = data.slice('jsonp122('.length, -')'.length);
data = JSON.parse(data);

var info = {
'cover_img_url': data.data.logo,
'title': data.data.collect_name,
'id': 'xmplaylist_' + list_id,
'source_url': 'http://www.xiami.com/collect/' + list_id
};

var tracks = [];
$.each(data.data.songs, function(index, item){
var track = xm_convert_song(item, 'artist_name');
tracks.push(track);
xm_ensure_cookie(function(token){
var api = '/api/collect/initialize';
var params = {"listId": parseInt(list_id)};
var url = xm_get_api_url(api, params, token);
hm.get(url).then(function(response) {
var collect = response.data.result.data.collectDetail;
var info = {
'cover_img_url': collect.collectLogo,
'title': collect.collectName,
'id': 'xmplaylist_' + list_id,
'source_url': 'http://www.xiami.com/collect/' + list_id
};
var tracks = [];
$.each(response.data.result.data.collectSongs, function(index, item){
var track = xm_convert_song2(item, 'artist_name');
tracks.push(track);
});
return fn({"tracks":tracks, "info":info});
});
return fn({"tracks":tracks, "info":info});
});
}
};
Expand Down Expand Up @@ -147,6 +172,26 @@ var xiami = (function() {
return track;
}

function xm_convert_song2(song_info, artist_field_name) {
var track = {
'id': 'xmtrack_' + song_info.songId,
'title': song_info.songName,
'artist': song_info.artistName,
'artist_id': 'xmartist_' + song_info.artistId,
'album': song_info.albumName,
'album_id': 'xmalbum_' + song_info.albumId,
'source': 'xiami',
'source_url': 'http://www.xiami.com/song/' + song_info.songId,
'img_url': song_info.albumLogo,
'url': 'xmtrack_' + song_info.songId,
//'lyric_url': song_info.lyricInfo.lyricFile
};
if (song_info.lyricInfo != undefined) {
track.lyric_url = song_info.lyricInfo.lyricFile;
}
return track;
}

var xm_search = function(url, hm, se) {
return {
success: function(fn) {
Expand Down
2 changes: 1 addition & 1 deletion listen1.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ <h3 class="masthead-brand" ng-click="showTag(2)">Listen 1</h3>
<div class="settings-content">
<p> Listen 1 主页: <a href="http://listen1.github.io/listen1/" target="_blank"> http://listen1.github.io/listen1/ </a> </p>
<p> Listen 1 邮箱: [email protected] </p>
<p> 当前版本 1.8.1 (本软件基于MIT协议开源免费)</p>
<p> 当前版本 1.9.0 (本软件基于MIT协议开源免费)</p>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"manifest_version": 2,
"name": "Listen 1",
"permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "*://*.kugou.com/", "*://*.kuwo.cn/", "*://api.github.com/*", "*://github.com/*", "webRequest", "webRequestBlocking"],
"version": "1.8.1",
"permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "cookies", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "*://*.kugou.com/", "*://*.kuwo.cn/", "*://api.github.com/*", "*://github.com/*", "webRequest", "webRequestBlocking"],
"version": "1.9.0",
"web_accessible_resources": [ "images/*" ],
"content_scripts": [{
"matches": ["https://listen1.github.io/listen1/*"],
Expand Down
2 changes: 1 addition & 1 deletion manifest_firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"manifest_version": 2,
"name": "Listen 1",
"permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "*://*.kugou.com/", "*://*.kuwo.cn/", "*://api.github.com/*", "*://github.com/*", "webRequest", "webRequestBlocking"],
"version": "1.8.1",
"version": "1.9.0",
"web_accessible_resources": [ "images/*" ],
"content_scripts": [{
"matches": ["https://listen1.github.io/listen1/*"],
Expand Down

0 comments on commit fb93e2e

Please sign in to comment.