Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions src/id3/v1/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions src/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down