Skip to content

Change input value type from string to vec for better supporting multivalued tag #634

@Linxuanhua1

Description

@Linxuanhua1

Summary

We now have a multivalued artist tag as shown below that needs to be written.
["小倉朝陽", 遥うみ", 八日堂朔莉", 坂リリ", 大蔵瑠美音", 遥そら", 桜小路亜十礼", "川崎美鳥"]
Under the current model, this is the only way we can write it.

let artists = vec!["小倉朝陽", "遥うみ", "八日堂朔莉", "坂リリ", "大蔵瑠美音", "遥そら", "桜小路亜十礼", "川崎美鳥"];

for artist in artists {
    source_tag.push("TrackArtist".to_string(), artist.to_string());
}

If we want to know if the original tag and the written tag are duplicates, we need to read them first and then make the judgment.

let artists = vec!["小倉朝陽", "遥うみ", "八日堂朔莉", "坂リリ", "大蔵瑠美音", "遥そら", "桜小路亜十礼", "川崎美鳥"];
let original_artists = source_tag.get_all("TrackArtist");
    
for original_artist in original_artists {
    if artists.contains(&original_artist) {
        ...
    }
}

If we change the input value into vec, we could parse the value like this. And the set mode is to overwrite, you will not care about whether the value is in original tag.

let artists = vec!["小倉朝陽", "遥うみ", "八日堂朔莉", "坂リリ", "大蔵瑠美音", "遥そら", "桜小路亜十礼", "川崎美鳥"];
source_tag.set_trackartist(&artists);

or

source_tag.set("TrackArtist".to_string(), &artists);

Moreover, there's the need to distinguish between single and multiple values, because even a single value can be passed into the vec, as is shown below.

let artists = vec!["小倉朝陽"];
source_tag.set_trackartist(&artists);

This change also allows for a unified external interface.

API design

pub fn set(&mut self, item_key: ItemKey, values: Vec<ItemValue>) {
        ....
}

Use this new api to instead the old api.

remove

pub fn insert()
pub fn insert_unchecked()
pub fn push()
pub fn push_unchecked()

Maybe it will remove more methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions