Skip to content

Commit

Permalink
fix kugou empty playlist after add to fav bug
Browse files Browse the repository at this point in the history
  • Loading branch information
listen1 committed Jun 10, 2018
1 parent 9a2a0c1 commit 0fa713d
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 130 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Listen 1 (Chrome Extension) V1.7.0
Listen 1 (Chrome Extension) V1.7.1
==========
(最后更新于2018年06月10日)

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

`2018-06-10`
* 修复酷狗音乐收藏歌单后可能显示空歌单的bug

`2018-06-10`
* 修复虾米音乐无法显示歌词的bug

Expand Down
290 changes: 164 additions & 126 deletions js/provider/kugou.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ var kugou = (function() {
return track;
}

function async_process_list(data_list, handler, handler_extra_param_list, callback) {
var tracks = [];
var fnDict = {};
$.each(data_list, function(index, item){
fnDict[index] = function(callback){
return handler(index, item, handler_extra_param_list, callback);
};
});
async.parallel(fnDict, function(err, results){
$.each(data_list, function(index){
tracks.push(results[index]);
});
callback(null, tracks);
});
}

function kg_render_search_result_item(index, item, params, callback) {
var hm = params[0];

var track = kg_convert_song(item);
// Add singer img
var url = 'http://www.kugou.com/yy/index.php?'
+ 'r=play/getdata&hash=' + track.lyric_url;
hm({
url: url,
method: 'GET',
transformResponse: undefined
}).then(function(response){
var data = response.data;
data = JSON.parse(data);
track.img_url = data.data.img;
callback(null, track);
});
}

var kg_search = function(url, hm, se) {
return {
success: function(fn) {
Expand All @@ -41,29 +76,52 @@ var kugou = (function() {
.then(function(response){
var data = response.data
data = JSON.parse(data);
var tracks = []
$.each(data.data.lists, function(index, item){
var track = kg_convert_song(item);
// Add singer img
target_url = 'http://www.kugou.com/yy/index.php?'
+ 'r=play/getdata&hash=' + track.lyric_url;
hm({
url: target_url,
method: 'GET',
transformResponse: undefined
}).then(function(response){
var data = response.data;
data = JSON.parse(data);
track.img_url = data.data.img;
});
tracks.push(track);
async_process_list(data.data.lists, kg_render_search_result_item, [hm], function(err, tracks){
return fn({"result": tracks, "total": data.data.total});
});
return fn({"result": tracks, "total": data.data.total});
});
}
};
}

function kg_render_playlist_result_item(index, item, params, callback){
var hm = params[0];
var target_url = 'http://m.kugou.com/app/i/getSongInfo.php?'
+ 'cmd=playInfo&hash=' + item.hash;

var track = {
'id': 'kgtrack_' + item.hash,
'title': '',
'artist': '',
'artist_id': '',
'album': '',
'album_id': 'kgalbum_' + item.album_id,
'source': 'kugou',
'source_url': 'http://www.kugou.com/song/#hash='
+ item.hash + '&album_id=' + item.album_id,
'img_url': '',
'url': 'xmtrack_' + item.hash,
'lyric_url': item.hash
};
// Fix song info
hm.get(target_url).then(function(response){
var data = response.data;
track['title'] = data.songName;
track['artist'] = data.singerId == 0 ?
'未知' : data.singerName;
track['artist_id'] = 'kgartist_' + data.singerId;
track['img_url'] = data.imgUrl.replace('{size}', '400');
// Fix album
target_url = 'http://mobilecdnbj.kugou.com/api/v3/album/info?albumid='
+ item.album_id;
hm.get(target_url).then(function(response){
var data = response.data;
track['album'] = data.status ? data.data.albumname : '';
return callback(null, track);
});
});
}

var kg_get_playlist = function(url, hm, se) {
return {
success: function(fn) {
Expand All @@ -83,48 +141,55 @@ var kugou = (function() {
};

var tracks = [];
$.each(data.list.list.info, function(index, item){
target_url = 'http://m.kugou.com/app/i/getSongInfo.php?'
+ 'cmd=playInfo&hash=' + item.hash;

var track = {
'id': 'kgtrack_' + item.hash,
'title': '',
'artist': '',
'artist_id': '',
'album': '',
'album_id': 'kgalbum_' + item.album_id,
'source': 'kugou',
'source_url': 'http://www.kugou.com/song/#hash='
+ item.hash + '&album_id=' + item.album_id,
'img_url': '',
'url': 'xmtrack_' + item.hash,
'lyric_url': item.hash
};
// Fix song info
hm.get(target_url).then(function(response){
var data = response.data;
track['title'] = data.songName;
track['artist'] = data.singerId == 0 ?
'未知' : data.singerName;
track['artist_id'] = 'kgartist_' + data.singerId;
track['img_url'] = data.imgUrl.replace('{size}', '400');
});
// Fix album
target_url = 'http://mobilecdnbj.kugou.com/api/v3/album/info?albumid='
+ item.album_id;
hm.get(target_url).then(function(response){
var data = response.data;
track['album'] = data.status ? data.data.albumname : '';
});
tracks.push(track);
async_process_list(data.list.list.info, kg_render_playlist_result_item, [hm], function(err, tracks){
return fn({"tracks":tracks, "info":info});
});
return fn({"tracks":tracks, "info":info});
});
}
};
}

function kg_render_artist_result_item(index, item, params, callback){
var hm = params[0];
var info = params[1];
var track = {
'id': 'kgtrack_' + item.hash,
'title': '',
'artist': '',
'artist_id': info['id'],
'album': '',
'album_id': 'kgalbum_' + item.album_id,
'source': 'kugou',
'source_url': 'http://www.kugou.com/song/#hash='
+ item.hash + '&album_id=' + item.album_id,
'img_url': '',
'url': 'kgtrack_' + item.hash,
'lyric_url': item.hash
};
var one = item.filename.split('-');
track['title'] = $.trim(one[1]);
track['artist'] = $.trim(one[0]);
// Fix album name and img
var target_url = 'http://www.kugou.com/yy/index.php?'
+ 'r=play/getdata&hash=' + item.hash;
hm({
url: 'http://mobilecdnbj.kugou.com/api/v3/album/info?albumid=' + item.album_id,
method: 'GET',
transformResponse: undefined
}).then(function(response){
var data = response.data; data = JSON.parse(data);
track['album'] = data.status ? data.data.albumname : '';
hm({
url: target_url, method: 'GET', transformResponse: undefined
}).then(function(response){
var data = JSON.parse(response.data);
track['img_url'] = data.data.img;
callback(null, track);
});
});
}

var kg_artist = function(url, hm, se) {
return {
success: function(fn) {
Expand Down Expand Up @@ -152,43 +217,10 @@ var kugou = (function() {
}).then(function(response){
var data = response.data;
data = JSON.parse(data);
var tracks = []
$.each(data.data.info, function(index, item){
var track = {
'id': 'kgtrack_' + item.hash,
'title': '', 'artist': '', 'artist_id': info['id'],
'album': '',
'album_id': 'kgalbum_' + item.album_id,
'source': 'kugou',
'source_url': 'http://www.kugou.com/song/#hash='
+ item.hash + '&album_id=' + item.album_id,
'img_url': '',
'url': 'kgtrack_' + item.hash,
'lyric_url': item.hash
};
var one = item.filename.split('-');
track['title'] = $.trim(one[1]);
track['artist'] = $.trim(one[0]);
// Fix album name and img
target_url = 'http://www.kugou.com/yy/index.php?'
+ 'r=play/getdata&hash=' + item.hash;
hm({
url: 'http://mobilecdnbj.kugou.com/api/v3/album/info?albumid=' + item.album_id,
method: 'GET',
transformResponse: undefined
}).then(function(response){
var data = response.data; data = JSON.parse(data);
track['album'] = data.status ? data.data.albumname : '';
});
hm({
url: target_url, method: 'GET', transformResponse: undefined
}).then(function(response){
var data = JSON.parse(response.data);
track['img_url'] = data.data.img;
});
tracks.push(track);
var tracks = [];
async_process_list(data.data.info, kg_render_artist_result_item, [hm, info], function(err, tracks){
return fn({"tracks":tracks, "info":info});
});
return fn({"tracks":tracks,"info": info});
});
});
}
Expand Down Expand Up @@ -236,6 +268,40 @@ var kugou = (function() {
};
}

function kg_render_album_result_item(index, item, params, callback){
var hm = params[0];
var info = params[1];
var album_id = params[2];
var track = {
'id': 'kgtrack_' + item.hash,
'title': '',
'artist': '',
'artist_id': '',
'album': info['title'],
'album_id': 'kgalbum_' + album_id,
'source': 'kugou',
'source_url': 'http://www.kugou.com/song/#hash='
+ item.hash + '&album_id=' + album_id,
'img_url': '',
'url': 'xmtrack_' + item.hash,
'lyric_url': item.hash
};
// Fix other data
var target_url = 'http://m.kugou.com/app/i/getSongInfo.php?'
+ 'cmd=playInfo&hash=' + item.hash;
hm({
url: target_url, method: 'GET', transformResponse: undefined
}).then(function(response){
var data = JSON.parse(response.data);
track['title'] = data.songName;
track['artist'] = data.singerId == 0 ?
'未知' : data.singerName;
track['artist_id'] = 'kgartist_' + data.singerId;
track['img_url'] = data.imgUrl.replace('{size}', '400');
callback(null, track);
});
}

var kg_album = function(url, hm, se) {
return {
success: function(fn) {
Expand All @@ -260,49 +326,21 @@ var kugou = (function() {
'source_url': 'http://www.kugou.com/album/{id}.html'
.replace('{id}', data.data.albumid)
};
});

target_url = 'http://mobilecdnbj.kugou.com/api/v3/album/song?'
target_url = 'http://mobilecdnbj.kugou.com/api/v3/album/song?'
+ 'albumid=' + album_id + '&page=1&pagesize=-1'
hm({
url: target_url,
method: 'GET',
transformResponse: undefined
}).then(function(response){
var data = response.data;
data = JSON.parse(data);
hm({
url: target_url,
method: 'GET',
transformResponse: undefined
}).then(function(response){
var data = response.data;
data = JSON.parse(data);

$.each(data.data.info, function(index, item){
var track = {
'id': 'kgtrack_' + item.hash,
'title': '',
'artist': '',
'artist_id': '',
'album': info['title'],
'album_id': 'kgalbum_' + album_id,
'source': 'kugou',
'source_url': 'http://www.kugou.com/song/#hash='
+ item.hash + '&album_id=' + album_id,
'img_url': '',
'url': 'xmtrack_' + item.hash,
'lyric_url': item.hash
};
// Fix other data
target_url = 'http://m.kugou.com/app/i/getSongInfo.php?'
+ 'cmd=playInfo&hash=' + item.hash;
hm({
url: target_url, method: 'GET', transformResponse: undefined
}).then(function(response){
var data = JSON.parse(response.data);
track['title'] = data.songName;
track['artist'] = data.singerId == 0 ?
'未知' : data.singerName;
track['artist_id'] = 'kgartist_' + data.singerId;
track['img_url'] = data.imgUrl.replace('{size}', '400');
async_process_list(data.data.info, kg_render_album_result_item, [hm, info, album_id], function(err, tracks){
return fn({"tracks":tracks, "info":info});
});
tracks.push(track);
});
return fn({"tracks": tracks,"info": info});
});
}
};
Expand Down
2 changes: 2 additions & 0 deletions js/vendor/async.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion listen1.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<script type="text/javascript" src="js/vendor/aes.js"></script>
<script type="text/javascript" src="js/vendor/bigint.js"></script>
<script type="text/javascript" src="js/vendor/timer.js"></script>
<script type="text/javascript" src="js/vendor/async.min.js"></script>

<script type="text/javascript" src="js/github_api.js"></script>
<script type="text/javascript" src="js/github.js"></script>
Expand Down Expand Up @@ -354,7 +355,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.7.0 (本软件基于MIT协议开源免费)</p>
<p> 当前版本 1.7.1 (本软件基于MIT协议开源免费)</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"manifest_version": 2,
"name": "Listen 1",
"permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "*://*.kugou.com/", "*://api.github.com/*", "*://github.com/*", "webRequest", "webRequestBlocking"],
"version": "1.7.0",
"version": "1.7.1",
"web_accessible_resources": [ "images/*" ],
"content_scripts": [{
"matches": ["https://listen1.github.io/listen1/*"],
Expand Down
Loading

0 comments on commit 0fa713d

Please sign in to comment.