几个常用音乐平台专辑曲目列表生成 Grab song list information from some websites
当前为
// ==UserScript==
// @name XMwiki专辑曲目列表生成
// @version 1.4.1
// @description 几个常用音乐平台专辑曲目列表生成 Grab song list information from some websites
// @author XMAnon
// @icon https://s1.ax1x.com/2020/07/15/UabtVe.jpg
// @match *://www.amazon.com/*
// @match *://www.amazon.de/*
// @match *://www.amazon.fr/*
// @match *://www.amazon.it/*
// @match *://www.amazon.es/*
// @match *://music.apple.com/*
// @match *://open.spotify.com/*
// the script is mostly inspired by Jeffrey.Deng(https://greasyfork.org/users/129338)复制spotify歌曲名脚本
// Grabbing Info from other sites is almost similar.
// 音乐平台抓取歌曲列表,并生成符合XM格式的歌曲列表(页面2)
// Supported:
// Spotify Album,
// Amazon Free Streaming and MP3 Site (tested on US/DE, other Countries should also work) may not working properly after amazon website update
// Apple Music
// To be done:
// Multiple CD case, Bandcamp, MusicBrainz
//
// @namespace https://greasyfork.org/users/666548
// ==/UserScript==
(function() {
'use strict';
// Your code here...
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
// IE specific code path to prevent textarea being shown while dialog is visible.
return clipboardData.setData("Text", text);
} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed";// Prevent scrolling to bottom of page in MS Edge.
document.body.appendChild(textarea);
textarea.select();
try {
return document.execCommand("copy");// Security exception may be thrown by some browsers.
} catch (ex) {
console.warn("Copy to clipboard failed.", ex);
return false;
} finally {
document.body.removeChild(textarea);
}
}
}
var song = function(_title, _artist) {
this.title = _title;
this.artist = _artist.replace(/ & | feat. |, /gm,';');
};
//***************************************** Spotify *********************************************************************
var getSpotify = function() {
var nodes = document.querySelector('#main .tracklist-container .tracklist').childNodes;//querySelectorAll("div > li > div.tracklist-col.name > div > div");
if (!nodes) {
console.warn("Songs nodes not found!!");
return;
}
var playList = [];
var len = nodes.length;
var charList = '';
for (var i = 0; i < len; i += 1) {
var one = new song(nodes[i].querySelector(".tracklist-name").innerText, nodes[i].querySelector(".second-line .ellipsis-one-line").innerText);
playList.push(one);
charList = charList + one.title + '【歌手】' + one.artist + '\n';
}
copyToClipboard(charList);
}
unsafeWindow.getSpotify = getSpotify;
//***************************************** Amazon *********************************************************************
var getAmazon = function(){//Amazon新的流媒体页面没有曲目艺人信息了所以就只抓取了曲目列表 2020.08
//var nodes = document.querySelector("#dmusic_tracklist_content > tbody").getElementsByClassName('a-text-left a-align-center darkenOnHover');//tested on 'amazon.de' unlimited stream page, but now without artists name
var nodes = document.querySelector("#dmusic_tracklist_content > tbody").childNodes;//tested on 'amazon.de' unlimited stream page, but now without artists name
//var headerNode = document.getElementById('dmusic_tracklist_header_box');
var len = nodes.length;
if (!nodes) {
console.warn("nodes not found");
return;}
// else if (len === 0){
// nodes = [headerNode.nextSibling.nextSibling]; //Special Case when it's EP
// len = 1;
// }
var playList = [];
var albumArtist = document.getElementById("ProductInfoArtistLink").innerText;
var charList = '';
for (var i = 0; i < len; i += 2) {
//var rawList = (nodes[i].innerText.split('\t'));
var title = (nodes[i].querySelector(".TitleLink").innerText);
//rawList = rawList.filter(function(e){return e.replace(/\t/gm,"")});
//var one = new song(rawList[1], rawList[2].replace(/ & /gm,';').replace(' feat. ',';').replace(/, /gm,';'));
//var one = new song(rawList[1]);
var one = new song(title,'');
// switch(0){
// case(one.artist.indexOf('\t')):
// one.artist = albumArtist;
// break;
// case(one.artist.indexOf('de ')):
// case(one.artist.indexOf('di ')):
// case(one.artist.indexOf('by ')):
// one.artist = one.artist.substring(3);
// break;
// case(one.artist.indexOf('von ')):
// one.artist = one.artist.substring(4);
// break;
// }
//console.log(rawList);
//console.log(one);
playList.push(one);
//charList = charList + one.title + '【歌手】'+ one.artist + '\n';
charList = charList + one.title + '\n';
}
copyToClipboard(charList);
}
unsafeWindow.getAmazon = getAmazon;
//var getBandCamp = function(){}
//var getMusicBrain = function(){}
// var getDiscogs = function(){//Discogs格式太乱了,情况太多了,写好了三种的,不好用先注释掉了。。。。
// var nodes = document.querySelector("#tracklist > div > table > tbody").querySelectorAll("tr");//[0].innerText;
// var len = nodes.length;
// if (!nodes) {
// console.warn("nodes not found");
// return;}
// var playList = [];
// var albumArtist = document.getElementById("profile_title").innerText.split(' – ')[0].replace(/ & | feat. |, | And /gm,';').replace(/\*/gm,'');
// var song = function(_title,_artist) {
// this.title = _title;
// this.artist = _artist;
// };
// var charList = '';
// for (var i = 0; i < len; i += 1) {
// var rawList = (nodes[i].innerText.replace('\n–\n','').split('\t'));
// rawList = rawList.filter(function(e){return e.replace(/\n/gm,'')});
// var lenElement = rawList.length;
// var one;
// switch(lenElement){
// case(4):
// one = new song(rawList[2], rawList[1].replace(/ & | feat. |, | And /gm,';').replace(/\*/gm,''));
// break;
// case(3):
// case(2):
// one = new song(rawList[lenElement - 2], albumArtist);
// break;
// }
// ;
// console.log(rawList);
// console.log(one);
// playList.push(one);
// charList = charList + one.title + '【歌手】'+ one.artist + '\n';
// }
// copyToClipboard(charList);
// }
// unsafeWindow.getDiscogs = getDiscogs;
//*********************************************************************************************************************
//***************************************** Spotify *********************************************************************
var getApple = function() {
var nodes = document.querySelector('#ember14 .header-and-songs-list .songs-list').querySelectorAll(".song");
if (!nodes) {
console.warn("Songs nodes not found!!");
return;
}
var albumArtist = document.querySelector("#ember14 .product-creator").innerText.replace(/ & | feat. /gm,';');
var playList = [];
var len = nodes.length;
var charList = '';
var artist = '';
for (var i = 0; i < len; i += 1) {
var title = nodes[i].querySelector(".song-name-wrapper .song-name").innerText;
if (!nodes[i].querySelector(".song-name-wrapper .by-line")){
artist = albumArtist;
}
else{
artist = nodes[i].querySelector(".song-name-wrapper .by-line").innerText}
var one = new song(title, artist);
playList.push(one);
charList = charList + one.title + '【歌手】' + one.artist + '\n';
}
copyToClipboard(charList);
}
unsafeWindow.getApple = getApple;
window.onload = function checkSrc() {//Check data source, add a button
var newBtn = document.createElement("input");
newBtn.type = "button";
newBtn.value = "虾抓";
newBtn.title = "Click to copy the song lists";
var currentUrl = window.location.href;
switch(true){
case (currentUrl.indexOf('open.spotify.com') > -1):
newBtn.onclick = getSpotify;
newBtn.style.backgroundColor = 'black';
var likeBtn_Spotify = document.querySelector("#main .main-view-container .spoticon-heart-32").parentNode.parentNode; //Button near the heart button
likeBtn_Spotify.appendChild(newBtn);
break;
case (currentUrl.indexOf('www.amazon') > -1):
newBtn.onclick = getAmazon;
newBtn.style.backgroundColor = 'orange';
var headerBox_Amzon = document.getElementById("dmusicProductTitle_feature_div"); //Button under the album title
headerBox_Amzon.appendChild(newBtn);
break;
case (currentUrl.indexOf('music.apple.com') > -1):
newBtn.onclick = getApple;
newBtn.style.backgroundColor = 'white';
var header_Apple = document.querySelector("#ember14 .album-header-metadata"); //Button under the album title
header_Apple.appendChild(newBtn);
break;
//case (currentUrl.indexOf('bandcamp') > -1):
// case (currentUrl.indexOf('discogs.com') > -1):
// newBtn.onclick = getDiscogs;
// newBtn.style.backgroundColor = 'white';
// var title_Discogs = document.getElementById("profile_title"); //Button near the title
// title_Discogs.appendChild(newBtn);
//break;
default:
console.warn('Host not matching');
}
}
})();