一键下载 MP3 至路由器 – UserScript 脚本 (也可用作书签工具)
8 月份折腾 极贰 时候写的,原文在 WP 博客有的,现在 不用 WP 复制一下,备忘,删除一些没用的 代码还可以一键下载 MP3 到本地
具体代码如下
下面是 在线的 MP3 搜索 下载 至路由器 Aria2 的页面
测试地址http://gouji.org/api/mp3/

具体代码如下
/** * 下载 百度 MP3 至路由器 UserScript 、 Bookmarklet 两用脚本 * Author: 简爱 * Mail: sc.419@qq.com * URL: http://gouji.org/ * Date: 20140828 * * 使用前需修改 * PATH 下载目录 * Aria2API aria2 地址 默认只修改 其中 IP 即可 * isTips 是否弹出确认提示 * 同时 按住 Ctrl 或 Alt 然后 鼠标单击歌曲 下载 至路由 * * 若果浏览器不支持 UserScript 可以尝试复制 下面内容在浏览器地址栏使用 */ javascript: (function() { var PATH = "/mnt/sda1/Downloads/mp3", Aria2API = "http://192.168.1.1:6800/jsonrpc", isTips = true; var SongLists = {}, API = "http://play.baidu.com/data/music/songlink?callback=?", songIdReg = /^\/song\/([0-9]*)/i, jaDownload = { /* 获取 歌曲信息 */ G: function (id){ if(SongLists[id] && SongLists[id].songLink){ jaDownload.D(SongLists[id].songLink, SongLists[id].songName +"-"+ SongLists[id].artistName +".mp3"); }else{ jaDownload.m(id +" 下载连接获取 ing ..."); $.getJSON(API, "songIds="+ id, function (j){ if(j.errorCode == 22000){ s = j.data.songList[0]; SongLists[id] = s; jaDownload.D(SongLists[id].songLink, SongLists[id].songName +"-"+ SongLists[id].artistName +".mp3"); } }); } }, /* 推送至 路由器 Aria2 */ D: function (url, name){ if(url == "") return; data = '[{"jsonrpc":"2.0","method":"aria2.addUri","id":1,"params":[["'+ encodeURI(url) +'"],{"out":"'+ name +'","dir":"'+ PATH +'","split":"5","max-connection-per-server":"1","seed-ratio":"1.0"}]}]'; Tips = "确定要下载 《"+ name +"》 ?"; jaDownload.m(Tips, "08d"); if(!isTips || confirm(Tips)){ jaDownload.m("下载:"+name); $.post(Aria2API, data, function(json){ jaDownload.m("Aria2 返回信息: "+ JSON.stringify(json), "08d"); }, "json"); }else{ jaDownload.m("《"+ name +"》 下载已取消 !", "f00"); } }, /* 显示日志 */ m: function (msg, c, s){ window.console && console.log("%c"+msg, "font-size:"+ (s ? s : 12) +"px; color:#"+ (c && c != "" ? c : "73BF00")); } } jaDownload.m("jaDownload 加载 OK 简爱 http://gouji.org/ 20140828 ", "f19", 19); $("a[sid], a[href*=song]").on("click", function(e){ if(!e.ctrlKey && !e.altKey) return true; id = $(this).attr("sid"); if(!id) id = $(this).attr("href").match(songIdReg)[1]; jaDownload.G(id); return false; }); })();
下面是 在线的 MP3 搜索 下载 至路由器 Aria2 的页面
测试地址http://gouji.org/api/mp3/

本文出自简爱博客,转载时请注明出处及相应链接。