From fb93e2e6e737b1348f783190d6a9d3678f0f8195 Mon Sep 17 00:00:00 2001 From: Listen 1 Date: Wed, 5 Dec 2018 15:23:38 +0800 Subject: [PATCH] v1.9.0, fix xiami collect api bug --- README.md | 7 ++- js/background.js | 4 +- js/provider/xiami.js | 137 ++++++++++++++++++++++++++++-------------- listen1.html | 2 +- manifest.json | 4 +- manifest_firefox.json | 2 +- 6 files changed, 102 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 82622ec2..dc3caf9a 100644 --- a/README.md +++ b/README.md @@ -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) @@ -45,6 +45,9 @@ Firefox打包安装 更新日志 ------- +`2018-12-05` +* 完全修复虾米音乐歌单访问的问题 + `2018-08-25` * 修复虾米音乐无法播放的bug diff --git a/js/background.js b/js/background.js index a84a3ad6..835eb5f2 100644 --- a/js/background.js +++ b/js/background.js @@ -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) || diff --git a/js/provider/xiami.js b/js/provider/xiami.js index fe57527d..4e8baf04 100644 --- a/js/provider/xiami.js +++ b/js/provider/xiami.js @@ -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; iListen 1

Listen 1 主页: http://listen1.github.io/listen1/

Listen 1 邮箱: githublisten1@gmail.com

-

当前版本 1.8.1 (本软件基于MIT协议开源免费)

+

当前版本 1.9.0 (本软件基于MIT协议开源免费)

diff --git a/manifest.json b/manifest.json index 8970318d..c9a87b38 100644 --- a/manifest.json +++ b/manifest.json @@ -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/*"], diff --git a/manifest_firefox.json b/manifest_firefox.json index 077f795a..4a747a7f 100644 --- a/manifest_firefox.json +++ b/manifest_firefox.json @@ -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/*"],