Compare commits

..

No commits in common. "dev" and "ZonyLrcToolsX_Alpha.2022121355" have entirely different histories.

129 changed files with 7207 additions and 1455 deletions

View File

@ -17,10 +17,12 @@ jobs:
run: echo "::set-output name=date::$(date +'%Y%m%d')${{github.run_number}}"
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
submodules: true
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Publish
@ -36,7 +38,6 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
retention-days: 90
name: release-files
path: |
./TempFiles
@ -44,7 +45,6 @@ jobs:
outputs:
version: ${{ steps.date.outputs.date }}
release:
if: github.event_name == 'push'
needs: build
runs-on: ubuntu-latest
steps:

View File

@ -1,11 +0,0 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>4.0.2</Version>
<Authors>Zony(real-zony)</Authors>
<RepositoryUrl>https://github.com/real-zony/ZonyLrcToolsX</RepositoryUrl>
</PropertyGroup>
</Project>

View File

@ -1,45 +0,0 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageVersion Include="McMaster.Extensions.Hosting.CommandLine" Version="4.1.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="QRCoder" Version="1.6.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageVersion Include="Polly" Version="8.5.0" />
<PackageVersion Include="TagLibSharp" Version="2.3.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
<PackageVersion Include="MusicDecrypto.Library" Version="2.4.1" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.6" />
<PackageVersion Include="SuperSocket.WebSocket" Version="2.0.0-beta.11" />
<PackageVersion Include="SuperSocket.WebSocket.Server" Version="2.0.0-beta.11" />
<!-- Testing Projects -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<!-- Avalonia -->
<PackageVersion Include="Ude.NetStandard" Version="1.2.0" />
<PackageVersion Include="YamlDotNet" Version="16.2.0" />
</ItemGroup>
</Project>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

166
README.md
View File

@ -1,39 +1,161 @@
English | [简体中文](./zh_CN.md)
简体中文 | [English](./docs/en_US.md)
# Disclaimer
## 免责声明
- 本工具仅作个人学习研究使用,可运行的二进制文件仅用于演示功能,不得将源码及其产物用于商业用途,否则由此造成的相关法律问题,[本人](https://github.com/real-zony) 不承担任何法律责任。
- 任何单位或个人因下载使用软件所产生的任何意外、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带或衍生的损失等)[本人](https://github.com/real-zony) 不承担任何法律责任。
- 用户明确并同意本声明条款列举的全部内容,对使用本工具可能存在的风险和相关后果将完全由用户自行承担,[本人](https://github.com/real-zony) 不承担任何法律责任。
- This tool is for personal learning and research purposes only. The executable binary files are for demonstration purposes only and the source code and its products must not be used for commercial purposes. Otherwise, I [here](https://github.com/real-zony) will not be responsible for any related legal issues.
- Any unit or individual that downloads and uses the software resulting in any accidents, negligence, contract breaches, defamation, copyright or intellectual property infringement, and their resulting losses (including but not limited to direct, indirect, incidental or derivative losses), I [here](https://github.com/real-zony) will not bear any legal responsibility.
- Users clearly agree to all the terms listed in this statement and fully assume the risks and consequences of using this tool. I [here](https://github.com/real-zony) will not bear any legal responsibility.
## 简介
# Introduction
ZonyLrcToolX 4 是一个基于 CEF 的跨平台歌词下载工具。
ZonyLrcToolX 4 is a cross-platform lyrics download tool based on CEF. **QQ Group: 337656932**. Detailed video tutorials are available in the group files.
🚧 当前版本正在开发当中。
🚧 如果你想查看可以工作的代码,请切换到 dev 分支。
🚧 The current version is under development.
🚧 If you want to see working code, please switch to the dev branch.
## 下载
# Download
工具会执行每日构建动作,请访问 **[Release](https://github.com/real-zony/ZonyLrcToolsX/releases)** 页面进行下载。
To get the latest version, please visit the **[Release](https://github.com/real-zony/ZonyLrcToolsX/releases)** page for download.
## 用法
## Arch Linux User Repository
Windows 用户请在软件目录当中,按住 Shift + 右键呼出菜单,然后选择 PowerShell/命令提示符/Windows 终端,根据下述说明执行命令即可。
This software has been packaged into [AUR](https://aur.archlinux.org/packages/zonylrctoolsx-bin). Arch Linux and its derivative distribution users can install it with the following command:
macOS 和 Linux 用户请打开终端,切换到软件目录,一样执行命令即可。
```bash
# yay or other AUR Helpers
yay -S zonylrctoolsx-bin
### 子命令
ZonyLrcTools.Cli --help
#### 歌词下载
子命令为 `download`,可用于下载歌词数据和专辑图像,支持多个下载器进行下载。
```shell
.\ZonyLrcTools.Cli.exe download -d|dir <WAIT_SCAN_DIRECTORY> [-l|--lyric] [-a|--album] [-n|--number]
.\ZonyLrcTools.Cli.exe download -h|--help
```
# Usage
Detailed usage instructions have been moved to a new documentation site. Please visit [https://docs.myzony.com](https://docs.myzony.com) for complete documentation.
**例子**
# Donation
[爱发电](https://afdian.net/a/zony-lrc-tools)
```shell
# 下载歌词
.\ZonyLrcTools.Cli.exe download -d "C:\歌曲目录" -l -n 2
# Star History
# 下载专辑封面
.\ZonyLrcTools.Cli.exe download -d "C:\歌曲目录" -a -n 2
```
#### 加密格式转换
子命令为 `util`,可用于转换部分加密歌曲,**仅供个人研究学习使用,思路与源码都来自于网络**。
具体支持的格式请参考项目 [MusicDecrypto](https://github.com/davidxuang/MusicDecrypto/blob/master/MusicDecrypto.Library/DecryptoFactory.cs#L23),本工具仅做一个集成,替换掉原本自己的一些实现。现在不需要指定对应的类型参数,程序会自动根据文件后缀选择适合的解密算法。
命令只需要一个参数 `-s`,指定需要转换的文件夹或者是文件路径。
```shell
.\ZonyLrcTools.Cli.exe util -s D:\CloudMusic
```
### 配置文件
程序的所有的配置信息,都在 `config.yaml` 进行更改,下面标注了各个配置的说明。
其中是否开启的可选项为 `true` 或者 `false`,等同于中文的是和否。
```yaml
globalOption:
# 允许扫描的歌曲文件后缀名。
supportFileExtensions:
- '*.mp3'
- '*.flac'
- '*.wav'
# 网络代理服务设置,仅支持 HTTP 代理。
networkOptions:
isEnable: false # 是否启用代理。
ip: 127.0.0.1 # 代理服务 IP 地址。
port: 4780 # 代理服务端口号。
updateUrl: https://api.myzony.com/lrc-tools/update # 更新检查地址。
# 下载器的相关参数配置。
provider:
# 标签扫描器的相关参数配置。
tag:
# 支持的标签扫描器。
plugin:
- name: Taglib # 基于 Taglib 库的标签扫描器。
priority: 1 # 优先级,升序排列。
- name: FileName # 基于文件名的标签扫描器。
priority: 2
# 基于文件名扫描器的扩展参数。
extensions:
# 正则表达式,用于匹配文件名中的作者信息和歌曲信息,可根据
# 自己的需求进行调整。
regularExpressions: "(?'artist'.+)\\s-\\s(?'name'.+)"
# 歌曲标签屏蔽字典替换功能。
blockWord:
isEnable: false # 是否启用屏蔽字典。
filePath: 'BlockWords.json' # 屏蔽字典的路径。
# 歌词下载器的相关参数配置。
lyric:
# 支持的歌词下载器。
plugin:
- name: NetEase # 基于网易云音乐的歌词下载器。
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
depth: 10 # 搜索深度,值越大搜索结果越多,但搜索时间越长。
- name: QQ # 基于 QQ 音乐的歌词下载器。
priority: 2
# depth: 10 # 暂时不支持。
- name: KuGou # 基于酷狗音乐的歌词下载器。
priority: 3
depth: 10
- name: KuWo # 基于酷我音乐的歌词下载器。
priority: 4
depth: 10
# 歌词下载的一些共有配置参数。
config:
isOneLine: true # 双语歌词是否合并为一行展示。
lineBreak: "\n" # 换行符的类型,记得使用双引号指定。
isEnableTranslation: true # 是否启用翻译歌词。
isOnlyOutputTranslation: false # 是否只输出翻译歌词。
isSkipExistLyricFiles: false # 如果歌词文件已经存在,是否跳过这些文件。
fileEncoding: 'utf-8' # 歌词文件的编码格式。
```
#### 支持的编码格式
详细信息请参考: [MSDN Encoding 列表](https://learn.microsoft.com/en-us/dotnet/api/System.Text.Encoding.GetEncodings?view=net-6.0#examples),使用 `identifier and name` 作为参数值填入 `config.yaml` 文件当中的 `fileEncoding`
#### 支持的歌词源
| 歌词源 | 默认优先级 |
| ---------- | ---------- |
| 网易云音乐 | 1 |
| QQ 音乐 | 2 |
| 酷狗音乐 | 3 |
| 酷我音乐 | 4 |
### 屏蔽字典
屏蔽字典适用于网易云音乐歌词下载,针对某些单词,网易云音乐使用了 * 号进行屏蔽,这个时候可以使用屏蔽字典,设置歌曲名的关键词替换。例如有一首歌曲叫做 *Fucking ABC* ,这个时候网易云实际的名字是 *Fu****ing* ,用户只需要在屏蔽字典加入替换逻辑即可,例如:
```json
{
"Fuckking": "Fu****ing"
}
```
屏蔽字典默认路径为程序所在目录的 *BlockWords.json* 文件,用户可以在 *appsettings.json* 文件中配置其他路径。
## 捐赠
<img src="./docs/img/alipay.jpg" width="200"/><img src="./docs/img/wechat.jpg" width="200"/>
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=real-zony/ZonyLrcToolsX&type=Timeline)](https://star-history.com/#real-zony/ZonyLrcToolsX&Timeline)
## 路线图
- [x] 支持跨平台的 CLI 工具。
- [x] 基于 Web GUI 的操作站点。
- [ ] 支持插件系统(Lua 引擎)。

View File

@ -11,8 +11,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Cli", "src\Zon
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Tests", "tests\ZonyLrcTools.Tests\ZonyLrcTools.Tests.csproj", "{FFBD3200-568F-455B-8390-5E76C51D522C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.LocalServer", "src\ZonyLrcTools.LocalServer\ZonyLrcTools.LocalServer.csproj", "{2875A08A-FFD6-4863-B815-5384DCFE88FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Common", "src\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj", "{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "vendor", "vendor", "{AB0E3F21-DDBF-459D-995C-04C177BF8995}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MusicDecrypto.Library", "vendor\MusicDecrypto\MusicDecrypto.Library\MusicDecrypto.Library.csproj", "{6BB67593-38CD-42E4-8409-EDAC3C138A6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,10 +33,18 @@ Global
{FFBD3200-568F-455B-8390-5E76C51D522C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFBD3200-568F-455B-8390-5E76C51D522C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFBD3200-568F-455B-8390-5E76C51D522C}.Release|Any CPU.Build.0 = Release|Any CPU
{2875A08A-FFD6-4863-B815-5384DCFE88FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2875A08A-FFD6-4863-B815-5384DCFE88FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2875A08A-FFD6-4863-B815-5384DCFE88FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2875A08A-FFD6-4863-B815-5384DCFE88FC}.Release|Any CPU.Build.0 = Release|Any CPU
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.Build.0 = Release|Any CPU
{6BB67593-38CD-42E4-8409-EDAC3C138A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BB67593-38CD-42E4-8409-EDAC3C138A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BB67593-38CD-42E4-8409-EDAC3C138A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BB67593-38CD-42E4-8409-EDAC3C138A6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -41,6 +55,8 @@ Global
GlobalSection(NestedProjects) = preSolution
{55D74323-ABFA-4A73-A3BF-F3E8D5DE6DE8} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
{FFBD3200-568F-455B-8390-5E76C51D522C} = {AF8ADB2F-E46C-4DEE-8316-652D9FE1A69B}
{2875A08A-FFD6-4863-B815-5384DCFE88FC} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
{6BB67593-38CD-42E4-8409-EDAC3C138A6B} = {AB0E3F21-DDBF-459D-995C-04C177BF8995}
EndGlobalSection
EndGlobal

View File

@ -1,3 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QQ/@EntryIndexedValue">QQ</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Zony/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,39 +1,18 @@
English | [简体中文](./zh_CN.md)
# Disclaimer
## Overview
- This tool is for personal learning and research purposes only. The executable binary files are for demonstration purposes only and the source code and its products must not be used for commercial purposes. Otherwise, I [here](https://github.com/real-zony) will not be responsible for any related legal issues.
- Any unit or individual that downloads and uses the software resulting in any accidents, negligence, contract breaches, defamation, copyright or intellectual property infringement, and their resulting losses (including but not limited to direct, indirect, incidental or derivative losses), I [here](https://github.com/real-zony) will not bear any legal responsibility.
- Users clearly agree to all the terms listed in this statement and fully assume the risks and consequences of using this tool. I [here](https://github.com/real-zony) will not bear any legal responsibility.
ZonyLrcToolX 2.0 is a cross-platform lyric downlaod tool based on CEF.
# Introduction
🚧 The current version is under development.
🚧 If you want to see the working code, please switch to the 1.0 branch.
ZonyLrcToolX 4 is a cross-platform lyrics download tool based on CEF. **QQ Group: 337656932**. Detailed video tutorials are available in the group files.
## Usage
🚧 The current version is under development.
🚧 If you want to see working code, please switch to the dev branch.
## Donation
# Download
## Roadmap
To get the latest version, please visit the **[Release](https://github.com/real-zony/ZonyLrcToolsX/releases)** page for download.
## Arch Linux User Repository
This software has been packaged into [AUR](https://aur.archlinux.org/packages/zonylrctoolsx-bin). Arch Linux and its derivative distribution users can install it with the following command:
```bash
# yay or other AUR Helpers
yay -S zonylrctoolsx-bin
ZonyLrcTools.Cli --help
```
# Usage
Detailed usage instructions have been moved to a new documentation site. Please visit [https://docs.myzony.com](https://docs.myzony.com) for complete documentation.
# Donation
[爱发电](https://afdian.net/a/zony-lrc-tools)
# Star History
[![Star History Chart](https://api.star-history.com/svg?repos=real-zony/ZonyLrcToolsX&type=Timeline)](https://star-history.com/#real-zony/ZonyLrcToolsX&Timeline)
- [ ] Supports cross-platform CLI tools.
- [ ] Web GUI based site (local).
- [ ] Support plug-in system (Lua Engine).

BIN
docs/img/alipay.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

BIN
docs/img/wechat.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

View File

@ -1,40 +0,0 @@
简体中文 | [English](./docs/en_US.md)
# 免责声明
- 本工具仅作个人学习研究使用,可运行的二进制文件仅用于演示功能,不得将源码及其产物用于商业用途,否则由此造成的相关法律问题,[本人](https://github.com/real-zony) 不承担任何法律责任。
- 任何单位或个人因下载使用软件所产生的任何意外、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带或衍生的损失等)[本人](https://github.com/real-zony) 不承担任何法律责任。
- 用户明确并同意本声明条款列举的全部内容,对使用本工具可能存在的风险和相关后果将完全由用户自行承担,[本人](https://github.com/real-zony) 不承担任何法律责任。
# 简介
ZonyLrcToolX 4 是一个基于 CEF 的跨平台歌词下载工具,**QQ 群:337656932**,群文件里面有详细的视频教程。
🚧 当前版本正在开发当中。
🚧 如果你想查看可以工作的代码,请切换到 dev 分支。
# 下载
如果你要获取最新版本,请访问 **[Release](https://github.com/real-zony/ZonyLrcToolsX/releases)** 页面进行下载。
## Arch Linux 用户仓库
本软件已打包到 [AUR](https://aur.archlinux.org/packages/zonylrctoolsx-bin)。Arch Linux 及其衍生发行版用户可用如下命令安装:
```bash
# yay 或其他 AUR Helper
yay -S zonylrctoolsx-bin
ZonyLrcTools.Cli --help
```
# 用法
软件的具体使用方法已经迁移到了全新的文档站点,请跳转到 [https://docs.myzony.com](https://docs.myzony.com),里面包含完整的说明文档。
# 捐赠
[爱发电](https://afdian.net/a/zony-lrc-tools)
# Star History
[![Star History Chart](https://api.star-history.com/svg?repos=real-zony/ZonyLrcToolsX&type=Timeline)](https://star-history.com/#real-zony/ZonyLrcToolsX&Timeline)

View File

@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using ZonyLrcTools.Cli.Infrastructure.MusicScannerOptions;
using ZonyLrcTools.Common;
using ZonyLrcTools.Common.Album;
using ZonyLrcTools.Common.Lyrics;
using ZonyLrcTools.Common.MusicScanner;
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
@ -21,17 +15,14 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
private readonly ILyricsDownloader _lyricsDownloader;
private readonly IAlbumDownloader _albumDownloader;
private readonly IMusicInfoLoader _musicInfoLoader;
private readonly IServiceProvider _serviceProvider;
public DownloadCommand(ILyricsDownloader lyricsDownloader,
IMusicInfoLoader musicInfoLoader,
IAlbumDownloader albumDownloader,
IServiceProvider serviceProvider)
IAlbumDownloader albumDownloader)
{
_lyricsDownloader = lyricsDownloader;
_musicInfoLoader = musicInfoLoader;
_albumDownloader = albumDownloader;
_serviceProvider = serviceProvider;
}
#region > Options <
@ -46,92 +37,24 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
[Option("-a|--album", CommandOptionType.NoValue, Description = "指定程序需要下载专辑图像。")]
public bool DownloadAlbum { get; set; }
[Option("-n|--number", CommandOptionType.SingleValue, Description = "指定下载时候的线程数量。(默认值 1)")]
public int ParallelNumber { get; set; } = 1;
#endregion
#region > Scanner Options <
[Option("-sc|--scanner", CommandOptionType.SingleValue, Description = "指定歌词文件扫描器,目前支持本地文件(local),网易云音乐(netease)csv 文件(csv),默认值为 local。")]
public string Scanner { get; set; } = "local";
[Option("-o|--output", Description = "指定歌词文件的输出路径。")]
public string OutputDirectory { get; set; } = "DownloadedLrc";
[Option("-p|--pattern", Description = "指定歌词文件的输出文件名模式。")]
public string OutputFileNamePattern { get; set; } = "{Artist} - {Name}.lrc";
[Option("-f|--file", Description = "指定 CSV 文件的路径。")]
public string CsvFilePath { get; set; }
[Option("-s|--song-list-id", Description = "指定网易云音乐歌单的 ID如果有多个歌单请使用 ';' 分割 ID。")]
public string SongListId { get; set; }
[Option("-n|--number", CommandOptionType.SingleValue, Description = "指定下载时候的线程数量。(默认值 2)")]
public int ParallelNumber { get; set; } = 2;
#endregion
protected override async Task<int> OnExecuteAsync(CommandLineApplication app)
{
if (!DownloadAlbum && !DownloadLyric)
{
throw new ArgumentException("请至少指定一个下载选项,例如 -l(下载歌词) 或 -a(下载专辑图像)。");
}
if (DownloadLyric)
{
await _lyricsDownloader.DownloadAsync(await GetMusicInfosAsync(Scanner), ParallelNumber);
await _lyricsDownloader.DownloadAsync(await _musicInfoLoader.LoadAsync(SongsDirectory, ParallelNumber), ParallelNumber);
}
if (DownloadAlbum)
{
await _albumDownloader.DownloadAsync(await GetMusicInfosAsync(Scanner), ParallelNumber);
await _albumDownloader.DownloadAsync(await _musicInfoLoader.LoadAsync(SongsDirectory, ParallelNumber), ParallelNumber);
}
return 0;
}
/// <summary>
/// Get the music infos by the scanner.
/// </summary>
private async Task<List<MusicInfo>> GetMusicInfosAsync(string scanner)
{
ValidateScannerOptions(scanner);
return scanner switch
{
MusicScannerConsts.LocalScanner => await _musicInfoLoader.LoadAsync(SongsDirectory, ParallelNumber),
MusicScannerConsts.CsvScanner => await _serviceProvider.GetService<CsvFileMusicScanner>()
.GetMusicInfoFromCsvFileAsync(CsvFilePath, OutputDirectory, OutputFileNamePattern),
MusicScannerConsts.NeteaseScanner => await _serviceProvider.GetService<NetEaseMusicSongListMusicScanner>()
.GetMusicInfoFromNetEaseMusicSongListAsync(SongListId, OutputDirectory, OutputFileNamePattern),
_ => await _musicInfoLoader.LoadAsync(SongsDirectory, ParallelNumber)
};
}
/// <summary>
/// Manually validate the options.
/// </summary>
/// <param name="scanner">Scanner Name.</param>
/// <exception cref="ArgumentException">If the options are invalid.</exception>
private void ValidateScannerOptions(string scanner)
{
if (scanner != MusicScannerConsts.LocalScanner && string.IsNullOrEmpty(OutputDirectory))
{
throw new ArgumentException("当使用非本地文件扫描器时,必须指定歌词文件的输出路径。");
}
if (scanner != MusicScannerConsts.LocalScanner && !Directory.Exists(OutputDirectory))
{
throw new ArgumentException("指定的歌词文件输出路径不存在。");
}
switch (scanner)
{
case MusicScannerConsts.CsvScanner when string.IsNullOrWhiteSpace(CsvFilePath):
throw new ArgumentException("当使用 CSV 文件扫描器时,必须指定 CSV 文件的路径。");
case MusicScannerConsts.NeteaseScanner when string.IsNullOrWhiteSpace(SongListId):
throw new ArgumentException("当使用网易云音乐扫描器时,必须指定歌单的 ID。");
}
}
}
}

View File

@ -1,15 +0,0 @@
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging;
namespace ZonyLrcTools.Cli.Commands.SubCommand;
[Command("manual", Description = "手动指定歌曲信息,然后下载对应的歌词数据。")]
public class ManualDownloadCommand : ToolCommandBase
{
private readonly ILogger<ManualDownloadCommand> _logger;
public ManualDownloadCommand(ILogger<ManualDownloadCommand> logger)
{
_logger = logger;
}
}

View File

@ -1,23 +1,13 @@
using System;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
namespace ZonyLrcTools.Cli.Commands
{
[HelpOption("--help|-h",
Description = "欢迎使用 ZonyLrcToolsX Command Line Interface有任何问题请访问 https://soft.myzony.com 或添加 QQ 群 337656932 寻求帮助。",
ShowInHelpText = true)]
[HelpOption("--help|-h", Description = "欢迎使用 ZonyLrcToolsX Command Line Interface。")]
public abstract class ToolCommandBase
{
protected virtual Task<int> OnExecuteAsync(CommandLineApplication app)
{
if (!Environment.UserInteractive)
{
Console.WriteLine("请使用终端运行此程序,如果你不知道如何操作,请访问 https://soft.myzony.com 或添加 QQ 群 337656932 寻求帮助。");
Console.ReadKey();
}
app.ShowHelp();
return Task.FromResult(0);
}
}

View File

@ -1,10 +0,0 @@
// ReSharper disable IdentifierTypo
namespace ZonyLrcTools.Cli.Infrastructure.MusicScannerOptions;
public class MusicScannerConsts
{
public const string LocalScanner = "local";
public const string NeteaseScanner = "netease";
public const string CsvScanner = "csv";
}

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
@ -7,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using ZonyLrcTools.Cli.Commands;
using ZonyLrcTools.Cli.Commands.SubCommand;
using ZonyLrcTools.Cli.Infrastructure;
@ -15,8 +17,6 @@ using ZonyLrcTools.Common.Infrastructure.DependencyInject;
using ZonyLrcTools.Common.Infrastructure.Exceptions;
using ZonyLrcTools.Common.Infrastructure.Network;
// ReSharper disable ClassNeverInstantiated.Global
namespace ZonyLrcTools.Cli
{
[Command("lyric-tool")]
@ -33,7 +33,6 @@ namespace ZonyLrcTools.Cli
try
{
Log.Logger.Information("Starting...");
return await BuildHostedService(args);
}
catch (Exception ex)
@ -64,12 +63,12 @@ namespace ZonyLrcTools.Cli
.WriteTo.Async(c => c.Console(theme: CustomConsoleTheme.Code))
.WriteTo.Logger(lc =>
{
lc.Filter.ByIncludingOnly(warningLog => warningLog.Level == LogEventLevel.Warning)
lc.Filter.ByIncludingOnly(lc => lc.Level == LogEventLevel.Warning)
.WriteTo.Async(c => c.File("Logs/warnings.txt"));
})
.WriteTo.Logger(lc =>
{
lc.Filter.ByIncludingOnly(errLog => errLog.Level == LogEventLevel.Error)
lc.Filter.ByIncludingOnly(lc => lc.Level == LogEventLevel.Error)
.WriteTo.Async(c => c.File("Logs/errors.txt"));
})
.CreateLogger();
@ -78,10 +77,11 @@ namespace ZonyLrcTools.Cli
private static Task<int> BuildHostedService(string[] args)
{
return new HostBuilder()
.ConfigureLogging(l => l.AddSerilog())
.ConfigureLogging(builder => builder.AddSerilog())
.ConfigureHostConfiguration(builder =>
{
builder.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
builder
.SetBasePath(Directory.GetCurrentDirectory())
.AddYamlFile("config.yaml");
})
.ConfigureServices((_, services) =>

View File

@ -4,8 +4,7 @@
"10002": "需要扫描的目录不存在,请确认路径是否正确。",
"10003": "不能获取文件的后缀信息。",
"10004": "没有扫描到任何音乐文件。",
"10005": "指定的编码不受支持,请检查配置,所有受支持的编码名称,请参考: https://docs.microsoft.com/en-us/dotnet/api/system.text.encodinginfo.codepage?view=net-6.0#system-text-encodinginfo-codepage。",
"10006": "无法从网易云音乐获取歌曲列表。"
"10005": "指定的编码不受支持,请检查配置,所有受支持的编码名称,请参考: https://docs.microsoft.com/en-us/dotnet/api/system.text.encodinginfo.codepage?view=net-6.0#system-text-encodinginfo-codepage。"
},
"Warning": {
"50001": "扫描文件时出现了错误。",

View File

@ -1,40 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<OutputType>Exe</OutputType>
<AssemblyVersion>0.0.0.1</AssemblyVersion>
<FileVersion>0.0.0.1</FileVersion>
<PackageVersion>0.0.0.1</PackageVersion>
<Version>0.0.0.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils"/>
<PackageReference Include="McMaster.Extensions.Hosting.CommandLine"/>
<PackageReference Include="Microsoft.Extensions.Hosting"/>
<PackageReference Include="Serilog.Extensions.Hosting"/>
<PackageReference Include="Serilog.Sinks.Async"/>
<PackageReference Include="Serilog.Sinks.Console"/>
<PackageReference Include="Serilog.Sinks.File"/>
<PackageReference Include="System.Text.Encoding.CodePages"/>
<PackageReference Include="Ude.NetStandard"/>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.1" />
<PackageReference Include="McMaster.Extensions.Hosting.CommandLine" Version="4.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json"/>
<None Remove="Resources\error_msg.json"/>
<None Remove="appsettings.json" />
<None Remove="Resources\error_msg.json" />
<Content Include="Resources\error_msg.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="BlockWords.json"/>
<None Remove="BlockWords.json" />
<Content Include="BlockWords.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="config.yaml"/>
<None Remove="config.yaml" />
<Content Include="config.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj"/>
<ProjectReference Include="..\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj" />
</ItemGroup>
</Project>

View File

@ -1,61 +1,56 @@
# 允许扫描的歌曲文件后缀名。
supportFileExtensions:
- '*.mp3'
- '*.flac'
- '*.wav'
- '*.m4a'
- '*.ogg'
- '*.opus'
# 网络代理服务设置,仅支持 HTTP 代理。
networkOptions:
isEnable: false # 是否启用代理。
ip: 127.0.0.1 # 代理服务 IP 地址。
port: 4780 # 代理服务端口号。
updateUrl: https://api.myzony.com/lrc-tools/update # 更新检查地址。
# 下载器的相关参数配置。
provider:
# 标签扫描器的相关参数配置。
tag:
# 支持的标签扫描器。
plugin:
- name: Taglib # 基于 Taglib 库的标签扫描器。
priority: 1 # 优先级,升序排列。
- name: FileName # 基于文件名的标签扫描器。
priority: 2
# 基于文件名扫描器的扩展参数。
extensions:
# 正则表达式,用于匹配文件名中的作者信息和歌曲信息,可根据
# 自己的需求进行调整。
regularExpressions: "(?'artist'.+)\\s-\\s(?'name'.+)"
# 歌曲标签屏蔽字典替换功能。
blockWord:
isEnable: false # 是否启用屏蔽字典。
filePath: 'BlockWords.json' # 屏蔽字典的路径。
# 歌词下载器的相关参数配置。
lyric:
# 支持的歌词下载器。
plugin:
- name: NetEase # 基于网易云音乐的歌词下载器。
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
depth: 10 # 搜索深度,值越大搜索结果越多,但搜索时间越长。
additional:
isEnableRomanOutput: false # 是否启用罗马音输出,本参数仅当对应歌曲有罗马音歌词时有效。
- name: QQ # 基于 QQ 音乐的歌词下载器。
priority: 2
# depth: 10 # 暂时不支持。
- name: KuGou # 基于酷狗音乐的歌词下载器。
priority: 3
depth: 10
- name: KuWo # 基于酷我音乐的歌词下载器。
priority: 4
depth: 10
# 歌词下载的一些共有配置参数。
config:
isOneLine: true # 双语歌词是否合并为一行展示。
lineBreak: "\n" # 换行符的类型,记得使用双引号指定。
isEnableTranslation: true # 是否启用翻译歌词。
isOnlyOutputTranslation: false # 是否只输出翻译歌词。
isSkipExistLyricFiles: false # 如果歌词文件已经存在,是否跳过这些文件。
fileEncoding: 'utf-8' # 歌词文件的编码格式。
globalOption:
# 允许扫描的歌曲文件后缀名。
supportFileExtensions:
- '*.mp3'
- '*.flac'
- '*.wav'
# 网络代理服务设置,仅支持 HTTP 代理。
networkOptions:
isEnable: false # 是否启用代理。
ip: 127.0.0.1 # 代理服务 IP 地址。
port: 4780 # 代理服务端口号。
updateUrl: https://api.myzony.com/lrc-tools/update # 更新检查地址。
# 下载器的相关参数配置。
provider:
# 标签扫描器的相关参数配置。
tag:
# 支持的标签扫描器。
plugin:
- name: Taglib # 基于 Taglib 库的标签扫描器。
priority: 1 # 优先级,升序排列。
- name: FileName # 基于文件名的标签扫描器。
priority: 2
# 基于文件名扫描器的扩展参数。
extensions:
# 正则表达式,用于匹配文件名中的作者信息和歌曲信息,可根据
# 自己的需求进行调整。
regularExpressions: "(?'artist'.+)\\s-\\s(?'name'.+)"
# 歌曲标签屏蔽字典替换功能。
blockWord:
isEnable: false # 是否启用屏蔽字典。
filePath: 'BlockWords.json' # 屏蔽字典的路径。
# 歌词下载器的相关参数配置。
lyric:
# 支持的歌词下载器。
plugin:
- name: NetEase # 基于网易云音乐的歌词下载器。
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
depth: 10 # 搜索深度,值越大搜索结果越多,但搜索时间越长。
- name: QQ # 基于 QQ 音乐的歌词下载器。
priority: 2
# depth: 10 # 暂时不支持。
- name: KuGou # 基于酷狗音乐的歌词下载器。
priority: 3
depth: 10
- name: KuWo # 基于酷我音乐的歌词下载器。
priority: 4
depth: 10
# 歌词下载的一些共有配置参数。
config:
isOneLine: true # 双语歌词是否合并为一行展示。
lineBreak: "\n" # 换行符的类型,记得使用双引号指定。
isEnableTranslation: true # 是否启用翻译歌词。
isOnlyOutputTranslation: false # 是否只输出翻译歌词。
isSkipExistLyricFiles: false # 如果歌词文件已经存在,是否跳过这些文件。
fileEncoding: 'utf-8' # 歌词文件的编码格式。

View File

@ -1,20 +0,0 @@
$Platforms = @('win-x64', 'linux-x64', 'osx-x64', 'win-arm64', 'linux-arm64', 'osx-arm64')
if (-not (Test-Path ./TempFiles)) {
New-Item -ItemType Directory -Path ./TempFiles | Out-Null
}
Remove-Item ./TempFiles/* -Recurse -Force
foreach ($platform in $Platforms) {
dotnet publish -r $platform -c Release -p:PublishSingleFile=true --self-contained true | Out-Null
if ($LASTEXITCODE -ne 0) {
exit 1
}
Set-Location ./bin/Release/net7.0/$platform/publish/
Compress-Archive -Path ./* -DestinationPath ./ZonyLrcTools_${platform}_${Env:PUBLISH_VERSION}.zip | Out-Null
Set-Location ../../../../../
Move-Item ./bin/Release/net7.0/$platform/publish/ZonyLrcTools_${platform}_${Env:PUBLISH_VERSION}.zip ./TempFiles
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
Platforms=('win-x64' 'linux-x64' 'osx-x64' 'win-arm64' 'linux-arm64' 'osx-arm64')
Platforms=('win-x64' 'linux-x64' 'osx-x64')
if ! [ -d './TempFiles' ];
then
@ -10,11 +10,11 @@ rm -rf ./TempFiles/*
for platform in "${Platforms[@]}"
do
dotnet publish -r "$platform" -c Release -p:PublishSingleFile=true -p:DebugType=none --self-contained true || exit 1
dotnet publish -r "$platform" -c Release -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true || exit 1
cd ./bin/Release/net8.0/"$platform"/publish/ || exit 1
cd ./bin/Release/net7.0/"$platform"/publish/ || exit 1
zip -r ./ZonyLrcTools_"$platform"_"${PUBLISH_VERSION}".zip ./ || exit 1
cd ../../../../../ || exit 1
mv ./bin/Release/net8.0/"$platform"/publish/ZonyLrcTools_"$platform"_"$PUBLISH_VERSION".zip ./TempFiles
mv ./bin/Release/net7.0/"$platform"/publish/ZonyLrcTools_"$platform"_"$PUBLISH_VERSION".zip ./TempFiles
done

View File

@ -41,7 +41,7 @@ namespace ZonyLrcTools.Common.Album.NetEase
true,
_defaultOption);
if (searchResult is not { StatusCode: 200 } || searchResult.Items is not { SongCount: > 0 })
if (searchResult is not { StatusCode: 200 } || searchResult.Items?.SongCount <= 0)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong);
}

View File

@ -13,6 +13,6 @@
/// <summary>
/// 屏蔽词字典文件,用于替换歌曲名或者歌手名称。
/// </summary>
public string FilePath { get; set; } = null!;
public string FilePath { get; set; }
}
}

View File

@ -5,16 +5,16 @@ namespace ZonyLrcTools.Common.Configuration
/// <summary>
/// 支持的音乐文件后缀集合。
/// </summary>
public List<string> SupportFileExtensions { get; set; } = null!;
public List<string> SupportFileExtensions { get; set; }
/// <summary>
/// 网络代理相关的配置信息。
/// </summary>
public NetworkOptions NetworkOptions { get; set; } = null!;
public NetworkOptions NetworkOptions { get; set; }
/// <summary>
/// 定义下载器的相关配置信息。
/// </summary>
public ProviderOptions Provider { get; set; } = null!;
public ProviderOptions Provider { get; set; }
}
}

View File

@ -2,12 +2,12 @@ namespace ZonyLrcTools.Common.Configuration;
public class LyricsOptions
{
public IEnumerable<LyricsProviderOptions> Plugin { get; set; } = null!;
public IEnumerable<LyricsProviderOptions> Plugin { get; set; }
public GlobalLyricsConfigOptions Config { get; set; } = null!;
public GlobalLyricsConfigOptions Config { get; set; }
public LyricsProviderOptions GetLyricProviderOption(string name)
{
return Plugin.FirstOrDefault(x => x.Name == name)!;
return Plugin.FirstOrDefault(x => x.Name == name);
}
}

View File

@ -5,7 +5,7 @@
/// <summary>
/// 歌词下载器的唯一标识。
/// </summary>
public string Name { get; set; } = null!;
public string Name { get; set; }
/// <summary>
/// 歌词下载时的优先级,当值为 -1 时是禁用。
@ -16,10 +16,5 @@
/// 搜索深度,值越大搜索结果越多,但搜索时间越长。
/// </summary>
public int Depth { get; set; }
/// <summary>
/// 歌词下载器的扩展属性。
/// </summary>
public Dictionary<string, string>? Additional { get; set; }
}
}

View File

@ -13,16 +13,11 @@ namespace ZonyLrcTools.Common.Configuration
/// <summary>
/// 代理服务器的 Ip。
/// </summary>
public string Ip { get; set; } = null!;
public string Ip { get; set; }
/// <summary>
/// 代理服务器的 端口。
/// </summary>
public int Port { get; set; }
/// <summary>
/// 更新检查的 Url。
/// </summary>
public string UpdateUrl { get; set; } = default!;
}
}

View File

@ -5,10 +5,10 @@ public class ProviderOptions
/// <summary>
/// 标签加载器相关的配置属性。
/// </summary>
public TagInfoOptions Tag { get; set; } = null!;
public TagInfoOptions Tag { get; set; }
/// <summary>
/// 歌词下载相关的配置信息。
/// </summary>
public LyricsOptions Lyric { get; set; } = null!;
public LyricsOptions Lyric { get; set; }
}

View File

@ -2,15 +2,10 @@
public class TagInfoOptions
{
public IEnumerable<TagInfoProviderOptions> Plugin { get; set; } = null!;
public IEnumerable<TagInfoProviderOptions> Plugin { get; set; }
/// <summary>
/// 屏蔽词功能相关配置。
/// </summary>
public BlockWordOptions BlockWord { get; set; } = null!;
public TagInfoProviderOptions GetTagProviderOption(string name)
{
return Plugin.FirstOrDefault(x => x.Name == name)!;
}
public BlockWordOptions BlockWord { get; set; }
}

View File

@ -2,10 +2,10 @@ namespace ZonyLrcTools.Common.Configuration
{
public class TagInfoProviderOptions
{
public string Name { get; set; } = null!;
public string Name { get; set; }
public int Priority { get; set; }
public Dictionary<string, string>? Extensions { get; set; } = null!;
public Dictionary<string, string> Extensions { get; set; }
}
}

View File

@ -45,7 +45,7 @@ namespace ZonyLrcTools.Common.Infrastructure.DependencyInject
public static List<Type> GetDefaultExposedTypes(Type type)
{
var serviceTypes = new List<Type> { type };
var serviceTypes = new List<Type>();
foreach (var interfaceType in type.GetTypeInfo().GetInterfaces())
{
@ -59,6 +59,7 @@ namespace ZonyLrcTools.Common.Infrastructure.DependencyInject
if (type.Name.EndsWith(interfaceName))
{
serviceTypes.Add(interfaceType);
serviceTypes.Add(type);
}
}

View File

@ -15,7 +15,7 @@ namespace ZonyLrcTools.Common.Infrastructure.DependencyInject
/// <summary>
/// 配置工具会用到的服务。
/// </summary>
public static IServiceCollection? ConfigureToolService(this IServiceCollection? services)
public static IServiceCollection ConfigureToolService(this IServiceCollection services)
{
if (services == null)
{
@ -43,11 +43,11 @@ namespace ZonyLrcTools.Common.Infrastructure.DependencyInject
public static IServiceCollection ConfigureConfiguration(this IServiceCollection services)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.SetBasePath(Directory.GetCurrentDirectory())
.AddYamlFile("config.yaml")
.Build();
services.Configure<GlobalOptions>(configuration);
services.Configure<GlobalOptions>(configuration.GetSection("globalOption"));
return services;
}

View File

@ -1,109 +0,0 @@
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
namespace ZonyLrcTools.Common.Infrastructure.Encryption;
/// <summary>
/// 提供网易云音乐 API 的相关加密方法。
/// </summary>
/// <remarks>
/// 加密方法参考以下开源项目:
/// 1. https://github.com/jitwxs/163MusicLyrics/blob/master/MusicLyricApp/Api/Music/NetEaseMusicNativeApi.cs
/// 2. https://github.com/mos9527/pyncm/blob/ad0a84b2ed5f1affa9890d5f54f6170c2cf99bbb/pyncm/utils/crypto.py#L53
/// </remarks>
public static class NetEaseMusicEncryptionHelper
{
public const string Modulus =
"00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7";
public const string Nonce = "0CoJUm6Qyw8W8jud";
public const string PubKey = "010001";
public const string Vi = "0102030405060708";
public static readonly byte[] ID_XOR_KEY_1 = "3go8&$8*3*3h0k(2)2"u8.ToArray();
public static string RsaEncode(string text)
{
var srText = new string(text.Reverse().ToArray());
var a = BCHexDec(BitConverter.ToString(Encoding.Default.GetBytes(srText)).Replace("-", string.Empty));
var b = BCHexDec(PubKey);
var c = BCHexDec(Modulus);
var key = BigInteger.ModPow(a, b, c).ToString("x");
key = key.PadLeft(256, '0');
return key.Length > 256 ? key.Substring(key.Length - 256, 256) : key;
}
public static BigInteger BCHexDec(string hex)
{
var dec = new BigInteger(0);
var len = hex.Length;
for (var i = 0; i < len; i++)
{
dec += BigInteger.Multiply(new BigInteger(Convert.ToInt32(hex[i].ToString(), 16)),
BigInteger.Pow(new BigInteger(16), len - i - 1));
}
return dec;
}
public static string AesEncode(string secretData, string secret = "TA3YiYCfY2dDJQgg")
{
byte[] encrypted;
var iv = Encoding.UTF8.GetBytes(Vi);
using (var aes = Aes.Create())
{
aes.Key = Encoding.UTF8.GetBytes(secret);
aes.IV = iv;
aes.Mode = CipherMode.CBC;
using (var encryptor = aes.CreateEncryptor())
{
using (var stream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(stream, encryptor, CryptoStreamMode.Write))
{
using (var sw = new StreamWriter(cryptoStream))
{
sw.Write(secretData);
}
encrypted = stream.ToArray();
}
}
}
}
return Convert.ToBase64String(encrypted);
}
public static string CreateSecretKey(int length)
{
const string str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sb = new StringBuilder(length);
var rnd = new Random();
for (var i = 0; i < length; ++i)
{
sb.Append(str[rnd.Next(0, str.Length)]);
}
return sb.ToString();
}
public static string CloudMusicDllEncode(string deviceId)
{
var xored = new byte[deviceId.Length];
for (var i = 0; i < deviceId.Length; i++)
{
xored[i] = (byte)(deviceId[i] ^ ID_XOR_KEY_1[i % ID_XOR_KEY_1.Length]);
}
using (var md5 = MD5.Create())
{
var digest = md5.ComputeHash(xored);
return Convert.ToBase64String(digest);
}
}
}

View File

@ -7,7 +7,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
{
public int ErrorCode { get; }
public object? AttachObject { get; }
public object AttachObject { get; }
/// <summary>
/// 构建一个新的 <see cref="ErrorCodeException"/> 对象。
@ -15,7 +15,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
/// <param name="errorCode">错误码,参考 <see cref="ErrorCodes"/> 类的定义。</param>
/// <param name="message">错误信息。</param>
/// <param name="attachObj">附加的对象数据。</param>
public ErrorCodeException(int errorCode, string? message = null, object? attachObj = null) : base(message)
public ErrorCodeException(int errorCode, string? message = null, object attachObj = null) : base(message)
{
ErrorCode = errorCode;
AttachObject = attachObj;

View File

@ -26,14 +26,14 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
return;
}
var jsonPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "error_msg.json");
var jsonPath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "error_msg.json");
using var jsonReader = new JsonTextReader(File.OpenText(jsonPath));
var jsonObj = JObject.Load(jsonReader);
var errors = jsonObj.SelectTokens("$.Error.*");
var warnings = jsonObj.SelectTokens("$.Warning.*");
errors.Union(warnings).Select(m => m.Parent).OfType<JProperty>().ToList()
.ForEach(m => ErrorMessages.Add(int.Parse(m.Name), m.Value.Value<string>() ?? string.Empty));
.ForEach(m => ErrorMessages.Add(int.Parse(m.Name), m.Value.Value<string>()));
}
public static string GetMessage(int errorCode) => ErrorMessages[errorCode];

View File

@ -31,11 +31,6 @@ namespace ZonyLrcTools.Common.Infrastructure.Exceptions
/// 文本: 指定的编码不受支持,请检查配置,所有受支持的编码名称。
/// </summary>
public const int NotSupportedFileEncoding = 10005;
/// <summary>
/// 文本: 无法从网易云音乐获取歌曲列表。
/// </summary>
public const int UnableGetSongListFromNetEaseCloudMusic = 10006;
#endregion

View File

@ -17,7 +17,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Extensions
/// <param name="logger">日志记录器实例。</param>
/// <param name="errorCode">错误码,具体请参考 <see cref="ErrorCodes"/> 类的定义。</param>
/// <param name="e">异常实例,可为空。</param>
public static void LogWarningWithErrorCode(this IWarpLogger logger, int errorCode, Exception? e = null)
public static void LogWarningWithErrorCode(this IWarpLogger logger, int errorCode, Exception e = null)
{
logger.WarnAsync($"错误代码: {errorCode}\n堆栈异常: {e?.StackTrace}").GetAwaiter().GetResult();
}

View File

@ -19,29 +19,9 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
}
public async ValueTask<string> PostAsync(string url,
object? parameters = null,
object parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage>? requestOption = null)
{
using var responseMessage = await PostReturnHttpResponseAsync(url, parameters, isQueryStringParam, requestOption);
var responseContentString = await responseMessage.Content.ReadAsStringAsync();
return ValidateHttpResponse(responseMessage, parameters, responseContentString);
}
public async ValueTask<TResponse> PostAsync<TResponse>(string url,
object? parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage>? requestOption = null)
{
var responseString = await PostAsync(url, parameters, isQueryStringParam, requestOption);
return ConvertHttpResponseToObject<TResponse>(parameters, responseString);
}
public async ValueTask<HttpResponseMessage> PostReturnHttpResponseAsync(string url,
object? parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage>? requestOption = null)
Action<HttpRequestMessage> requestOption = null)
{
var parametersStr = isQueryStringParam ? BuildQueryString(parameters) : BuildJsonBodyString(parameters);
var requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
@ -49,12 +29,24 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
requestOption?.Invoke(requestMessage);
return await BuildHttpClient().SendAsync(requestMessage);
using var responseMessage = await BuildHttpClient().SendAsync(requestMessage);
var responseContentString = await responseMessage.Content.ReadAsStringAsync();
return ValidateHttpResponse(responseMessage, parameters, responseContentString);
}
public async ValueTask<TResponse> PostAsync<TResponse>(string url,
object parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage> requestOption = null)
{
var responseString = await PostAsync(url, parameters, isQueryStringParam, requestOption);
return ConvertHttpResponseToObject<TResponse>(parameters, responseString);
}
public async ValueTask<string> GetAsync(string url,
object? parameters = null,
Action<HttpRequestMessage>? requestOption = null)
object parameters = null,
Action<HttpRequestMessage> requestOption = null)
{
var requestParamsStr = BuildQueryString(parameters);
var requestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri($"{url}?{requestParamsStr}"));
@ -67,8 +59,8 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
}
public async ValueTask<TResponse> GetAsync<TResponse>(string url,
object? parameters = null,
Action<HttpRequestMessage>? requestOption = null)
object parameters = null,
Action<HttpRequestMessage> requestOption = null)
{
var responseString = await GetAsync(url, parameters, requestOption);
return ConvertHttpResponseToObject<TResponse>(parameters, responseString);
@ -79,7 +71,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
return _httpClientFactory.CreateClient(HttpClientNameConstant);
}
private string BuildQueryString(object? parameters)
private string BuildQueryString(object parameters)
{
if (parameters == null)
{
@ -89,7 +81,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
var type = parameters.GetType();
if (type == typeof(string))
{
return parameters as string ?? string.Empty;
return parameters as string;
}
var properties = type.GetProperties();
@ -106,7 +98,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
return paramBuilder.ToString().TrimEnd('&');
}
private string BuildJsonBodyString(object? parameters)
private string BuildJsonBodyString(object parameters)
{
if (parameters == null) return string.Empty;
if (parameters is string result) return result;
@ -122,7 +114,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
/// <param name="responseString">执行 Http 请求之后响应内容。</param>
/// <returns>如果响应正常,则返回具体的响应内容。</returns>
/// <exception cref="ErrorCodeException">如果 Http 响应不正常,则可能抛出本异常。</exception>
private string ValidateHttpResponse(HttpResponseMessage responseMessage, object? requestParameters, string responseString)
private string ValidateHttpResponse(HttpResponseMessage responseMessage, object requestParameters, string responseString)
{
return responseMessage.StatusCode switch
{
@ -139,7 +131,7 @@ namespace ZonyLrcTools.Common.Infrastructure.Network
/// <param name="responseString">执行 Http 请求之后响应内容。</param>
/// <typeparam name="TResponse">需要将响应结果反序列化的目标类型。</typeparam>
/// <exception cref="ErrorCodeException">如果反序列化失败,则可能抛出本异常。</exception>
private TResponse ConvertHttpResponseToObject<TResponse>(object? requestParameters, string responseString)
private TResponse ConvertHttpResponseToObject<TResponse>(object requestParameters, string responseString)
{
var throwException = new ErrorCodeException(ErrorCodes.HttpResponseConvertJsonFailed, attachObj: new { requestParameters, responseString });

View File

@ -14,9 +14,9 @@
/// <param name="requestOption">请求时的配置动作。</param>
/// <returns>服务端的响应结果。</returns>
ValueTask<string> PostAsync(string url,
object? parameters = null,
object parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage>? requestOption = null);
Action<HttpRequestMessage> requestOption = null);
/// <summary>
/// 根据指定的配置执行 POST 请求,并将结果反序列化为 <see cref="TResponse"/> 对象。
@ -28,14 +28,9 @@
/// <typeparam name="TResponse">需要将响应结果反序列化的目标类型。</typeparam>
/// <returns>服务端的响应结果。</returns>
ValueTask<TResponse> PostAsync<TResponse>(string url,
object? parameters = null,
object parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage>? requestOption = null);
ValueTask<HttpResponseMessage> PostReturnHttpResponseAsync(string url,
object? parameters = null,
bool isQueryStringParam = false,
Action<HttpRequestMessage>? requestOption = null);
Action<HttpRequestMessage> requestOption = null);
/// <summary>
/// 根据指定的配置执行 GET 请求,并以 <see cref="string"/> 作为返回值。
@ -45,8 +40,8 @@
/// <param name="requestOption">请求时的配置动作。</param>
/// <returns>服务端的响应结果。</returns>
ValueTask<string> GetAsync(string url,
object? parameters = null,
Action<HttpRequestMessage>? requestOption = null);
object parameters = null,
Action<HttpRequestMessage> requestOption = null);
/// <summary>
/// 根据指定的配置执行 GET 请求,并将结果反序列化为 <see cref="TResponse"/> 对象。
@ -58,7 +53,7 @@
/// <returns>服务端的响应结果。</returns>
ValueTask<TResponse> GetAsync<TResponse>(
string url,
object? parameters = null,
Action<HttpRequestMessage>? requestOption = null);
object parameters = null,
Action<HttpRequestMessage> requestOption = null);
}
}

View File

@ -1,24 +1,10 @@
namespace ZonyLrcTools.Common.Lyrics;
/// <summary>
/// 歌词下载核心逻辑的接口定义。
/// </summary>
public interface ILyricsDownloader
{
/// <summary>
/// 使用给定的歌词信息下载歌词,并输出文件到指定的路径。
/// </summary>
/// <param name="needDownloadMusicInfos">需要下载的歌词信息。</param>
/// <param name="parallelCount">下载线程/并发量。</param>
/// <param name="callback">任务完成之后的回调方法。</param>
/// <param name="cancellationToken">任务取消标记。</param>
Task DownloadAsync(List<MusicInfo> needDownloadMusicInfos,
int parallelCount = 1,
Func<MusicInfo, Task>? callback = null,
int parallelCount = 2,
CancellationToken cancellationToken = default);
/// <summary>
/// 获取目前可用的歌词下载器。
/// </summary>
IEnumerable<ILyricsProvider> AvailableProviders { get; }
}

View File

@ -18,6 +18,6 @@ namespace ZonyLrcTools.Common.Lyrics
/// <param name="sourceLyric">原始歌词数据。</param>
/// <param name="translationLyric">翻译歌词数据。</param>
/// <returns>构建完成的 <see cref="LyricsItemCollection"/> 对象。</returns>
LyricsItemCollection Build(string? sourceLyric, string? translationLyric);
LyricsItemCollection Build(string sourceLyric, string translationLyric);
}
}

View File

@ -12,7 +12,7 @@ namespace ZonyLrcTools.Common.Lyrics
/// <param name="artist">歌曲的作者。</param>
/// <param name="duration">歌曲的时长。</param>
/// <returns>歌曲的歌词数据对象。</returns>
ValueTask<LyricsItemCollection> DownloadAsync(string songName, string artist, long? duration = null);
ValueTask<LyricsItemCollection> DownloadAsync(string? songName, string? artist, long? duration = null);
/// <summary>
/// 下载器的名称。

View File

@ -1,5 +1,4 @@
using System.Collections.Immutable;
using System.Text;
using System.Text;
using Microsoft.Extensions.Options;
using ZonyLrcTools.Common.Configuration;
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
@ -10,7 +9,6 @@ using ZonyLrcTools.Common.Infrastructure.Threading;
namespace ZonyLrcTools.Common.Lyrics;
/// <inheritdoc cref="ZonyLrcTools.Common.Lyrics.ILyricsDownloader" />
public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
{
private readonly IEnumerable<ILyricsProvider> _lyricsProviders;
@ -38,8 +36,7 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
}
public async Task DownloadAsync(List<MusicInfo> needDownloadMusicInfos,
int parallelCount = 1,
Func<MusicInfo, Task>? callback = null,
int parallelCount = 2,
CancellationToken cancellationToken = default)
{
await _logger.InfoAsync("开始下载歌词文件数据...");
@ -59,21 +56,17 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
{
await DownloadAndWriteLyricsAsync(lyricsProvider, info);
if (!info.IsSuccessful) continue;
_logger.LogSuccessful(info);
break;
if (info.IsSuccessful)
{
_logger.LogSuccessful(info);
return;
}
}
if (callback != null) await callback(info);
}, cancellationToken), cancellationToken));
await Task.WhenAll(downloadTasks);
var successfulCount = needDownloadMusicInfos.Count(m => m is { IsSuccessful: true, IsPruneMusic: false });
var skippedCount = needDownloadMusicInfos.Count(m => m is { IsSuccessful: true, IsPruneMusic: true });
var failedCount = needDownloadMusicInfos.Count(m => m.IsSuccessful == false);
await _logger.InfoAsync($"歌词数据下载完成,成功: {successfulCount} 跳过(纯音乐): {skippedCount} 失败{failedCount}。");
await LogFailedSongFilesInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"歌词下载失败列表_{DateTime.Now:yyyyMMddHHmmss}.txt"), needDownloadMusicInfos);
await _logger.InfoAsync($"歌词数据下载完成,成功: {needDownloadMusicInfos.Count(m => m.IsSuccessful)} 失败{needDownloadMusicInfos.Count(m => m.IsSuccessful == false)}。");
}
private async Task DownloadAndWriteLyricsAsync(ILyricsProvider provider, MusicInfo info)
@ -85,7 +78,6 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
if (lyrics.IsPruneMusic)
{
info.IsSuccessful = true;
info.IsPruneMusic = true;
return;
}
@ -125,13 +117,6 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
private byte[] Utf8ToSelectedEncoding(LyricsItemCollection lyrics)
{
var supportEncodings = Encoding.GetEncodings();
// If the encoding is UTF-8 BOM, add the BOM to the front of the lyrics.
if (_options.Provider.Lyric.Config.FileEncoding == "utf-8-bom")
{
return Encoding.UTF8.GetPreamble().Concat(lyrics.GetUtf8Bytes()).ToArray();
}
if (supportEncodings.All(x => x.Name != _options.Provider.Lyric.Config.FileEncoding))
{
throw new ErrorCodeException(ErrorCodes.NotSupportedFileEncoding);
@ -139,23 +124,4 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
return Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding(_options.Provider.Lyric.Config.FileEncoding), lyrics.GetUtf8Bytes());
}
private async Task LogFailedSongFilesInfo(string outFilePath, IEnumerable<MusicInfo> musicInfos)
{
var failedSongList = musicInfos.Where(m => m.IsSuccessful == false).ToImmutableList();
if (!failedSongList.Any())
{
return;
}
var failedSongFiles = new StringBuilder();
failedSongFiles.AppendLine("歌曲名,歌手,路径");
foreach (var failedSongFile in failedSongList)
{
failedSongFiles.AppendLine($"{failedSongFile.Name},{failedSongFile.Artist},{failedSongFile.FilePath}");
}
await File.WriteAllTextAsync(outFilePath, failedSongFiles.ToString());
}
}

View File

@ -15,7 +15,7 @@ namespace ZonyLrcTools.Common.Lyrics
/// <summary>
/// 歌词文本数据。
/// </summary>
public string? LyricText { get; }
public string LyricText { get; }
/// <summary>
/// 歌词所在的时间(分)。
@ -55,21 +55,21 @@ namespace ZonyLrcTools.Common.Lyrics
/// <param name="minute">歌词所在的时间(分)。</param>
/// <param name="second">歌词所在的时间(秒)。</param>
/// <param name="lyricText">歌词文本数据。</param>
public LyricsItem(int minute, double second, string? lyricText)
public LyricsItem(int minute, double second, string lyricText)
{
Minute = minute;
Second = second;
LyricText = lyricText;
}
public int CompareTo(LyricsItem? other)
public int CompareTo(LyricsItem other)
{
if (SortScore > other?.SortScore)
if (SortScore > other.SortScore)
{
return 1;
}
if (SortScore < other?.SortScore)
if (SortScore < other.SortScore)
{
return -1;
}
@ -87,12 +87,12 @@ namespace ZonyLrcTools.Common.Lyrics
return left.SortScore < right.SortScore;
}
public static bool operator ==(LyricsItem? left, LyricsItem? right)
public static bool operator ==(LyricsItem left, LyricsItem right)
{
return (int?)left?.SortScore == (int?)right?.SortScore;
}
public static bool operator !=(LyricsItem? item1, LyricsItem? item2)
public static bool operator !=(LyricsItem item1, LyricsItem item2)
{
return !(item1 == item2);
}
@ -107,7 +107,7 @@ namespace ZonyLrcTools.Common.Lyrics
return LyricText == other.LyricText && Minute == other.Minute && Second.Equals(other.Second);
}
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;

View File

@ -14,7 +14,7 @@ namespace ZonyLrcTools.Common.Lyrics
/// </summary>
public bool IsPruneMusic => Count == 0;
public GlobalLyricsConfigOptions? Options { get; }
public GlobalLyricsConfigOptions? Options { get; private set; }
public LyricsItemCollection(GlobalLyricsConfigOptions? options)
{
@ -29,11 +29,6 @@ namespace ZonyLrcTools.Common.Lyrics
}
var option = left.Options;
if (option == null)
{
throw new NullReferenceException("LyricsItemCollection.Options");
}
var newCollection = new LyricsItemCollection(option);
var indexDiff = left.Count - right.Count;
if (!option.IsOneLine)
@ -105,11 +100,6 @@ namespace ZonyLrcTools.Common.Lyrics
public override string ToString()
{
if (Options == null)
{
throw new NullReferenceException("LyricsItemCollection.Options");
}
var lyricBuilder = new StringBuilder();
ForEach(lyric => lyricBuilder.Append(lyric).Append(Options.LineBreak));
return lyricBuilder.ToString().TrimEnd(Options.LineBreak);

View File

@ -30,7 +30,7 @@ namespace ZonyLrcTools.Common.Lyrics
return lyric;
}
public LyricsItemCollection Build(string? sourceLyric, string? translationLyric)
public LyricsItemCollection Build(string sourceLyric, string translationLyric)
{
var lyric = new LyricsItemCollection(_options.Provider.Lyric.Config);
if (string.IsNullOrEmpty(sourceLyric))

View File

@ -10,9 +10,9 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou.JsonModel
[JsonProperty("client")] public string UnknownParameters3 { get; }
[JsonProperty("hash")] public string? FileHash { get; }
[JsonProperty("hash")] public string FileHash { get; }
public GetLyricAccessKeyRequest(string? fileHash)
public GetLyricAccessKeyRequest(string fileHash)
{
UnknownParameters1 = 1;
UnknownParameters2 = "yes";

View File

@ -8,13 +8,13 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou.JsonModel
[JsonProperty("errcode")] public int ErrorCode { get; set; }
[JsonProperty("candidates")] public List<GetLyricAccessKeyDataObject>? AccessKeyDataObjects { get; set; }
[JsonProperty("candidates")] public List<GetLyricAccessKeyDataObject> AccessKeyDataObjects { get; set; }
}
public class GetLyricAccessKeyDataObject
{
[JsonProperty("accesskey")] public string? AccessKey { get; set; }
[JsonProperty("accesskey")] public string AccessKey { get; set; }
[JsonProperty("id")] public string? Id { get; set; }
[JsonProperty("id")] public string Id { get; set; }
}
}

View File

@ -12,11 +12,11 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou.JsonModel
[JsonProperty("charset")] public string UnknownParameters4 { get; }
[JsonProperty("id")] public string? Id { get; }
[JsonProperty("id")] public string Id { get; }
[JsonProperty("accesskey")] public string? AccessKey { get; }
[JsonProperty("accesskey")] public string AccessKey { get; }
public GetLyricRequest(string? id, string? accessKey)
public GetLyricRequest(string id, string accessKey)
{
UnknownParameters1 = 1;
UnknownParameters2 = "iphone";

View File

@ -6,20 +6,20 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou.JsonModel
{
[JsonProperty("status")] public int Status { get; set; }
[JsonProperty("data")] public SongSearchResponseInnerData? Data { get; set; }
[JsonProperty("data")] public SongSearchResponseInnerData Data { get; set; }
[JsonProperty("error_code")] public int ErrorCode { get; set; }
[JsonProperty("error_msg")] public string? ErrorMessage { get; set; }
[JsonProperty("error_msg")] public string ErrorMessage { get; set; }
}
public class SongSearchResponseInnerData
{
[JsonProperty("lists")] public List<SongSearchResponseSongDetail>? List { get; set; }
[JsonProperty("lists")] public List<SongSearchResponseSongDetail> List { get; set; }
}
public class SongSearchResponseSongDetail
{
public string? FileHash { get; set; }
public string FileHash { get; set; }
}
}

View File

@ -8,7 +8,7 @@ using ZonyLrcTools.Common.Lyrics.Providers.KuGou.JsonModel;
namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou
{
public class KuGouLyricsProvider : LyricsProvider
public class KuGourLyricsProvider : LyricsProvider
{
public override string DownloaderName => InternalLyricsProviderNames.KuGou;
@ -20,7 +20,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou
private const string KuGouGetLyricAccessKeyUrl = @"http://lyrics.kugou.com/search";
private const string KuGouGetLyricUrl = @"http://lyrics.kugou.com/download";
public KuGouLyricsProvider(IWarpHttpClient warpHttpClient,
public KuGourLyricsProvider(IWarpHttpClient warpHttpClient,
ILyricsItemCollectionFactory lyricsItemCollectionFactory,
IOptions<GlobalOptions> options)
{
@ -38,12 +38,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou
// 获得特殊的 AccessToken 与 Id真正请求歌词数据。
var accessKeyResponse = await _warpHttpClient.GetAsync<GetLyricAccessKeyResponse>(KuGouGetLyricAccessKeyUrl,
new GetLyricAccessKeyRequest(searchResult.Data?.List?[0].FileHash));
if (accessKeyResponse.AccessKeyDataObjects == null || accessKeyResponse.AccessKeyDataObjects.Count == 0)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
}
new GetLyricAccessKeyRequest(searchResult.Data.List[0].FileHash));
var accessKeyObject = accessKeyResponse.AccessKeyDataObjects[0];
return await _warpHttpClient.GetAsync(KuGouGetLyricUrl,
@ -54,18 +49,18 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou
{
await ValueTask.CompletedTask;
var lyricJsonObj = JObject.Parse((data as string)!);
if (lyricJsonObj.SelectToken("$.status")?.Value<int>() != 200)
if (lyricJsonObj.SelectToken("$.status").Value<int>() != 200)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
}
var lyricText = Encoding.UTF8.GetString(Convert.FromBase64String(lyricJsonObj.SelectToken("$.content")?.Value<string>() ?? string.Empty));
var lyricText = Encoding.UTF8.GetString(Convert.FromBase64String(lyricJsonObj.SelectToken("$.content").Value<string>()));
return _lyricsItemCollectionFactory.Build(lyricText);
}
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricsProviderArgs args)
{
if ((response.ErrorCode != 0 && response.Status != 1) || response.Data?.List?.Count == 0)
if (response.ErrorCode != 0 && response.Status != 1 || response.Data.List == null)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
}

View File

@ -6,7 +6,7 @@ public class GetLyricsResponse
{
[JsonProperty("status")] public int Status { get; set; }
[JsonProperty("data")] public GetLyricsResponseInnerData? Data { get; set; }
[JsonProperty("data")] public GetLyricsResponseInnerData Data { get; set; }
[JsonProperty("msg")] public string? ErrorMessage { get; set; }
@ -15,12 +15,12 @@ public class GetLyricsResponse
public class GetLyricsResponseInnerData
{
[JsonProperty("lrclist")] public ICollection<GetLyricsItem>? Lyrics { get; set; }
[JsonProperty("lrclist")] public ICollection<GetLyricsItem> Lyrics { get; set; }
}
public class GetLyricsItem
{
[JsonProperty("lineLyric")] public string? Text { get; set; }
[JsonProperty("lineLyric")] public string Text { get; set; }
[JsonProperty("time")] public string Position { get; set; } = null!;
[JsonProperty("time")] public string Position { get; set; }
}

View File

@ -4,49 +4,13 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuWo.JsonModel;
public class SongSearchRequest
{
[JsonProperty("all")] public string Keyword { get; set; }
[JsonProperty("key")] public string Keyword { get; set; }
[JsonProperty("pn")] public int PageNumber { get; }
[JsonProperty("rn")] public int PageSize { get; }
[JsonProperty("ft")] public string Unknown1 { get; } = "music";
[JsonProperty("newsearch")] public string Unknown2 { get; } = "1";
[JsonProperty("alflac")] public string Unknown3 { get; } = "1";
[JsonProperty("itemset")] public string Unknown4 { get; } = "web_2013";
[JsonProperty("client")] public string Unknown5 { get; } = "kt";
[JsonProperty("cluster")] public string Unknown6 { get; } = "0";
[JsonProperty("vermerge")] public string Unknown7 { get; } = "1";
[JsonProperty("rformat")] public string Unknown8 { get; } = "json";
[JsonProperty("encoding")] public string Unknown9 { get; } = "utf8";
[JsonProperty("show_copyright_off")] public string Unknown10 { get; } = "1";
[JsonProperty("pcmp4")] public string Unknown11 { get; } = "1";
[JsonProperty("ver")] public string Unknown12 { get; } = "mbox";
[JsonProperty("plat")] public string Unknown13 { get; } = "pc";
[JsonProperty("vipver")] public string Unknown14 { get; } = "MUSIC_9.2.0.0_W6";
[JsonProperty("devid")] public string Unknown15 { get; } = "11404450";
[JsonProperty("newver")] public string Unknown16 { get; } = "1";
[JsonProperty("issubtitle")] public string Unknown17 { get; } = "1";
[JsonProperty("pcjson")] public string Unknown18 { get; } = "1";
public SongSearchRequest(string name, string artist, int pageNumber = 0, int pageSize = 20)
public SongSearchRequest(string name, string artist, int pageNumber = 1, int pageSize = 20)
{
Keyword = $"{name} {artist}";
PageNumber = pageNumber;

View File

@ -4,14 +4,15 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuWo.JsonModel;
public class SongSearchResponse
{
[JsonProperty("TOTAL")] public int TotalCount { get; set; }
[JsonProperty("code")] public int Code { get; set; }
[JsonProperty("abslist")]
public IList<SongSearchResponseSongDetail> SongList { get; set; }
[JsonProperty("data")] public SongSearchResponseInnerData InnerData { get; set; }
[JsonProperty("msg")] public string? ErrorMessage { get; set; }
public long GetMatchedMusicId(string musicName, string artistName, long? duration)
{
var prefectMatch = SongList.FirstOrDefault(x => x.Name == musicName && x.Artist == artistName);
var prefectMatch = InnerData.SongItems.FirstOrDefault(x => x.Name == musicName && x.Artist == artistName);
if (prefectMatch != null)
{
return prefectMatch.MusicId;
@ -19,42 +20,27 @@ public class SongSearchResponse
if (duration is null or 0)
{
return SongList.First().MusicId;
return InnerData.SongItems.First().MusicId;
}
return SongList.OrderBy(t => Math.Abs(t.Duration - duration.Value)).First().MusicId;
return InnerData.SongItems.OrderBy(t => Math.Abs(t.Duration - duration.Value)).First().MusicId;
}
}
public class SongSearchResponseSongDetail
public class SongSearchResponseInnerData
{
/// <summary>
/// 专辑名称。
/// </summary>
[JsonProperty("ALBUM")]
public string Album { get; set; }
[JsonProperty("total")] public string Total { get; set; }
/// <summary>
/// 歌手名称。
/// </summary>
[JsonProperty("ARTIST")]
public string Artist { get; set; }
[JsonProperty("list")] public ICollection<SongSearchResponseDetail> SongItems { get; set; }
}
/// <summary>
/// 歌曲名称。
/// </summary>
[JsonProperty("SONGNAME")]
public string Name { get; set; }
public class SongSearchResponseDetail
{
[JsonProperty("artist")] public string? Artist { get; set; }
/// <summary>
/// 歌曲的 ID。
/// </summary>
[JsonProperty("DC_TARGETID")]
public long MusicId { get; set; }
[JsonProperty("name")] public string? Name { get; set; }
/// <summary>
/// 歌曲的时间长度。
/// </summary>
[JsonProperty("DURATION")]
public long Duration { get; set; }
[JsonProperty("rid")] public long MusicId { get; set; }
[JsonProperty("duration")] public long Duration { get; set; }
}

View File

@ -13,27 +13,29 @@ public class KuWoLyricsProvider : LyricsProvider
{
public override string DownloaderName => InternalLyricsProviderNames.KuWo;
private const string KuWoSearchMusicUrl = @"https://search.kuwo.cn/r.s";
private const string KuWoSearchMusicUrl = @"https://www.kuwo.cn/api/www/search/searchMusicBykeyWord";
private const string KuWoSearchLyricsUrl = @"https://m.kuwo.cn/newh5/singles/songinfoandlrc";
private const string KuWoDefaultToken = "ABCDE12345";
private readonly IWarpHttpClient _warpHttpClient;
private readonly ILyricsItemCollectionFactory _lyricsItemCollectionFactory;
private readonly GlobalOptions _options;
private static readonly ProductInfoHeaderValue UserAgent = new("Chrome", "81.0.4044.138");
public KuWoLyricsProvider(IWarpHttpClient warpHttpClient,
ILyricsItemCollectionFactory lyricsItemCollectionFactory,
IOptions<GlobalOptions> options)
{
_warpHttpClient = warpHttpClient;
_lyricsItemCollectionFactory = lyricsItemCollectionFactory;
_options = options.Value;
}
protected override async ValueTask<object> DownloadDataAsync(LyricsProviderArgs args)
{
var songSearchResponse = await _warpHttpClient.GetAsync<SongSearchResponse>(KuWoSearchMusicUrl,
new SongSearchRequest(args.SongName, args.Artist,
pageSize: _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth),
new SongSearchRequest(args.SongName, args.Artist, pageSize: _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth),
op =>
{
op.Headers.UserAgent.Add(UserAgent);
@ -53,23 +55,16 @@ public class KuWoLyricsProvider : LyricsProvider
});
}
protected override async ValueTask<LyricsItemCollection> GenerateLyricAsync(object lyricsObject,
LyricsProviderArgs args)
protected override async ValueTask<LyricsItemCollection> GenerateLyricAsync(object lyricsObject, LyricsProviderArgs args)
{
await ValueTask.CompletedTask;
var lyricsResponse = (GetLyricsResponse)lyricsObject;
if (lyricsResponse.Data?.Lyrics == null)
{
return new LyricsItemCollection(null);
}
var items = lyricsResponse.Data.Lyrics.Select(l =>
{
var position = double.Parse(l.Position);
var positionSpan = TimeSpan.FromSeconds(position);
return new LyricsItem(positionSpan.Minutes,
double.Parse($"{positionSpan.Seconds}.{positionSpan.Milliseconds}"), l.Text);
return new LyricsItem(positionSpan.Minutes, double.Parse($"{positionSpan.Seconds}.{positionSpan.Milliseconds}"), l.Text);
});
var lyricsItemCollection = new LyricsItemCollection(_options.Provider.Lyric.Config);
@ -79,7 +74,12 @@ public class KuWoLyricsProvider : LyricsProvider
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricsProviderArgs args)
{
if (response.TotalCount == 0)
if (response.Code != 200)
{
throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, response.ErrorMessage, args);
}
if (response.InnerData.SongItems.Count == 0)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
}

View File

@ -8,7 +8,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
{
public GetLyricRequest(long songId)
{
OS = "pc";
OS = "ios";
Id = songId;
Lv = Kv = Tv = Rv = -1;
}

View File

@ -8,31 +8,31 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
/// 原始的歌词。
/// </summary>
[JsonProperty("lrc")]
public InnerLyric? OriginalLyric { get; set; }
public InnerLyric OriginalLyric { get; set; }
/// <summary>
/// 卡拉 OK 歌词。
/// </summary>
[JsonProperty("klyric")]
public InnerLyric? KaraokeLyric { get; set; }
public InnerLyric KaraokeLyric { get; set; }
/// <summary>
/// 如果存在翻译歌词,则本项内容为翻译歌词。
/// </summary>
[JsonProperty("tlyric")]
public InnerLyric? TranslationLyric { get; set; }
public InnerLyric TranslationLyric { get; set; }
/// <summary>
/// 如果存在罗马音歌词,则本项内容为罗马音歌词。
/// </summary>
[JsonProperty("romalrc")]
public InnerLyric? RomaLyric { get; set; }
public InnerLyric RomaLyric { get; set; }
/// <summary>
/// 状态码。
/// </summary>
[JsonProperty("code")]
public string? StatusCode { get; set; }
public string StatusCode { get; set; }
}
/// <summary>
@ -40,12 +40,12 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
/// </summary>
public class InnerLyric
{
[JsonProperty("version")] public string? Version { get; set; }
[JsonProperty("version")] public string Version { get; set; }
/// <summary>
/// 具体的歌词数据。
/// </summary>
[JsonProperty("lyric")]
public string? Text { get; set; }
public string Text { get; set; }
}
}

View File

@ -4,13 +4,13 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
{
public class GetSongDetailsRequest
{
public GetSongDetailsRequest(long songId)
public GetSongDetailsRequest(int songId)
{
SongId = songId;
SongIds = $"%5B{songId}%5D";
}
[JsonProperty("id")] public long SongId { get; }
[JsonProperty("id")] public int SongId { get; }
[JsonProperty("ids")] public string SongIds { get; }
}

View File

@ -45,19 +45,22 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
[JsonProperty("crypto")] public string Crypto { get; set; } = "weapi";
public SongSearchRequest(string musicName, string artistName, int limit = 10)
public SongSearchRequest()
{
CsrfToken = string.Empty;
Type = 1;
Offset = 0;
IsTotal = true;
Limit = 10;
}
public SongSearchRequest(string musicName, string artistName, int limit = 10) : this()
{
// Remove all the brackets and the content inside them.
var regex = new Regex(@"\([^)]*\)");
musicName = regex.Replace(musicName, string.Empty);
SearchKey = $"{musicName}+{artistName}";
SearchKey = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8);
Limit = limit;
}
}

View File

@ -4,11 +4,11 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
{
public class SongSearchResponse
{
[JsonProperty("result")] public InnerListItemModel Items { get; set; } = null!;
[JsonProperty("result")] public InnerListItemModel Items { get; set; }
[JsonProperty("code")] public int StatusCode { get; set; }
public long GetFirstMatchSongId(string songName, long? duration)
public int GetFirstMatchSongId(string songName, long? duration)
{
var perfectMatch = Items.SongItems.FirstOrDefault(x => x.Name == songName);
if (perfectMatch != null)
@ -27,7 +27,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
public class InnerListItemModel
{
[JsonProperty("songs")] public IList<SongModel> SongItems { get; set; } = null!;
[JsonProperty("songs")] public IList<SongModel> SongItems { get; set; }
[JsonProperty("songCount")] public int SongCount { get; set; }
}
@ -38,25 +38,25 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
/// 歌曲的名称。
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
public string Name { get; set; }
/// <summary>
/// 歌曲的 Sid (Song Id)。
/// </summary>
[JsonProperty("id")]
public long Id { get; set; }
public int Id { get; set; }
/// <summary>
/// 歌曲的演唱者。
/// </summary>
[JsonProperty("artists")]
public IList<SongArtistModel>? Artists { get; set; }
public IList<SongArtistModel> Artists { get; set; }
/// <summary>
/// 歌曲的专辑信息。
/// </summary>
[JsonProperty("album")]
public SongAlbumModel? Album { get; set; }
public SongAlbumModel Album { get; set; }
/// <summary>
/// 歌曲的实际长度。
@ -71,7 +71,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
/// 歌手/艺术家的名称。
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
public string Name { get; set; }
}
public class SongAlbumModel
@ -80,12 +80,12 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
/// 专辑的名称。
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
public string Name { get; set; }
/// <summary>
/// 专辑图像的 Url 地址。
/// </summary>
[JsonProperty("img1v1Url")]
public string? PictureUrl { get; set; }
public string PictureUrl { get; set; }
}
}

View File

@ -2,7 +2,6 @@ using System.Net.Http.Headers;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using ZonyLrcTools.Common.Configuration;
using ZonyLrcTools.Common.Infrastructure.Encryption;
using ZonyLrcTools.Common.Infrastructure.Exceptions;
using ZonyLrcTools.Common.Infrastructure.Network;
using ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel;
@ -17,10 +16,11 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
private readonly ILyricsItemCollectionFactory _lyricsItemCollectionFactory;
private readonly GlobalOptions _options;
private const string NetEaseSearchMusicUrl = @"https://music.163.com/weapi/search/get";
private const string NetEaseGetLyricUrl = @"https://music.163.com/weapi/song/lyric?csrf_token=";
private const string NetEaseSearchMusicUrl = @"https://music.163.com/api/search/get/web";
private const string NetEaseGetLyricUrl = @"https://music.163.com/api/song/lyric";
private const string NetEaseRequestReferer = @"https://music.163.com";
private const string NetEaseRequestContentType = @"application/x-www-form-urlencoded";
public NetEaseLyricsProvider(IWarpHttpClient warpHttpClient,
ILyricsItemCollectionFactory lyricsItemCollectionFactory,
@ -33,30 +33,25 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
protected override async ValueTask<object> DownloadDataAsync(LyricsProviderArgs args)
{
var secretKey = NetEaseMusicEncryptionHelper.CreateSecretKey(16);
var encSecKey = NetEaseMusicEncryptionHelper.RsaEncode(secretKey);
var searchResult = await _warpHttpClient.PostAsync<SongSearchResponse>(NetEaseSearchMusicUrl,
requestOption: request =>
var searchResult = await _warpHttpClient.PostAsync<SongSearchResponse>(
NetEaseSearchMusicUrl,
new SongSearchRequest(args.SongName, args.Artist, _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth),
true,
msg =>
{
request.Headers.Referrer = new Uri(NetEaseRequestReferer);
request.Content = new FormUrlEncodedContent(HandleRequest(
new SongSearchRequest(args.SongName, args.Artist, _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth),
secretKey,
encSecKey));
msg.Headers.Referrer = new Uri(NetEaseRequestReferer);
if (msg.Content != null)
{
msg.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(NetEaseRequestContentType);
}
});
ValidateSongSearchResponse(searchResult, args);
return await _warpHttpClient.PostAsync(NetEaseGetLyricUrl,
requestOption: request =>
{
request.Headers.Referrer = new Uri(NetEaseRequestReferer);
request.Content = new FormUrlEncodedContent(HandleRequest(
new GetLyricRequest(searchResult.GetFirstMatchSongId(args.SongName, args.Duration)),
secretKey,
encSecKey));
});
return await _warpHttpClient.GetAsync(
NetEaseGetLyricUrl,
new GetLyricRequest(searchResult.GetFirstMatchSongId(args.SongName, args.Duration)),
msg => msg.Headers.Referrer = new Uri(NetEaseRequestReferer));
}
protected override async ValueTask<LyricsItemCollection> GenerateLyricAsync(object lyricsObject, LyricsProviderArgs args)
@ -76,7 +71,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
return _lyricsItemCollectionFactory.Build(
json.OriginalLyric.Text,
json.TranslationLyric?.Text);
json.TranslationLyric.Text);
}
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricsProviderArgs args)
@ -86,23 +81,10 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args);
}
if (response.Items is not { SongCount: > 0 })
if (response.Items?.SongCount <= 0)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
}
}
private Dictionary<string, string> HandleRequest(object srcParams, string secretKey, string encSecKey)
{
return new Dictionary<string, string>
{
{
"params", NetEaseMusicEncryptionHelper.AesEncode(
NetEaseMusicEncryptionHelper.AesEncode(
JsonConvert.SerializeObject(srcParams), NetEaseMusicEncryptionHelper.Nonce), secretKey)
},
{ "encSecKey", encSecKey }
};
}
}
}

View File

@ -16,6 +16,10 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.QQMusic.JsonModel
[JsonProperty("g_tk")] public int Gtk { get; set; }
protected GetLyricRequest()
{
}
public GetLyricRequest(string? songId)
{
IsNoBase64Encoding = 1;

View File

@ -19,8 +19,8 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.QQMusic.JsonModel
public string Platform { get; protected set; }
[JsonProperty("key")]
public string Keyword { get; protected set; } = null!;
public string Keyword { get; protected set; }
protected SongSearchRequest()
{
Format = "json";

View File

@ -6,21 +6,21 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.QQMusic.JsonModel
{
[JsonProperty("code")] public int StatusCode { get; set; }
[JsonProperty("data")] public QQMusicInnerDataModel? Data { get; set; }
[JsonProperty("data")] public QQMusicInnerDataModel Data { get; set; }
}
public class QQMusicInnerDataModel
{
[JsonProperty("song")] public QQMusicInnerSongModel? Song { get; set; }
[JsonProperty("song")] public QQMusicInnerSongModel Song { get; set; }
}
public class QQMusicInnerSongModel
{
[JsonProperty("itemlist")] public List<QQMusicInnerSongItem>? SongItems { get; set; }
[JsonProperty("itemlist")] public List<QQMusicInnerSongItem> SongItems { get; set; }
}
public class QQMusicInnerSongItem
{
[JsonProperty("mid")] public string? SongId { get; set; }
[JsonProperty("mid")] public string SongId { get; set; }
}
}

View File

@ -35,7 +35,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.QQMusic
ValidateSongSearchResponse(searchResult, args);
return await _warpHttpClient.GetAsync(QQGetLyricUrl,
new GetLyricRequest(searchResult.Data?.Song?.SongItems?.FirstOrDefault()?.SongId),
new GetLyricRequest(searchResult.Data.Song.SongItems.FirstOrDefault()?.SongId),
op => op.Headers.Referrer = new Uri(QQMusicRequestReferer));
}
@ -57,15 +57,15 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.QQMusic
}
var lyricJsonObj = JObject.Parse(lyricJsonString);
var sourceLyric = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(lyricJsonObj.SelectToken("$.lyric")!.Value<string>()));
var translateLyric = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(lyricJsonObj.SelectToken("$.trans")!.Value<string>()));
var sourceLyric = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(lyricJsonObj.SelectToken("$.lyric").Value<string>()));
var translateLyric = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(lyricJsonObj.SelectToken("$.trans").Value<string>()));
return _lyricsItemCollectionFactory.Build(sourceLyric, translateLyric);
}
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricsProviderArgs args)
{
if (response is not { StatusCode: 0 } || response.Data?.Song?.SongItems == null)
if (response is not { StatusCode: 0 } || response.Data.Song.SongItems == null)
{
throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args);
}

View File

@ -24,7 +24,7 @@ namespace ZonyLrcTools.Common.MusicDecryption
await file.CopyToAsync(buffer);
using var decrypto = DecryptoFactory.Create(buffer, Path.GetFileName(filePath), message => { });
var outFileName = (await decrypto.DecryptAsync()).NewName;
var outFileName = decrypto.Decrypt().NewName;
var outFilePath = Path.Combine(Path.GetDirectoryName(filePath)!, outFileName);
if (!File.Exists(outFilePath))

View File

@ -1,11 +1,9 @@
using System.Text.RegularExpressions;
namespace ZonyLrcTools.Common
{
/// <summary>
/// 歌曲信息的承载类,携带歌曲的相关数据。
/// </summary>
public partial class MusicInfo
public class MusicInfo
{
/// <summary>
/// 歌曲对应的物理文件路径。
@ -32,11 +30,6 @@ namespace ZonyLrcTools.Common
/// </summary>
public bool IsSuccessful { get; set; } = true;
/// <summary>
/// 是否时纯音乐?
/// </summary>
public bool IsPruneMusic { get; set; } = false;
/// <summary>
/// 构建一个新的 <see cref="MusicInfo"/> 对象。
/// </summary>
@ -45,37 +38,9 @@ namespace ZonyLrcTools.Common
/// <param name="artist">歌曲的作者。</param>
public MusicInfo(string filePath, string name, string artist)
{
FilePath = Path.Combine(Path.GetDirectoryName(filePath)!, HandleInvalidFilePath(Path.GetFileName(filePath)));
FilePath = filePath;
Name = name;
Artist = artist;
}
private string HandleInvalidFilePath(string srcText)
{
return InvalidFilePathRegex().Replace(srcText, "");
}
[GeneratedRegex(@"[<>:""/\\|?*]")]
private static partial Regex InvalidFilePathRegex();
public static bool operator ==(MusicInfo? left, MusicInfo? right)
{
if (left is null && right is null)
{
return true;
}
if (left is null || right is null)
{
return false;
}
return left.FilePath == right.FilePath;
}
public static bool operator !=(MusicInfo? left, MusicInfo? right)
{
return !(left == right);
}
}
}

View File

@ -1,53 +0,0 @@
using System.Text;
using Ude;
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
namespace ZonyLrcTools.Common.MusicScanner;
/// <summary>
/// 基于 CSV 文件的音乐信息扫描器。
/// </summary>
public class CsvFileMusicScanner : ITransientDependency
{
/// <summary>
/// 从 Csv 文件中获取需要下载的歌曲信息。
/// </summary>
/// <param name="csvFilePath">CSV 文件的路径。</param>
/// <param name="outputDirectory">歌词文件的输出目录。</param>
/// <param name="pattern">输出的歌词文件格式,默认是 "{Artist} - {Title}.lrc" 的形式。</param>
public async Task<List<MusicInfo>> GetMusicInfoFromCsvFileAsync(string csvFilePath, string outputDirectory,
string pattern)
{
var encoding = DetectFileEncoding(csvFilePath);
var csvFileContent = await File.ReadAllTextAsync(csvFilePath, encoding);
var csvFileLines = csvFileContent.Split([Environment.NewLine], StringSplitOptions.RemoveEmptyEntries);
return csvFileLines.Skip(1).Select(line => GetMusicInfoFromCsvFileLine(line, outputDirectory, pattern))
.ToList();
}
private MusicInfo GetMusicInfoFromCsvFileLine(string csvFileLine, string outputDirectory, string pattern)
{
var csvFileLineItems = csvFileLine.Split(',');
var name = csvFileLineItems[0];
var artist = csvFileLineItems[1];
var fakeFilePath = Path.Combine(outputDirectory, pattern.Replace("{Name}", name).Replace("{Artist}", artist));
var musicInfo = new MusicInfo(fakeFilePath, name, artist);
return musicInfo;
}
private Encoding DetectFileEncoding(string filePath)
{
using var fileStream = File.OpenRead(filePath);
var detector = new CharsetDetector();
detector.Feed(fileStream);
detector.DataEnd();
if (detector.Charset != null)
{
return Encoding.GetEncoding(detector.Charset);
}
return Encoding.Default;
}
}

View File

@ -1,77 +0,0 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ZonyLrcTools.Common.MusicScanner.JsonModel;
public sealed class GetMusicInfoFromNetEaseMusicSongListResponse
{
/// <summary>
/// 请求结果代码,为 200 时请求成功。
/// </summary>
[JsonProperty("code")]
public int Code { get; set; }
/// <summary>
/// 歌单信息。
/// </summary>
[JsonProperty("playlist")]
public PlayListModel? PlayList { get; set; }
}
public sealed class PlayListModel
{
/// <summary>
/// 歌单的歌曲列表。
/// </summary>
[JsonProperty("tracks")]
public ICollection<PlayListSongModel>? SongList { get; set; }
}
public sealed class PlayListSongModel
{
/// <summary>
/// 歌曲的名称。
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
/// <summary>
/// 歌曲的艺术家信息,可能会有多位艺术家/歌手。
/// </summary>
[JsonProperty("ar")]
[JsonConverter(typeof(PlayListSongArtistModelJsonConverter))]
public ICollection<PlayListSongArtistModel>? Artists { get; set; }
}
public sealed class PlayListSongArtistModel
{
/// <summary>
/// 艺术家的名称。
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
}
public class PlayListSongArtistModelJsonConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
var token = JToken.Load(reader);
return token.Type switch
{
JTokenType.Array => token.ToObject(objectType),
JTokenType.Object => new List<PlayListSongArtistModel> { token.ToObject<PlayListSongArtistModel>()! },
_ => null
};
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(ICollection<PlayListSongArtistModel>);
}
}

View File

@ -1,222 +0,0 @@
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using QRCoder;
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
using ZonyLrcTools.Common.Infrastructure.Encryption;
using ZonyLrcTools.Common.Infrastructure.Exceptions;
using ZonyLrcTools.Common.Infrastructure.Network;
using ZonyLrcTools.Common.MusicScanner.JsonModel;
namespace ZonyLrcTools.Common.MusicScanner;
/// <summary>
/// 网易云歌单音乐扫描器,用于从网易云歌单获取需要下载的歌词列表。
/// </summary>
public class NetEaseMusicSongListMusicScanner : ISingletonDependency
{
private readonly IWarpHttpClient _warpHttpClient;
private readonly ILogger<NetEaseMusicSongListMusicScanner> _logger;
private const string Host = "https://music.163.com";
private string Cookie { get; set; } = string.Empty;
private string CsrfToken { get; set; } = string.Empty;
/// <summary>
/// 构建一个新的 <see cref="NetEaseMusicSongListMusicScanner"/> 对象。
/// </summary>
public NetEaseMusicSongListMusicScanner(IWarpHttpClient warpHttpClient,
ILogger<NetEaseMusicSongListMusicScanner> logger)
{
_warpHttpClient = warpHttpClient;
_logger = logger;
}
/// <summary>
/// 从网易云歌单获取需要下载的歌曲列表,调用这个 API 需要用户登录,否则获取的歌单数据不全。
/// </summary>
/// <param name="songListIds">网易云音乐歌单的 ID。</param>
/// <param name="outputDirectory">歌词文件的输出路径。</param>
/// <param name="pattern">输出的歌词文件格式,默认是 "{Artist} - {Title}.lrc" 的形式。</param>
/// <returns>返回获取到的歌曲列表。</returns>
public async Task<List<MusicInfo>> GetMusicInfoFromNetEaseMusicSongListAsync(string songListIds, string outputDirectory, string pattern)
{
if (string.IsNullOrEmpty(Cookie))
{
var loginResponse = await LoginViqQrCodeAsync();
Cookie = loginResponse.cookieContainer?.GetCookieHeader(new Uri(Host)) ?? string.Empty;
CsrfToken = loginResponse.csrfToken ?? string.Empty;
}
async Task<List<MusicInfo>> GetMusicInfoBySongIdAsync(string songId)
{
var secretKey = NetEaseMusicEncryptionHelper.CreateSecretKey(16);
var encSecKey = NetEaseMusicEncryptionHelper.RsaEncode(secretKey);
var response = await _warpHttpClient.PostAsync<GetMusicInfoFromNetEaseMusicSongListResponse>(
$"{Host}/weapi/v6/playlist/detail?csrf_token={CsrfToken}", requestOption:
request =>
{
request.Headers.Add("Cookie", Cookie);
request.Content = new FormUrlEncodedContent(HandleRequest(new
{
csrf_token = CsrfToken,
id = songId,
n = 1000,
offset = 0,
total = true,
limit = 1000,
}, secretKey, encSecKey));
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
});
if (response.Code != 200 || response.PlayList?.SongList == null)
{
throw new ErrorCodeException(ErrorCodes.NotSupportedFileEncoding);
}
return response.PlayList.SongList
.Where(song => !string.IsNullOrEmpty(song.Name))
.Select(song =>
{
var artistName = song.Artists?.FirstOrDefault()?.Name ?? string.Empty;
var fakeFilePath = Path.Combine(outputDirectory, pattern.Replace("{Name}", song.Name).Replace("{Artist}", artistName));
return new MusicInfo(fakeFilePath, song.Name!, artistName);
}).ToList();
}
var musicInfoList = new List<MusicInfo>();
foreach (var songListId in songListIds.Split(';'))
{
_logger.LogInformation("正在获取歌单 {SongListId} 的歌曲列表。", songListId);
var musicInfos = await GetMusicInfoBySongIdAsync(songListId);
musicInfoList.AddRange(musicInfos);
}
return musicInfoList;
}
/// <summary>
/// 用于加密请求参数,具体加密算法请参考网易云音乐的 JS 代码。
/// </summary>
/// <param name="srcParams"></param>
/// <param name="secretKey"></param>
/// <param name="encSecKey"></param>
/// <returns></returns>
private Dictionary<string, string> HandleRequest(object srcParams, string secretKey, string encSecKey)
{
return new Dictionary<string, string>
{
{
"params", NetEaseMusicEncryptionHelper.AesEncode(
NetEaseMusicEncryptionHelper.AesEncode(
JsonConvert.SerializeObject(srcParams), NetEaseMusicEncryptionHelper.Nonce), secretKey)
},
{ "encSecKey", encSecKey }
};
}
/// <summary>
/// 通过二维码登录网易云音乐,登录成功后返回 Cookie 和 CSRF Token。
/// </summary>
private async Task<(string? csrfToken, CookieContainer? cookieContainer)> LoginViqQrCodeAsync()
{
// Get unikey.
var qrCodeKeyJson = await (await PostAsync($"{Host}/weapi/login/qrcode/unikey", new
{
type = 1
})).Content.ReadAsStringAsync();
var uniKey = JObject.Parse(qrCodeKeyJson).SelectToken("$.unikey")!.Value<string>();
if (string.IsNullOrEmpty(uniKey)) return (null, null);
// Generate QR code.
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode($"{Host}/login?codekey={uniKey}",
QRCodeGenerator.ECCLevel.L);
var qrCode = new AsciiQRCode(qrCodeData);
var asciiQrCodeString = qrCode.GetGraphic(1, drawQuietZones: false);
_logger.LogInformation("请使用网易云 APP 扫码登录:");
_logger.LogInformation("\n{AsciiQrCodeString}", asciiQrCodeString);
// Wait for login success.
var isLogin = false;
while (!isLogin)
{
var (isSuccess, cookieContainer) = await CheckIsLoginAsync(uniKey);
isLogin = isSuccess;
if (!isLogin)
{
await Task.Delay(2000);
}
else
{
return (cookieContainer?.GetCookies(new Uri(Host))["__csrf"]?.Value, cookieContainer);
}
}
return (null, null);
}
/// <summary>
/// 使用 <paramref name="uniKey"/> 检测是否登录成功。
/// </summary>
/// <param name="uniKey">由网易云 API 生成的唯一 Key用于登录。</param>
/// <returns>
/// 当登录成功的时候,元组 <c>isSuccess</c> 会为 true<c>cookieContainer</c> 会包含登录成功后的 Cookie。<br/>
/// 如果登录失败,<c>isSuccess</c> 会为 false<c>cookieContainer</c> 会为 null。
/// </returns>
private async Task<(bool isSuccess, CookieContainer? cookieContainer)> CheckIsLoginAsync(string uniKey)
{
var responseMessage = await PostAsync($"{Host}/weapi/login/qrcode/client/login", new
{
key = uniKey,
type = 1
});
var responseString = await responseMessage.Content.ReadAsStringAsync();
var responseCode = JObject.Parse(responseString)["code"]?.Value<int>();
if (responseCode != 803)
{
return (false, null);
}
if (!responseMessage.Headers.TryGetValues("Set-Cookie", out var cookies))
{
return (false, null);
}
var cookieContainer = new CookieContainer();
foreach (var cookie in cookies)
{
cookieContainer.SetCookies(new Uri(Host), cookie);
}
return (true, cookieContainer);
}
/// <summary>
/// 封装了网易云音乐的加密请求方式。
/// </summary>
/// <param name="url">需要请求的网易云音乐 API 地址。</param>
/// <param name="params">API 请求参数。</param>
/// <returns>
/// 正常情况下会返回一个 <see cref="HttpResponseMessage"/> 对象。
/// </returns>
private async Task<HttpResponseMessage> PostAsync(string url, object @params)
{
var secretKey = NetEaseMusicEncryptionHelper.CreateSecretKey(16);
var encSecKey = NetEaseMusicEncryptionHelper.RsaEncode(secretKey);
return await _warpHttpClient.PostReturnHttpResponseAsync(url, requestOption:
request =>
{
request.Content = new FormUrlEncodedContent(HandleRequest(@params, secretKey, encSecKey));
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
});
}
}

View File

@ -22,11 +22,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
_wordsDictionary = new Lazy<Dictionary<string, string>>(() =>
{
var jsonData = File.ReadAllText(_options.Provider.Tag.BlockWord.FilePath);
return JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonData) ?? throw new InvalidOperationException("屏蔽词字典文件格式错误。");
return JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonData);
});
}
public string? GetValue(string key)
public string GetValue(string key)
{
if (_wordsDictionary.Value.TryGetValue(key, out var value))
{

View File

@ -25,7 +25,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
_options = options.Value;
}
public async ValueTask<MusicInfo?> LoadAsync(string filePath)
public async ValueTask<MusicInfo> LoadAsync(string filePath)
{
await ValueTask.CompletedTask;

View File

@ -13,6 +13,6 @@
/// </remarks>
/// <param name="key">原始单词。</param>
/// <returns>原始单词对应的屏蔽词。</returns>
string? GetValue(string key);
string GetValue(string key);
}
}

View File

@ -18,6 +18,6 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
/// </summary>
/// <param name="filePath">歌曲文件的路径。</param>
/// <returns>加载完成的歌曲信息。</returns>
ValueTask<MusicInfo?> LoadAsync(string filePath);
ValueTask<MusicInfo> LoadAsync(string filePath);
}
}

View File

@ -14,7 +14,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
public string Name => ConstantName;
public const string ConstantName = "Taglib";
public async ValueTask<MusicInfo?> LoadAsync(string filePath)
public async ValueTask<MusicInfo> LoadAsync(string filePath)
{
try
{
@ -30,7 +30,12 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
await ValueTask.CompletedTask;
return songName == null ? null : new MusicInfo(filePath, songName, songArtist);
if (songName == null && songArtist == null)
{
return null;
}
return new MusicInfo(filePath, songName, songArtist);
}
catch (Exception ex)
{

View File

@ -23,11 +23,6 @@ public class DefaultUpdater : IUpdater, ISingletonDependency
public async Task CheckUpdateAsync()
{
if (!IsCheckUpdate())
{
return;
}
var response = await _warpHttpClient.GetAsync<NewVersionResponse?>(UpdateUrl);
if (response == null)
{
@ -41,7 +36,7 @@ public class DefaultUpdater : IUpdater, ISingletonDependency
}
var importantItem = response.Items?.FirstOrDefault(x => x.ItemType == NewVersionItemType.Important);
if (importantItem?.Url != null)
if (importantItem != null)
{
_logger.LogWarning($"发现了新版本,请点击下面的链接进行更新:{importantItem.Url}");
_logger.LogWarning($"最新版本号:{response.NewVersion},当前版本号: ${currentVersion}");
@ -61,27 +56,4 @@ public class DefaultUpdater : IUpdater, ISingletonDependency
}
}
}
private bool IsCheckUpdate()
{
var lockFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "update.lock");
if (!File.Exists(lockFile))
{
File.WriteAllText(lockFile, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
return true;
}
if (long.TryParse(File.ReadAllText(lockFile), out var time))
{
var now = DateTimeOffset.Now.ToUnixTimeSeconds();
if (now - time <= 86400 /* 1 Day */)
{
return false;
}
}
File.WriteAllText(lockFile, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
return true;
}
}

View File

@ -1,26 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>4.0.0.50</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions"/>
<PackageReference Include="MusicDecrypto.Library"/>
<PackageReference Include="Newtonsoft.Json"/>
<PackageReference Include="NetEscapades.Configuration.Yaml"/>
<PackageReference Include="Polly"/>
<PackageReference Include="QRCoder"/>
<PackageReference Include="TagLibSharp"/>
<PackageReference Include="Ude.NetStandard" />
<PackageReference Include="YamlDotNet" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Lyrics\Providers\Kugeci\KugeciDownloader.cs"/>
<Compile Remove="Lyrics\Providers\Kugeci\KugeciDownloader.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\vendor\MusicDecrypto\MusicDecrypto.Library\MusicDecrypto.Library.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace ZonyLrcTools.LocalServer.Contract.Dtos;
public class PagedListRequestDto
{
public int PageIndex { get; set; }
public int PageSize { get; set; }
}

View File

@ -0,0 +1,9 @@
namespace ZonyLrcTools.LocalServer.Contract.Dtos;
public class PagedListResultDto<T>
{
public int TotalCount { get; set; }
public int PageIndex { get; set; }
public int PageSize { get; set; }
public List<T> Items { get; set; } = new List<T>();
}

View File

@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
using ZonyLrcTools.LocalServer.Contract.Dtos;
using ZonyLrcTools.LocalServer.Services.MusicInfo;
using ZonyLrcTools.LocalServer.Services.MusicInfo.Dtos;
namespace ZonyLrcTools.LocalServer.Controllers;
[Route("api/music-infos")]
public class MusicInfoController : Controller, IMusicInfoService, ITransientDependency
{
private readonly IMusicInfoService _musicInfoService;
public MusicInfoController(IMusicInfoService musicInfoService)
{
_musicInfoService = musicInfoService;
}
[HttpGet]
public Task<PagedListResultDto<MusicInfoListItemDto>> GetMusicInfoListAsync(MusicInfoListInput input)
{
return _musicInfoService.GetMusicInfoListAsync(input);
}
}

View File

@ -0,0 +1,15 @@
using SuperSocket.WebSocket.Server;
namespace ZonyLrcTools.LocalServer.EventBus;
public class SuperSocketListener
{
public async Task ListenAsync()
{
var host = WebSocketHostBuilder.Create()
.UseWebSocketMessageHandler(async (session, message) => { await session.SendAsync(message); })
.Build();
await host.StartAsync();
}
}

View File

@ -0,0 +1,66 @@
using System.Diagnostics;
using System.Reflection;
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
using ZonyLrcTools.LocalServer.EventBus;
#region Main Flow
var app = RegisterAndConfigureServices();
await ListenServices();
#endregion
#region Configure Services
async Task ListenServices()
{
await new SuperSocketListener().ListenAsync();
await app?.RunAsync()!;
}
WebApplication? RegisterAndConfigureServices()
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(k => k.ListenAnyIP(50002));
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.BeginAutoDependencyInject<Program>();
var insideApp = builder.Build();
insideApp.UseSpaStaticFiles(new StaticFileOptions
{
RequestPath = "",
FileProvider = new Microsoft.Extensions.FileProviders
.ManifestEmbeddedFileProvider(
Assembly.GetExecutingAssembly(), "UiStaticResources"
)
});
insideApp.MapControllers();
#if !DEBUG
insideApp.Lifetime.ApplicationStarted.Register(OpenBrowser);
#endif
return insideApp;
}
void OpenBrowser()
{
const string url = "http://localhost:50002/index.html";
if (OperatingSystem.IsWindows())
{
Process.Start("explorer.exe", url);
}
else if (OperatingSystem.IsMacOS())
{
Process.Start("open", url);
}
else if (OperatingSystem.IsLinux())
{
Process.Start("xdg-open", url);
}
}
#endregion

View File

@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"ZonyLrcTools.LocalServer": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:50002",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,16 @@
using ZonyLrcTools.LocalServer.Contract.Dtos;
namespace ZonyLrcTools.LocalServer.Services.MusicInfo.Dtos;
public class MusicInfoListItemDto
{
public string Name { get; set; }
public int Size { get; set; }
public int Status { get; set; }
}
public class MusicInfoListInput : PagedListRequestDto
{
}

View File

@ -0,0 +1,9 @@
using ZonyLrcTools.LocalServer.Contract.Dtos;
using ZonyLrcTools.LocalServer.Services.MusicInfo.Dtos;
namespace ZonyLrcTools.LocalServer.Services.MusicInfo;
public interface IMusicInfoService
{
Task<PagedListResultDto<MusicInfoListItemDto>> GetMusicInfoListAsync(MusicInfoListInput input);
}

View File

@ -0,0 +1,38 @@
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
using ZonyLrcTools.LocalServer.Contract.Dtos;
using ZonyLrcTools.LocalServer.Services.MusicInfo.Dtos;
namespace ZonyLrcTools.LocalServer.Services.MusicInfo;
public class MusicInfoService : ITransientDependency, IMusicInfoService
{
public async Task<PagedListResultDto<MusicInfoListItemDto>> GetMusicInfoListAsync(MusicInfoListInput input)
{
await Task.CompletedTask;
return new PagedListResultDto<MusicInfoListItemDto>
{
Items = new List<MusicInfoListItemDto>
{
new MusicInfoListItemDto
{
Name = "测试歌曲",
Size = 1024,
Status = 1
},
new MusicInfoListItemDto
{
Name = "测试歌曲2",
Size = 1024,
Status = 1
},
new MusicInfoListItemDto
{
Name = "测试歌曲3",
Size = 1024,
Status = 1
},
}
};
}
}

View File

@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.9" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="6.0.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SuperSocket.WebSocket" Version="2.0.0-beta.11" />
<PackageReference Include="SuperSocket.WebSocket.Server" Version="2.0.0-beta.11" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="UiStaticResources\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj" />
</ItemGroup>
<!-- <ItemGroup>-->
<!-- <ProjectReference Include="..\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />-->
<!-- </ItemGroup>-->
</Project>

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,18 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"serverOptions": {
"name": "ZonyLRcToolsServer",
"listeners": [
{
"ip": "Any",
"port": 50001
}
]
}
}

3
src/ui/.browserslistrc Normal file
View File

@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead

213
src/ui/.gitignore vendored Normal file
View File

@ -0,0 +1,213 @@
### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
### Vue template
# gitignore template for Vue.js projects
#
# Recommended template: Node.gitignore
# TODO: where does this rule come from?
docs/_book
# TODO: where does this rule come from?
test/

19
src/ui/README.md Normal file
View File

@ -0,0 +1,19 @@
# ui
## Project setup
```
yarn install
```
### Compiles and hot-reloads for development
```
yarn serve
```
### Compiles and minifies for production
```
yarn build
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

5
src/ui/babel.config.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

19
src/ui/jsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}

28
src/ui/package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "ui",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"axios": "^1.1.3",
"core-js": "^3.8.3",
"vue": "^2.6.14",
"vue-router": "^3.5.1",
"vuetify": "^2.6.0",
"vuex": "^3.6.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0",
"@vue/cli-plugin-vuex": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"sass": "^1.32.7",
"sass-loader": "^12.0.0",
"vue-cli-plugin-vuetify": "~2.5.8",
"vue-template-compiler": "^2.6.14",
"vuetify-loader": "^1.7.0"
}
}

BIN
src/ui/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

19
src/ui/public/index.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

80
src/ui/src/App.vue Normal file
View File

@ -0,0 +1,80 @@
<template>
<v-app id="inspire">
<v-navigation-drawer
v-model="drawer"
app
>
<v-sheet
color="grey lighten-4"
class="pa-4"
>
<div>ZonyLrcTools-X</div>
</v-sheet>
<v-divider></v-divider>
<v-list>
<v-list-item
v-for="[icon, text, to] in links"
:key="icon"
:to="to"
link
>
<v-list-item-icon>
<v-icon>{{ icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ text }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-navigation-drawer>
<v-app-bar app>
<v-app-bar-nav-icon @click="drawer = !drawer"></v-app-bar-nav-icon>
<v-toolbar-title>ZonyLrcToolsX</v-toolbar-title>
</v-app-bar>
<v-main>
<v-container
class="py-8 px-6"
fluid
>
<router-view></router-view>
</v-container>
</v-main>
</v-app>
</template>
<script>
import Socket from "@/communication/socket";
import {mapMutations} from "vuex"
export default {
data: () => ({
drawer: null,
links: [
['mdi-play-circle', '开始', '/'],
['mdi-multiplication-box', '设置', '/setting'],
['mdi-information', '关于', '/about'],
],
}),
created() {
Socket.$on("message", this.handleGetMessage);
},
beforeDestroy() {
Socket.$off("message", this.handleGetMessage);
},
methods: {
...mapMutations({
setWsRes: "ws/setWsRes",
}),
handleGetMessage(msg) {
this.setWsRes(JSON.parse(msg));
}
}
}
</script>

BIN
src/ui/src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 87.5 100"><defs><style>.cls-1{fill:#1697f6;}.cls-2{fill:#7bc6ff;}.cls-3{fill:#1867c0;}.cls-4{fill:#aeddff;}</style></defs><title>Artboard 46</title><polyline class="cls-1" points="43.75 0 23.31 0 43.75 48.32"/><polygon class="cls-2" points="43.75 62.5 43.75 100 0 14.58 22.92 14.58 43.75 62.5"/><polyline class="cls-3" points="43.75 0 64.19 0 43.75 48.32"/><polygon class="cls-4" points="64.58 14.58 87.5 14.58 43.75 100 43.75 62.5 64.58 14.58"/></svg>

After

Width:  |  Height:  |  Size: 539 B

Some files were not shown because too many files have changed in this diff Show More