Tags: Improve handling of Year tag

This commit is contained in:
Serial 2023-01-08 15:52:42 -05:00 committed by Alex
parent f63afb2046
commit a6b114b2e4
3 changed files with 25 additions and 6 deletions

View file

@ -30,6 +30,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- All of the format-specific features have been removed, as they served no purpose. They used to bring in
optional dependencies, but they have long since been removed.
### Fixed
- **Tag**: Handling of the `Year` tag has been improved.
- Previously, setting a year with `Tag::set_year` required a `RecordingDate`. Now it will check if the format
supports the `Year` tag, and if not, then it will set a `RecordingDate`.
## [0.10.0] - 2022-12-27
### Added

View file

@ -258,13 +258,18 @@ impl From<ID3v1Tag> for Tag {
}
impl From<Tag> for ID3v1Tag {
fn from(input: Tag) -> Self {
fn from(mut input: Tag) -> Self {
let title = input.take_strings(&ItemKey::TrackTitle).next();
let artist = input.take_strings(&ItemKey::TrackArtist).next();
let album = input.take_strings(&ItemKey::AlbumTitle).next();
let year = input.year().map(|y| y.to_string());
let comment = input.take_strings(&ItemKey::Comment).next();
Self {
title: input.get_string(&ItemKey::TrackTitle).map(str::to_owned),
artist: input.get_string(&ItemKey::TrackArtist).map(str::to_owned),
album: input.get_string(&ItemKey::AlbumTitle).map(str::to_owned),
year: input.get_string(&ItemKey::Year).map(str::to_owned),
comment: input.get_string(&ItemKey::Comment).map(str::to_owned),
title,
artist,
album,
year,
comment,
track_number: input
.get_string(&ItemKey::TrackNumber)
.map(|g| g.parse::<u8>().ok())

View file

@ -204,8 +204,17 @@ impl Accessor for Tag {
if item.len() >= 4 {
let (_, remaining) = item.split_at(4);
self.insert_text(ItemKey::RecordingDate, format!("{value}{remaining}"));
return;
}
}
// Some formats have a dedicated item for `Year`, others just have it as
// a part of `RecordingDate`
if ItemKey::Year.map_key(self.tag_type, false).is_some() {
self.insert_text(ItemKey::Year, value.to_string());
} else {
self.insert_text(ItemKey::RecordingDate, value.to_string());
}
}
fn remove_year(&mut self) {