From e7168a2fe62335eaaa7a4965b66d96a79aa2bd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Wed, 12 Nov 2025 14:28:26 +0800 Subject: [PATCH] 1 --- docker-compose.yml | 1 + .../Controllers/JobTriggerController.cs | 35 +++++++++++++++++++ src/WebApi/Controllers/NotifyController.cs | 4 --- src/WebApi/WebApi.csproj | 5 +-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7d7f1e6..cc564b9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ - /etc/localtime:/etc/localtime:ro - /wd/media/tv:/data/media/tv:rw - /wd/media/anime:/data/media/anime:rw + - /wd/media/music:/data/media/music:rw - /wd/media/others/anime:/data/media/anime-other:rw - /wd/apps/vols/nas_robot:/app/data:rw - /wd:/host/wd:ro diff --git a/src/WebApi/Controllers/JobTriggerController.cs b/src/WebApi/Controllers/JobTriggerController.cs index 9503f87..0adebbe 100644 --- a/src/WebApi/Controllers/JobTriggerController.cs +++ b/src/WebApi/Controllers/JobTriggerController.cs @@ -88,4 +88,39 @@ public class JobTriggerController : BaseController return "OK"; } + + [HttpGet] + public string MusicTagAsync() + { + var musicPath = "/data/media/music"; + List musicType = ["mp3", "flac", "m4a", "wav", "ape", "ogg", "wma", "alac", "aac", "dsd"]; + + // 递归获取所有音乐文件 + var files = Directory.GetFiles(musicPath, "*.*", SearchOption.AllDirectories) + .Where(f => musicType.Contains(Path.GetExtension(f).TrimStart('.').ToLower())) + .ToList(); + + foreach (var file in files) + { + _logger.LogInformation("Processing music file: {file}", file); + + try + { + var fileTag = TagLib.File.Create(file); + var artist = fileTag.Tag.FirstPerformer ?? "未知艺术家"; + var album = fileTag.Tag.Album ?? "未知专辑"; + var title = fileTag.Tag.Title ?? Path.GetFileNameWithoutExtension(file); + var year = fileTag.Tag.Year > 0 ? fileTag.Tag.Year.ToString() : "未知年份"; + var genre = fileTag.Tag.FirstGenre ?? "未知风格"; + _logger.LogInformation("Tag info - Artist: {artist}, Album: {album}, Title: {title}, Year: {year}, Genre: {genre}", artist, album, title, year, genre); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + return "OK"; + } } \ No newline at end of file diff --git a/src/WebApi/Controllers/NotifyController.cs b/src/WebApi/Controllers/NotifyController.cs index 9e1fa32..ed50b71 100644 --- a/src/WebApi/Controllers/NotifyController.cs +++ b/src/WebApi/Controllers/NotifyController.cs @@ -7,10 +7,6 @@ namespace WebApi.Controllers; public class NotifyController : BaseController { - public NotifyController() - { - } - [HttpPost] public async Task Radarr() { diff --git a/src/WebApi/WebApi.csproj b/src/WebApi/WebApi.csproj index 0c366c9..693c607 100644 --- a/src/WebApi/WebApi.csproj +++ b/src/WebApi/WebApi.csproj @@ -9,8 +9,9 @@ - - + + +