xenzh / lastfm-parse-rs

Collection of Lastfm API data types in Rust
https://xenzh.github.io/lastfm-parse-rs/
MIT License
1 stars 1 forks source link

Deserialization failed for user::GetRecentTracks #4

Open vervaekejonathan opened 4 years ago

vervaekejonathan commented 4 years ago
        let url = user::GetRecentTracks::request(
            BASE_URL,
            API_KEY,
            None,
            None,
            user,
            None, 
            None, 
            None,
            None,
            None,
        ).get_url().unwrap();
        let mut data : Vec<u8> = Vec::new();
        get_data::<user::GetRecentTracks>(url, &mut data);
        match from_json_slice(data) {
            Ok(info ) => action(info),
            Err(err) => { println!("{}", err)},
        };

Compile output:

Deserialization failed, reason: missing field name at line 1 column 200

vervaekejonathan commented 4 years ago

Do you have an idea on how this issue can be fixed?

xenzh commented 4 years ago

Sorry for the delay, I'm usually busy during the week.

So the reason for this one is, one of the recent track entries in last.fm response didn't contain a field called name - either for the track itself, or the artist, or the album. Having a track with no name makes little sense, so I'd suspect one of the latter.

I'm thinking of making a small patch to mark artist and album as optional, do you mind testing it before I merge? Alternatively, you could confirm from raw json if one of the recept tracks you've got has this problem.

xenzh commented 4 years ago

And here's the patch branch: optional-names

As far as I understand you can test it by adding following lines to your Cargo.toml:

[patch.'https://github.com/xenzh/lastfm-parse-rs']
lastfm-parse-rs = { git = 'https://github.com/xenzh/lastfm-parse-rs', branch = 'optional-names' }
vervaekejonathan commented 4 years ago

Sorry for the late reply, it still does not work and I'm trying to figure it out, but still no result :) Would you have tips for debugging it ?

The data that is inserted into the from_json_slice function looks like this:

{"recenttracks":{"@attr":{"page":"1","total":"220979","user":"Festhead","perPage":"1","totalPages":"220979"},"track":[{"artist":{"mbid":"","#text":"Childish Gambino"},"@attr":{"nowplaying":"true"},"mbid":"","album":{"mbid":"","#text":"3.15.20"},"streamable":"0","url":"https:\/\/www.last.fm\/music\/Childish+Gambino\/\/0.00","name":"0.00","image":[{"size":"small","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/34s\/d2761d589b3f0255213d2d0def8d8681.jpg"},{"size":"medium","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/64s\/d2761d589b3f0255213d2d0def8d8681.jpg"},{"size":"large","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/174s\/d2761d589b3f0255213d2d0def8d8681.jpg"},{"size":"extralarge","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/300x300\/d2761d589b3f0255213d2d0def8d8681.jpg"}]},{"artist":{"mbid":"","#text":"The Flaming Lips"},"album":{"mbid":"472fed21-00bc-3b35-842b-f8a44a8b9678","#text":"The Soft Bulletin"},"image":[{"size":"small","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/34s\/b6606579390247959e2a6dcd3463179c.png"},{"size":"medium","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/64s\/b6606579390247959e2a6dcd3463179c.png"},{"size":"large","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/174s\/b6606579390247959e2a6dcd3463179c.png"},{"size":"extralarge","#text":"https:\/\/lastfm.freetls.fastly.net\/i\/u\/300x300\/b6606579390247959e2a6dcd3463179c.png"}],"streamable":"0","date":{"uts":"1584885733","#text":"22 Mar 2020, 14:02"},"url":"https:\/\/www.last.fm\/music\/The+Flaming+Lips\/\/Race+for+the+Prize+-+2017+Remaster","name":"Race for the Prize - 2017 Remaster","mbid":""}]}}

vervaekejonathan commented 4 years ago

Ok, some progress, it seems that this line needs Id1 instead of Id2

https://github.com/xenzh/lastfm-parse-rs/blob/master/src/structs/user.rs#L566