feat: 新增AM解析

解析需要阅读文档
This commit is contained in:
zhiyu 2024-05-11 11:49:42 +08:00
parent 5a56db1f4a
commit df2fe92916
6 changed files with 120 additions and 29 deletions

View File

@ -79,6 +79,16 @@ chmod a+rx ~/.local/bin/yt-dlp
sudo pacman -Syu yt-dlp
```
`AM解析`需要使用两个依赖`freyr``atomicparsley`现在只以Debian系统为例
```shell
npm install -g freyr
# 或者你有yarn的话可以使用
yarn global add freyr
# 接着安装它的依赖
apt-get install atomicparsley
```
4. 【可选】小程序解析适配了:
* 喵崽:[Yoimiya / Miao-Yunzai](https://gitee.com/yoimiya-kokomi/Miao-Yunzai)
* TRSS[时雨◎星空 / Yunzai](https://gitee.com/TimeRainStarSky/Yunzai)
@ -102,8 +112,8 @@ sudo pacman -Syu yt-dlp
```shell
# 删除当前的R插件
rm -rf ./plugins/rconsole-plugin/
# 克隆指定版本的R插件
git clone -b 1.5.1 https://gitee.com/kyrzy0416/rconsole-plugin.git
# 克隆指定版本的R插件稳定版本
git clone -b 1.6.7-lts https://gitee.com/kyrzy0416/rconsole-plugin.git
```
## 🐤 Q&A
@ -152,7 +162,7 @@ git clone -b 1.5.1 https://gitee.com/kyrzy0416/rconsole-plugin.git
1. 配置文件,将拉格朗日的配置文件`appsettings.json``Implementations`加入一个正向连接`ForwardWebSocket`
最好是9091这样就不用改tools配置文件
```json
```yaml
"Implementations": [
{
"Type": "ReverseWebSocket",
@ -233,6 +243,7 @@ git clone -b 1.5.1 https://gitee.com/kyrzy0416/rconsole-plugin.git
🌸 感谢以下框架的开源:
- [yt-dlp:A youtube-dl fork with additional features and fixes](https://github.com/yt-dlp/yt-dlp)
- [freyr-js](https://github.com/miraclx/freyr-js)
## ☕ 请我喝一杯瑞幸咖啡
如果你觉得插件能帮助到你增进好友关系,那么你可以在有条件的情况下[请我喝一杯瑞幸咖啡](https://afdian.net/a/zhiyu1998),这是我开源这个插件的最大动力!

View File

@ -8,7 +8,7 @@ import _ from "lodash";
import tunnel from "tunnel";
import HttpProxyAgent from "https-proxy-agent";
import { exec, execSync } from "child_process";
import { checkAndRemoveFile, mkdirIfNotExists } from "../utils/file.js";
import { checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists } from "../utils/file.js";
import {
downloadBFile,
getBiliAudio,
@ -67,8 +67,14 @@ import { getDS } from "../utils/mihoyo.js";
import GeneralLinkAdapter from "../utils/general-link-adapter.js";
import { mid2id } from "../utils/weibo.js";
import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
import path from "path";
export class tools extends plugin {
/**
* 用于计数applemusic达到一定数量清理文件
* @type {number}
*/
static #amCount = 0;
/**
* 构造安全的命令
* @type {{existsPromptKey: string, existsTransKey: string}}
@ -161,6 +167,10 @@ export class tools extends plugin {
{
reg: "share.xiaochuankeji.cn",
fnc: "zuiyou"
},
{
reg: "music.apple.com",
fnc: "applemusic"
}
],
});
@ -1432,6 +1442,77 @@ export class tools extends plugin {
}
}
async applemusic(e) {
// https://music.apple.com/cn/album/hectopascal-from-yagate-kimi-ni-naru-piano-arrangement/1468323115?i=1468323724
// 过滤参数
const message = e.msg.replace("&ls", "");
// 找到R插件保存目录
const currentWorkingDirectory = path.resolve(this.defaultPath);
// 如果没有文件夹就创建一个
await mkdirIfNotExists(currentWorkingDirectory + "/am")
// 执行命令
const result = await execSync(`freyr -d ${ currentWorkingDirectory } get ${ message }`);
logger.info(result.toString());
// 获取信息
const { title, album, artist } = await this.parseFreyrLog(result.toString());
e.reply(`识别Apple Music${ title }--${ artist }\n${ album }`);
// 检查目录是否存在
const musicPath = currentWorkingDirectory + "/am/" + artist + "/" + album;
const that = this;
// 找到音频文件
if (fs.existsSync(musicPath)) {
logger.info('目录存在。正在获取.m4a文件...');
// 读取目录中的所有文件和文件夹
fs.readdir(musicPath, (err, files) => {
if (err) {
e.reply("Apple Music解析出错请查看日志")
logger.error('读取目录时出错:', err);
return;
}
// 过滤出以.m4a结尾的文件
const m4aFiles = files.filter(file => path.extname(file).toLowerCase() === '.m4a');
// 打印出所有.m4a文件
logger.info('找到以下.m4a文件:');
m4aFiles.forEach(file => {
that.uploadGroupFile(e, path.join(musicPath, file));
});
});
} else {
e.reply("下载失败没有找到Apple Music下载下来文件");
}
// 计数
tools.#amCount += 1;
logger.info(`当前Apple Music已经下载了${ tools.#amCount }`);
// 定时清理
if (tools.#amCount >= 5) {
await deleteFolderRecursive(currentWorkingDirectory + "/am");
// 重置
tools.#amCount = 0;
}
return true;
}
/**
* 用于Apple Music抓取部分信息的函数
* @link {applemusic}
* @param log
* @returns {Promise<{artist: (*|string), album: (*|string), title: (*|string)}>}
*/
async parseFreyrLog(log) {
const titleMatch = log.match(/Title: (.*)/);
const albumMatch = log.match(/Album: (.*)/);
const artistMatch = log.match(/Artist: (.*)/);
const title = titleMatch ? titleMatch[1] : 'N/A';
const album = albumMatch ? albumMatch[1] : 'N/A';
const artist = artistMatch ? artistMatch[1] : 'N/A';
return { title, album, artist };
}
/**
* 哔哩哔哩下载
* @param title

View File

@ -39,11 +39,11 @@
title: "bilibili/b23"
desc: 哔哩哔哩分享实时下载
- icon: bqrcode
title: "R插件B站扫码"
title: "#rbq/#RBQ"
desc: R插件B站扫码
- icon: bilimusic
title: "bili音乐+链接"
desc: 哔哩哔哩音乐分享实时下载
- icon: applemusic
title: "Apple Music"
desc: Apple Music音乐分享实时下载
- icon: youtube
title: "youtube.com"
desc: 油管学习版分享实时下载

View File

@ -1,11 +1,10 @@
- {
version: 1.7.0,
version: 1.7.1,
data:
[
新增<span class="cmd">适配拉格朗日上传</span>功能,
新增<span class="cmd">AM解析</span>功能,
适配<span class="cmd">拉格朗日上传</span>功能,
新增<span class="cmd">超过文件大小转上传</span>功能,
新增<span class="cmd">B站下载</span>功能,
新增<span class="cmd">B站扫码</span>功能,
支持<span class="cmd">锅巴</span>插件,方便查看和修改配置,
添加<span class="cmd">#R帮助</span>获取插件帮助,
添加<span class="cmd">#R版本</span>获取插件版本,

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB