获取豆瓣 FM 红心歌曲信息

新年第一篇。
把这个压了几个月的代码贴出来当作福利吧。
由于你懂的原因,本文以英文撰写。

00. songs on mobile
\Android\data\com.douban.radio\files\song\music

01. link of douban redheart
https://douban.fm/mine/?type=liked#!type=liked

02. embed and

var lo = document.createElement('script');
lo.src = 'https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js';
document.getElementsByTagName('head')[0].appendChild(lo);
var jq = document.createElement('script');
jq.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
document.getElementsByTagName('head')[0].appendChild(jq);

03. get basic info of redheart

var RED;
$.ajax({
    url: 'https://douban.fm/j/v2/redheart/basic',
    success: function(res){ RED = res }
})

04. get sid of songs

var SID = _.map(RED.songs, 'sid').join('|')

05. get full songs info

var FULL;
$.ajax({
    url: 'https://douban.fm/j/v2/redheart/songs',
    type: 'POST',
    data: {
        kbps: 192,
        ck: 'T4rh', //change according to RED
        sids: SID
    },
    success: function(res) { FULL = res }
})

06. get title and artist

var INFO = [];
_.each(FULL, function(o){
  INFO.push(_.pick(o, ['sid', 'title', 'artist', 'albumtitle']))
})
 
var LINK = _.map(FULL, function(o) { return o.url }) //you know what to do

07. extract info

$('body').append('<div>' + JSON.stringify(INFO) + '</div>')
 
$('body').append('<div>' + LINK.join('<br>') + '</div>')

08. rename with info
(bulk rename utility with suga.js)

var info = INFO;
for(var i = 0; i < info.length; i++){
  if(origName === info[i].sid){
    newName = (info[i].title + '@@' + info[i].artist + '##' + info[i].albumtitle + '##' + info[i].sid).replace(/[/:*\?"<>|]/g, '')
  }
}
newExt = 'mp3'

09. filename to tag
(mp3tag, id3v1)
%title%@@%artist%##%album%##%comment%

10. filename to filename
(mp3tag, may duplicated)
%1@@%2##%3##%4
%1-%2


sp1. info to sorted tags

var SORT = _.clone(INFO);
_.each(SORT, function(o, i){
    SORT[i].sid = parseInt(SORT[i].sid)
});
SORT = _.sortBy(SORT, 'sid');
 
var TAGS = _.map(SORT, function(o){
    return o.title + '    ' + o.artist + '    ' + o.albumtitle
});
 
$('body').append('<pre>' + TAGS.join('\n') + '</pre>');

sp2. get tag and filename
(mp3tags, txt file to tag)
%title% %artist% %album%

(mp3tags, tag to filename)
%title% - %artist%

发表评论

邮箱地址不会被公开。 必填项已用*标注