优化格式识别

main
amuliang 2023-08-02 23:58:47 +08:00
parent 336108efb7
commit c2bf1b8f5a
3 changed files with 48 additions and 12 deletions

View File

@ -27,8 +27,8 @@ searcher.registerSourceModel(new mfm.MyFreemp3XimalayaSource());
searcher.registerSourceModel(new mfm.MyFreemp3LizhiSource()); searcher.registerSourceModel(new mfm.MyFreemp3LizhiSource());
searcher.registerSourceModel(new mfm.MyFreemp3KgSource()); searcher.registerSourceModel(new mfm.MyFreemp3KgSource());
searcher.registerSourceModel(new mfm.MyFreemp31tingSource()); searcher.registerSourceModel(new mfm.MyFreemp31tingSource());
searcher.registerSourceModel(new mfm.MyFreemp35singycSource()); // searcher.registerSourceModel(new mfm.MyFreemp35singycSource());
searcher.registerSourceModel(new mfm.MyFreemp35singfcSource()); // searcher.registerSourceModel(new mfm.MyFreemp35singfcSource());
// *********************************************************************** // ***********************************************************************

View File

@ -1,10 +1,29 @@
const { SourceModel } = require('../model/SourceModel'); 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 { class MyFreemp3Source extends SourceModel {
constructor() { constructor() {
super(); super();
this.type = 'qq'; this.type = '';
this.name = "MyFreemp3_QQ"; this.name = '';
}
getExtension(url) {
return url.toLowerCase();
} }
async search(keywords) { async search(keywords) {
@ -37,7 +56,8 @@ class MyFreemp3Source extends SourceModel {
link: item.link, link: item.link,
lrc: item.lrc, lrc: item.lrc,
pic: item.pic, pic: item.pic,
source_name: this.getName() source_name: this.getName(),
extension: item.url ? checkExtension(this.getExtension(item.url)) : ''
} }
}); });
}else { }else {
@ -54,6 +74,10 @@ class MyFreemp3QQSource extends MyFreemp3Source {
this.type = 'qq'; this.type = 'qq';
this.name = "MyFreemp3_QQ"; this.name = "MyFreemp3_QQ";
} }
getExtension(url) {
return url.split('?')[0].split('/').pop().split('.').pop().toLowerCase();
}
} }
class MyFreemp3NeteaseSource extends MyFreemp3Source { class MyFreemp3NeteaseSource extends MyFreemp3Source {
@ -62,6 +86,10 @@ class MyFreemp3NeteaseSource extends MyFreemp3Source {
this.type = 'netease'; this.type = 'netease';
this.name = "MyFreemp3_网易"; this.name = "MyFreemp3_网易";
} }
getExtension(url) {
return url.split('.').pop().toLowerCase();
}
} }
class MyFreemp3KugouSource extends MyFreemp3Source { class MyFreemp3KugouSource extends MyFreemp3Source {

View File

@ -31,7 +31,7 @@
<div style="margin: 10px 0"> <div style="margin: 10px 0">
<label>选择搜索源:</label> <label>选择搜索源:</label>
<Checkbox-Group v-model="selected_sources" style="display: inline-block;"> <Checkbox-Group v-model="selected_sources" style="display: inline-block;">
<Checkbox v-for="item in sources" :label="item">{{ item }}</Checkbox> <Checkbox v-for="item in sources" :label="item" style="padding-right:15px;">{{ item }}</Checkbox>
</Checkbox-Group> </Checkbox-Group>
</div> </div>
<div style="margin: 10px 0"> <div style="margin: 10px 0">
@ -63,7 +63,8 @@
<Row style="vertical-align: middle; line-height: 32px;"> <Row style="vertical-align: middle; line-height: 32px;">
<i-col span="4">链接:</i-col> <i-col span="4">链接:</i-col>
<i-col span="20"> <i-col span="20">
<a :href="current_item.url" target="_blank" download="download" style="margin-right: 20px;">下载歌曲</a> <a v-if="current_item.url" :href="current_item.url" target="_blank" download="download" style="margin-right: 20px;">下载歌曲</a>
<span v-if="!current_item.url" style="margin-right: 20px;color:#aaa;">下载歌曲</span>
<a :href="current_item.link" target="_blank">源链接</a> <a :href="current_item.link" target="_blank">源链接</a>
</i-col> </i-col>
</Row> </Row>
@ -105,7 +106,7 @@
<i-col span="16"> <i-col span="16">
<p style="display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;" :title="item2.title">{{ item2.title }}</p> <p style="display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;" :title="item2.title">{{ item2.title }}</p>
<p style="color:#bbb">{{ item2.author }}</p> <p style="color:#bbb">{{ item2.author }}</p>
<p><Tag :color="['default','primary','success','error','warning','magenta','red','volcano','orange','gold','yellow'][item2.number%11]">{{ item2.source_name }}</Tag></p> <p><Tag>{{ item2.extension || '未知格式' }}</Tag><Tag :color="['default','primary','success','error','warning','magenta','red','volcano','orange','gold','yellow'][item2.number%11]">{{ item2.source_name }}</Tag></p>
</i-col> </i-col>
</Row> </Row>
</div> </div>
@ -121,8 +122,8 @@
el: "#app", el: "#app",
data() { data() {
const ajax = axios.create({ const ajax = axios.create({
baseURL: 'http://www.amuliang.top:5750', //baseURL: 'http://www.amuliang.top:5750',
//baseURL: 'http://localhost:5000', baseURL: 'http://localhost:5000',
timeout: 10000, timeout: 10000,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
@ -190,7 +191,6 @@
let list = await this.search(selected_sources[i], keywords, result); let list = await this.search(selected_sources[i], keywords, result);
list.forEach(item => { list.forEach(item => {
item.number = i; //主要用来打标记 item.number = i; //主要用来打标记
item.extension = getExtension(item.url);
result.push(item); result.push(item);
}); });
} }
@ -228,6 +228,10 @@
handleStore() { handleStore() {
this.is_storing = true; this.is_storing = true;
this.store_message = ''; this.store_message = '';
if(getSelection(this.renderedStorePath) == '') {
this.$Message.error("请指定有效歌曲后缀名");
return;
}
this.get('/api/store', { this.get('/api/store', {
music_path: this.renderedStorePath, music_path: this.renderedStorePath,
music_url: this.current_item.url, music_url: this.current_item.url,
@ -249,6 +253,10 @@
this.is_searching = true; this.is_searching = true;
this.get('/api/source/all').then(response => { this.get('/api/source/all').then(response => {
this.sources = response.data.data; this.sources = response.data.data;
if(this.sources.length > 0) {
// 默认选中第一个
this.selected_sources = [this.sources[0]];
}
this.is_searching = false; this.is_searching = false;
}).catch(err => { }).catch(err => {
this.$Message.error(err.message); this.$Message.error(err.message);
@ -273,7 +281,7 @@
} }
function getExtension(url) { function getExtension(url) {
var ext = url.split('?')[0].split('/').pop().split('.').pop().toLowerCase(); var ext = url.split('/').pop().split('.').pop().toLowerCase();
var exts = ['mp3', 'acc', 'aiff', 'ape', 'au', 'flac', 'm4a', 'mmf', 'opus', 'voc', 'wav', 'ogg', 'ra', 'dvf', 'taa', 'dsf', 'diff', 'dts', 'wma']; var exts = ['mp3', 'acc', 'aiff', 'ape', 'au', 'flac', 'm4a', 'mmf', 'opus', 'voc', 'wav', 'ogg', 'ra', 'dvf', 'taa', 'dsf', 'diff', 'dts', 'wma'];
if(exts.indexOf(ext) >= 0) { if(exts.indexOf(ext) >= 0) {
return ext; return ext;