From c2bf1b8f5a99e4a9db4e30d8f848c1f0ce0d10a8 Mon Sep 17 00:00:00 2001 From: amuliang <982632988@qq.com> Date: Wed, 2 Aug 2023 23:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=BC=E5=BC=8F=E8=AF=86?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.js | 4 ++-- app/source/MyFreemp3Source.js | 34 +++++++++++++++++++++++++++++++--- html/index.html | 22 +++++++++++++++------- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/app/main.js b/app/main.js index f609c4e..8dbb596 100644 --- a/app/main.js +++ b/app/main.js @@ -27,8 +27,8 @@ searcher.registerSourceModel(new mfm.MyFreemp3XimalayaSource()); searcher.registerSourceModel(new mfm.MyFreemp3LizhiSource()); searcher.registerSourceModel(new mfm.MyFreemp3KgSource()); searcher.registerSourceModel(new mfm.MyFreemp31tingSource()); -searcher.registerSourceModel(new mfm.MyFreemp35singycSource()); -searcher.registerSourceModel(new mfm.MyFreemp35singfcSource()); +// searcher.registerSourceModel(new mfm.MyFreemp35singycSource()); +// searcher.registerSourceModel(new mfm.MyFreemp35singfcSource()); // *********************************************************************** diff --git a/app/source/MyFreemp3Source.js b/app/source/MyFreemp3Source.js index d08ef8f..23ca344 100644 --- a/app/source/MyFreemp3Source.js +++ b/app/source/MyFreemp3Source.js @@ -1,10 +1,29 @@ 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 = 'qq'; - this.name = "MyFreemp3_QQ"; + this.type = ''; + this.name = ''; + } + + getExtension(url) { + return url.toLowerCase(); } async search(keywords) { @@ -37,7 +56,8 @@ class MyFreemp3Source extends SourceModel { link: item.link, lrc: item.lrc, pic: item.pic, - source_name: this.getName() + source_name: this.getName(), + extension: item.url ? checkExtension(this.getExtension(item.url)) : '' } }); }else { @@ -54,6 +74,10 @@ class MyFreemp3QQSource extends MyFreemp3Source { this.type = 'qq'; this.name = "MyFreemp3_QQ"; } + + getExtension(url) { + return url.split('?')[0].split('/').pop().split('.').pop().toLowerCase(); + } } class MyFreemp3NeteaseSource extends MyFreemp3Source { @@ -62,6 +86,10 @@ class MyFreemp3NeteaseSource extends MyFreemp3Source { this.type = 'netease'; this.name = "MyFreemp3_网易"; } + + getExtension(url) { + return url.split('.').pop().toLowerCase(); + } } class MyFreemp3KugouSource extends MyFreemp3Source { diff --git a/html/index.html b/html/index.html index 89b12de..6b51b41 100644 --- a/html/index.html +++ b/html/index.html @@ -31,7 +31,7 @@
- {{ item }} + {{ item }}
@@ -63,7 +63,8 @@ 链接: - 下载歌曲 + 下载歌曲 + 下载歌曲 源链接 @@ -105,7 +106,7 @@

{{ item2.title }}

{{ item2.author }}

-

{{ item2.source_name }}

+

{{ item2.extension || '未知格式' }}{{ item2.source_name }}

@@ -121,8 +122,8 @@ el: "#app", data() { const ajax = axios.create({ - baseURL: 'http://www.amuliang.top:5750', - //baseURL: 'http://localhost:5000', + //baseURL: 'http://www.amuliang.top:5750', + baseURL: 'http://localhost:5000', timeout: 10000, headers: { 'Content-Type': 'application/x-www-form-urlencoded', @@ -190,7 +191,6 @@ let list = await this.search(selected_sources[i], keywords, result); list.forEach(item => { item.number = i; //主要用来打标记 - item.extension = getExtension(item.url); result.push(item); }); } @@ -228,6 +228,10 @@ handleStore() { this.is_storing = true; this.store_message = ''; + if(getSelection(this.renderedStorePath) == '') { + this.$Message.error("请指定有效歌曲后缀名"); + return; + } this.get('/api/store', { music_path: this.renderedStorePath, music_url: this.current_item.url, @@ -249,6 +253,10 @@ this.is_searching = true; this.get('/api/source/all').then(response => { this.sources = response.data.data; + if(this.sources.length > 0) { + // 默认选中第一个 + this.selected_sources = [this.sources[0]]; + } this.is_searching = false; }).catch(err => { this.$Message.error(err.message); @@ -273,7 +281,7 @@ } 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']; if(exts.indexOf(ext) >= 0) { return ext;