197 lines
5.2 KiB
JavaScript
197 lines
5.2 KiB
JavaScript
const { SourceModel } = require('../model/SourceModel');
|
|
|
|
const exts = ['mp3', 'acc', 'aiff', 'ape', 'au', 'flac', 'm4a', 'mmf', 'opus', 'voc', 'wav', 'ogg', 'ra', 'dvf', 'taa', 'dsf', 'diff', 'dts', 'wma'];
|
|
function checkExtension(ext) {
|
|
if(exts.indexOf(ext) >= 0) {
|
|
return ext;
|
|
}
|
|
|
|
for(let i = 0; i < exts.length; i++) {
|
|
if(ext.indexOf('.'+exts[i]) >= 0) {
|
|
return exts[i];
|
|
}
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
class MyFreemp3Source extends SourceModel {
|
|
constructor() {
|
|
super();
|
|
this.type = '';
|
|
this.name = '';
|
|
}
|
|
|
|
getExtension(url) {
|
|
return url.toLowerCase();
|
|
}
|
|
|
|
async search(keywords) {
|
|
keywords = encodeURIComponent(keywords);
|
|
// POST请求
|
|
let options = {
|
|
url: `http://myfreemp3.sharerj.com/?name=${keywords}&type=${this.type}`,
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
//'Host': 'myfreemp3.sharerj.com',
|
|
//'Origin': 'http://myfreemp3.sharerj.com',
|
|
//'Referer': `http://myfreemp3.sharerj.com/?name=${keywords}&type=qq`,
|
|
//'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.183',
|
|
//'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
'X-Requested-With': 'XMLHttpRequest', //此行必须填写
|
|
//'Cookie': '__gads=ID=f167a79e430852c8-227b3bd2b6e70079:T=1690680059:RT=1690680059:S=ALNI_MZixvU2-9BVQv0qTuN2kVnZttuZIQ; __gpi=UID=00000d30f9e155c5:T=1690680059:RT=1690680059:S=ALNI_MZtwSz24f5LJ-tGCRKRuzz0AFH5rA'
|
|
},
|
|
json: true, //将body解析为json
|
|
body: `input=${keywords}&filter=name&type=${this.type}&page=1`
|
|
};
|
|
|
|
let result = await this.request(options);
|
|
if(result.data instanceof Array) {
|
|
result = result.data.map(item => {
|
|
return {
|
|
title: item.title,
|
|
author: item.author,
|
|
url: item.url,
|
|
link: item.link,
|
|
lrc: item.lrc,
|
|
pic: item.pic,
|
|
source_name: this.getName(),
|
|
extension: item.url ? checkExtension(this.getExtension(item.url)) : ''
|
|
}
|
|
});
|
|
}else {
|
|
result = result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
class MyFreemp3QQSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'qq';
|
|
this.name = "MyFreemp3_QQ";
|
|
}
|
|
|
|
getExtension(url) {
|
|
return url.split('?')[0].split('/').pop().split('.').pop().toLowerCase();
|
|
}
|
|
}
|
|
|
|
class MyFreemp3NeteaseSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'netease';
|
|
this.name = "MyFreemp3_网易";
|
|
}
|
|
|
|
getExtension(url) {
|
|
return url.split('.').pop().toLowerCase();
|
|
}
|
|
}
|
|
|
|
class MyFreemp3KugouSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'kugou';
|
|
this.name = "MyFreemp3_酷狗";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3KuwoSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'kuwo';
|
|
this.name = "MyFreemp3_酷我";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3QianqianSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'baidu';
|
|
this.name = "MyFreemp3_千千";
|
|
}
|
|
}
|
|
|
|
class MyFreemp31tingSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = '1ting';
|
|
this.name = "MyFreemp3_一听";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3MiguSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'migu';
|
|
this.name = "MyFreemp3_咪咕";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3LizhiSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'lizhi';
|
|
this.name = "MyFreemp3_荔枝";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3QingtingSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'qingting';
|
|
this.name = "MyFreemp3_蜻蜓";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3XimalayaSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'ximalaya';
|
|
this.name = "MyFreemp3_喜马拉雅";
|
|
}
|
|
}
|
|
|
|
class MyFreemp35singycSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = '5singyc';
|
|
this.name = "MyFreemp3_5sing原创";
|
|
}
|
|
}
|
|
|
|
class MyFreemp35singfcSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = '5singfc';
|
|
this.name = "MyFreemp3_5sing翻唱";
|
|
}
|
|
}
|
|
|
|
class MyFreemp3KgSource extends MyFreemp3Source {
|
|
constructor() {
|
|
super();
|
|
this.type = 'kg';
|
|
this.name = "MyFreemp3_全民K歌";
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
MyFreemp3QQSource,
|
|
MyFreemp3NeteaseSource,
|
|
MyFreemp3KugouSource,
|
|
MyFreemp3KuwoSource,
|
|
MyFreemp3QianqianSource,
|
|
MyFreemp31tingSource,
|
|
MyFreemp3MiguSource,
|
|
MyFreemp3LizhiSource,
|
|
MyFreemp3QingtingSource,
|
|
MyFreemp3XimalayaSource,
|
|
MyFreemp35singycSource,
|
|
MyFreemp35singfcSource,
|
|
MyFreemp3KgSource
|
|
} |