Last active
October 25, 2024 19:29
-
-
Save XueshiQiao/858974dbf86bc91030fbf49f9c6daf43 to your computer and use it in GitHub Desktop.
导出网易云音乐歌单到 AppleMusic / Spotify 等平台
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 使用方法: | |
* 1. 用 Chrome 打开歌单的 web 页面(可以通过分享拿到链接,链接类似这样:http://music.163.com/playlist?id=xxx&userid=yyy) | |
* 2. 然后右键“检查”(如果有左上角有 device 选项,需要选择 Laptop 开头的,可以在 Edit/编辑 里添加,添加的时候注意 “User Agent string” 里选择 Desktop) | |
* 3. 在 console 里输入下面脚本,即可输出 “歌曲名 - 歌手名” 格式的内容: | |
Springsteen - Eric Church | |
Chattahoochee - Alan Jackson | |
Baby Now That I Found You - Alison Krauss | |
Check Yes or No - George Strait | |
Meanwhile Back At Mama's (feat. Faith Hill) - Tim McGraw/Faith Hill | |
。。 | |
* 4.通过 https://www.tunemymusic.com/zh-cn 导出到 Apple Music 或者 Spotify 等音乐平台 | |
*/ | |
// 原代码已失效,更新为评论区 @hellodk34 提供的代码,感谢 | |
(function () { | |
function getSinger(trNode) { | |
return trNode.getElementsByClassName("text")[0].title; | |
} | |
function getSongName(trNode) { | |
return trNode.getElementsByTagName("b")[0].title; | |
} | |
let allSongsTRNode = document.querySelectorAll('table.m-table > tbody > tr') | |
var songsStr = ""; | |
allSongsTRNode.forEach(songTR => { | |
songsStr += (getSongName(songTR) + " - " + getSinger(songTR)); | |
songsStr += "\n"; | |
}); | |
console.log(songsStr); | |
})(); |
@gannan123 我这测试自定义一个是可以的,但是"Use agent string” 那里默认是 Mobile,要改为 Desktop.
比较诡异,在界面等待曲目加载完成再输入得到的是undefined,等待十分钟之后相同代码得到了正确结果。
补充了正确替换空格的操作。
(function () {
function getSinger(trNode) {
return trNode.getElementsByClassName("text")[0].title.replace(/\u00A0/g, " ");
}
function getSongName(trNode) {
return trNode.getElementsByTagName("b")[0].title.replace(/\u00A0/g, " ");
}
function getAlbumName(trNode) {
return trNode.getElementsByTagName("td")[4].getElementsByTagName("a")[0].title.replace(/\u00A0/g, " ");
}
let allSongsTRNode = document.querySelectorAll('table.m-table > tbody > tr');
var songsStr = "";
allSongsTRNode.forEach(songTR => {
songsStr += (getSongName(songTR) + " - " + getSinger(songTR) + " - " + getAlbumName(songTR));
songsStr += "\n";
});
console.log(songsStr);
})();
// 获取包含所有歌曲信息的 tbody 元素
const tbody = document.querySelector('tbody');
// 存储歌曲信息的数组
const songs = [];
// 遍历 tbody 中的每一行
tbody.querySelectorAll('tr').forEach(row => {
// 获取歌曲名
const songTitle = row.querySelector('td:nth-child(2) b').getAttribute('title');
// 获取歌手名
const artistName = row.querySelector('td:nth-child(4) div').getAttribute('title');
// 将格式化的“歌手 - 歌曲名”字符串加入数组
if (songTitle && artistName) {
songs.push(`${artistName} - ${songTitle}`);
}
});
// 将所有歌曲信息输出,每行一对数据
console.log(songs.join('\n'));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我发现我的电脑没有预设的laptop....全是手机,然后我自己自定义了一个也不行,没有输出。