From e4e7530902860763ff90bdc911a69f0ddb54f523 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 21 Nov 2025 18:36:18 +0900 Subject: [PATCH] common/types: implement serialization helpers for `Tag` --- src/common/types/tag.rs | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/common/types/tag.rs b/src/common/types/tag.rs index f88406b7..9d65db79 100644 --- a/src/common/types/tag.rs +++ b/src/common/types/tag.rs @@ -118,4 +118,86 @@ impl Tag { other => Self::Other(other.to_string(), value), } } + + pub fn key(&self) -> &str { + match self { + Tag::Artist(_) => "Artist", + Tag::ArtistSort(_) => "ArtistSort", + Tag::Album(_) => "Album", + Tag::AlbumSort(_) => "AlbumSort", + Tag::AlbumArtist(_) => "AlbumArtist", + Tag::AlbumArtistSort(_) => "AlbumArtistSort", + Tag::Title(_) => "Title", + Tag::TitleSort(_) => "TitleSort", + Tag::Track(_) => "Track", + Tag::Name(_) => "Name", + Tag::Genre(_) => "Genre", + Tag::Mood(_) => "Mood", + Tag::Date(_) => "Date", + Tag::OriginalDate(_) => "OriginalDate", + Tag::Composer(_) => "Composer", + Tag::ComposerSort(_) => "ComposerSort", + Tag::Performer(_) => "Performer", + Tag::Conductor(_) => "Conductor", + Tag::Work(_) => "Work", + Tag::Ensemble(_) => "Ensemble", + Tag::Movement(_) => "Movement", + Tag::MovementNumber(_) => "MovementNumber", + Tag::ShowMovement(_) => "ShowMovement", + Tag::Location(_) => "Location", + Tag::Grouping(_) => "Grouping", + Tag::Comment(_) => "Comment", + Tag::Disc(_) => "Disc", + Tag::Label(_) => "Label", + Tag::MusicBrainzArtistId(_) => "MusicBrainzArtistId", + Tag::MusicBrainzAlbumId(_) => "MusicBrainzAlbumId", + Tag::MusicBrainzAlbumArtistId(_) => "MusicBrainzAlbumArtistId", + Tag::MusicBrainzTrackId(_) => "MusicBrainzTrackId", + Tag::MusicBrainzReleaseGroupId(_) => "MusicBrainzReleaseGroupId", + Tag::MusicBrainzReleaseTrackId(_) => "MusicBrainzReleaseTrackId", + Tag::MusicBrainzWorkId(_) => "MusicBrainzWorkId", + Tag::Other(key, _) => key, + } + } + + pub fn value(&self) -> &str { + match self { + Tag::Artist(v) + | Tag::ArtistSort(v) + | Tag::Album(v) + | Tag::AlbumSort(v) + | Tag::AlbumArtist(v) + | Tag::AlbumArtistSort(v) + | Tag::Title(v) + | Tag::TitleSort(v) + | Tag::Track(v) + | Tag::Name(v) + | Tag::Genre(v) + | Tag::Mood(v) + | Tag::Date(v) + | Tag::OriginalDate(v) + | Tag::Composer(v) + | Tag::ComposerSort(v) + | Tag::Performer(v) + | Tag::Conductor(v) + | Tag::Work(v) + | Tag::Ensemble(v) + | Tag::Movement(v) + | Tag::MovementNumber(v) + | Tag::ShowMovement(v) + | Tag::Location(v) + | Tag::Grouping(v) + | Tag::Comment(v) + | Tag::Disc(v) + | Tag::Label(v) + | Tag::MusicBrainzArtistId(v) + | Tag::MusicBrainzAlbumId(v) + | Tag::MusicBrainzAlbumArtistId(v) + | Tag::MusicBrainzTrackId(v) + | Tag::MusicBrainzReleaseGroupId(v) + | Tag::MusicBrainzReleaseTrackId(v) + | Tag::MusicBrainzWorkId(v) + | Tag::Other(_, v) => v, + } + } }