Compare commits

...

2 commits

Author SHA1 Message Date
f328062ed0 fix: add track album_id to response model
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-11-20 14:57:32 +01:00
e33219f37d fix: album model (nullable track nr) 2023-11-19 00:06:10 +01:00
7 changed files with 157 additions and 163 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "bandcamp"
version = "0.2.0"
version = "0.3.1"
edition = "2021"
authors = ["ThetaDev <thetadev@magenta.de>"]
license = "MIT"

View file

@ -3,7 +3,7 @@
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, NoneAsEmptyString, VecSkipError};
use serde_with::{serde_as, DefaultOnNull, NoneAsEmptyString, VecSkipError};
use time::OffsetDateTime;
use crate::util;
@ -78,6 +78,7 @@ pub struct Album {
pub release_date: OffsetDateTime,
/// List of album tags (genres and locations)
#[serde(default)]
#[serde_as(deserialize_as = "DefaultOnNull")]
pub tags: Vec<Tag>,
/// List of album tracks
pub tracks: Vec<Track>,
@ -92,14 +93,11 @@ pub struct Track {
pub track_id: u64,
/// Track title
pub title: String,
/// Numeric album id
pub album_id: u64,
/// Album title
#[serde_as(deserialize_as = "NoneAsEmptyString")]
pub album_title: Option<String>,
/// Numeric band id
pub band_id: u64,
/// Band name
/// Track album ID
///
/// Is None for single tracks
pub album_id: Option<u64>,
/// Track artist name (may differ from band name)
#[serde_as(deserialize_as = "NoneAsEmptyString")]
pub band_name: Option<String>,
/// Duration in seconds
@ -112,9 +110,10 @@ pub struct Track {
///
/// `mp3-128` => `https://bandcamp.com/stream_redirect?enc=mp3-128&track_id=4173325157&ts=1686871135&t=a1f7904205e6caca970009ca6744ef0b512f353a`
#[serde(default)]
#[serde_as(deserialize_as = "DefaultOnNull")]
pub streaming_url: BTreeMap<String, String>,
/// Album track number
pub track_num: u16,
pub track_num: Option<u16>,
}
/// Discograph (album or track)
@ -245,6 +244,7 @@ pub struct SearchBand {
pub location: Option<String>,
/// List of tag names associated with the
#[serde(default)]
#[serde_as(deserialize_as = "DefaultOnNull")]
pub tag_names: Vec<String>,
/// Bandcamp URL
///
@ -314,6 +314,7 @@ pub struct FeedStories {
}
/// Bandcamp feed item
#[serde_as]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct FeedItem {
@ -357,6 +358,7 @@ pub struct FeedItem {
pub num_streamable_tracks: u16,
/// List of tags
#[serde(default)]
#[serde_as(deserialize_as = "DefaultOnNull")]
pub tags: Vec<Tag>,
}

View file

@ -71,101 +71,83 @@ Album(
Track(
track_id: 2221991469,
title: "Sommarfågel",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 232.642,
streaming_url: "[streaming_url]",
track_num: 1,
track_num: Some(1),
),
Track(
track_id: 1593213040,
title: "The Rocket",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 211.491,
streaming_url: "[streaming_url]",
track_num: 2,
track_num: Some(2),
),
Track(
track_id: 2806652396,
title: "Valentine",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 238.538,
streaming_url: "[streaming_url]",
track_num: 3,
track_num: Some(3),
),
Track(
track_id: 4173325157,
title: "Slottskogen Disc Golf Club",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 212.65,
streaming_url: "[streaming_url]",
track_num: 4,
track_num: Some(4),
),
Track(
track_id: 3038199534,
title: "Biking Is Better",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 208.27,
streaming_url: "[streaming_url]",
track_num: 5,
track_num: Some(5),
),
Track(
track_id: 3487050701,
title: "Västanberg",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 265.692,
streaming_url: "[streaming_url]",
track_num: 6,
track_num: Some(6),
),
Track(
track_id: 1604303190,
title: "Starmachine2000",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 243.139,
streaming_url: "[streaming_url]",
track_num: 7,
track_num: Some(7),
),
Track(
track_id: 716010980,
title: "All Was Well",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 183.224,
streaming_url: "[streaming_url]",
track_num: 8,
track_num: Some(8),
),
Track(
track_id: 2322125757,
title: "Paradis",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 850.6,
streaming_url: "[streaming_url]",
track_num: 9,
track_num: Some(9),
),
],
)

View file

@ -76,310 +76,254 @@ Album(
Track(
track_id: 3886649117,
title: "Skyjacks",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 263.262,
streaming_url: "[streaming_url]",
track_num: 1,
track_num: Some(1),
),
Track(
track_id: 3353751902,
title: "Bound for the Cutting Stone",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 126.905,
streaming_url: "[streaming_url]",
track_num: 2,
track_num: Some(2),
),
Track(
track_id: 814453490,
title: "Harmony",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 109.548,
streaming_url: "[streaming_url]",
track_num: 3,
track_num: Some(3),
),
Track(
track_id: 3751525198,
title: "Lighthouse",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 187.492,
streaming_url: "[streaming_url]",
track_num: 4,
track_num: Some(4),
),
Track(
track_id: 461427875,
title: "Dark Magic",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 67.5178,
streaming_url: "[streaming_url]",
track_num: 5,
track_num: Some(5),
),
Track(
track_id: 694400627,
title: "Way Hay Ho",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 179.318,
streaming_url: "[streaming_url]",
track_num: 6,
track_num: Some(6),
),
Track(
track_id: 1856437095,
title: "Toast the Axel",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 101.507,
streaming_url: "[streaming_url]",
track_num: 7,
track_num: Some(7),
),
Track(
track_id: 1961563423,
title: "Ring the Bell",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 113.478,
streaming_url: "[streaming_url]",
track_num: 8,
track_num: Some(8),
),
Track(
track_id: 405906043,
title: "Call of the Sky",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 201.026,
streaming_url: "[streaming_url]",
track_num: 9,
track_num: Some(9),
),
Track(
track_id: 3751492440,
title: "Johnny Forgot His Square Knot",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 58.7233,
streaming_url: "[streaming_url]",
track_num: 10,
track_num: Some(10),
),
Track(
track_id: 3046284392,
title: "Dance",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 48.9229,
streaming_url: "[streaming_url]",
track_num: 11,
track_num: Some(11),
),
Track(
track_id: 1075587078,
title: "Skyjacks (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 263.348,
streaming_url: "[streaming_url]",
track_num: 12,
track_num: Some(12),
),
Track(
track_id: 3865632006,
title: "Bound for the Cutting Stone (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 125.76,
streaming_url: "[streaming_url]",
track_num: 13,
track_num: Some(13),
),
Track(
track_id: 951718157,
title: "Lighthouse (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 187.492,
streaming_url: "[streaming_url]",
track_num: 14,
track_num: Some(14),
),
Track(
track_id: 1384316860,
title: "Way Hay Ho (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 179.318,
streaming_url: "[streaming_url]",
track_num: 15,
track_num: Some(15),
),
Track(
track_id: 1215251403,
title: "Toast the Axel (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 101.507,
streaming_url: "[streaming_url]",
track_num: 16,
track_num: Some(16),
),
Track(
track_id: 1871038324,
title: "Ring the Bell (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 111.769,
streaming_url: "[streaming_url]",
track_num: 17,
track_num: Some(17),
),
Track(
track_id: 2289302029,
title: "Call of the Sky (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 201.026,
streaming_url: "[streaming_url]",
track_num: 18,
track_num: Some(18),
),
Track(
track_id: 1290369552,
title: "Way Hay Ho (Show Cut)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 129.01,
streaming_url: "[streaming_url]",
track_num: 19,
track_num: Some(19),
),
Track(
track_id: 1453689011,
title: "Call of the Sky (Acoustic)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 196.0,
streaming_url: "[streaming_url]",
track_num: 20,
track_num: Some(20),
),
Track(
track_id: 3921099822,
title: "Lighthouse (Cabin Cut)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 113.751,
streaming_url: "[streaming_url]",
track_num: 21,
track_num: Some(21),
),
Track(
track_id: 2006464954,
title: "Otto Van Von Veen",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 128.545,
streaming_url: "[streaming_url]",
track_num: 22,
track_num: Some(22),
),
Track(
track_id: 3157042890,
title: "Lighthouse (Duet)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 166.898,
streaming_url: "[streaming_url]",
track_num: 23,
track_num: Some(23),
),
Track(
track_id: 3031409543,
title: "Call of the Sky (Fan Edition)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 201.143,
streaming_url: "[streaming_url]",
track_num: 24,
track_num: Some(24),
),
Track(
track_id: 3451672807,
title: "Call of the Sky 2: The Sequel to Call of the Sky (Instrumental)",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 78.7156,
streaming_url: "[streaming_url]",
track_num: 25,
track_num: Some(25),
),
Track(
track_id: 2232966671,
title: "Skyjacks: Call of the Sky Behind the Music Part 1",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 1957.24,
streaming_url: "[streaming_url]",
track_num: 26,
track_num: Some(26),
),
Track(
track_id: 3477530801,
title: "Skyjacks: Call of the Sky Behind the Music Part 2",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 3668.83,
streaming_url: "[streaming_url]",
track_num: 27,
track_num: Some(27),
),
Track(
track_id: 3005668857,
title: "Skyjacks: Call of the Sky Behind the Music Part 3",
album_id: 1493086082,
album_title: None,
band_id: 3760769193,
album_id: Some(1493086082),
band_name: Some("Arne Parrott"),
duration: 3876.74,
streaming_url: "[streaming_url]",
track_num: 28,
track_num: Some(28),
),
],
)

View file

@ -31,13 +31,11 @@ Album(
Track(
track_id: 716010980,
title: "All Was Well",
album_id: 2572654767,
album_title: None,
band_id: 2464198920,
album_id: Some(2572654767),
band_name: Some("Wintergatan"),
duration: 183.224,
streaming_url: "[streaming_url]",
track_num: 8,
track_num: Some(8),
),
],
)

View file

@ -0,0 +1,56 @@
---
source: tests/tests.rs
expression: "&album"
---
Album(
id: 3835153004,
title: "Test Me",
art_id: Some(269941427),
type: t,
tralbum_artist: "Cydnee with a C",
band: BandInfo(
band_id: 3453236550,
name: "Cydnee with a C",
bio: None,
image_id: Some(30619318),
location: Some("Los Angeles, California"),
),
bandcamp_url: "https://cydneewithac.bandcamp.com/track/test-me",
credits: Some("Cydnee Jazmere Butler \nJackson Renauld"),
about: None,
featured_track_id: 3835153004,
release_date: 1654905600,
tags: [
Tag(
name: "R&B/Soul",
norm_name: "r-b-soul",
isloc: false,
),
Tag(
name: "drum and bass",
norm_name: "drum-and-bass",
isloc: false,
),
Tag(
name: "k-pop",
norm_name: "k-pop",
isloc: false,
),
Tag(
name: "Los Angeles",
norm_name: "los-angeles",
isloc: true,
),
],
tracks: [
Track(
track_id: 3835153004,
title: "Test Me",
album_id: None,
band_name: Some("Cydnee with a C"),
duration: 106.667,
streaming_url: "[streaming_url]",
track_num: None,
),
],
)

View file

@ -81,6 +81,18 @@ async fn album_track() {
check_image(&album.img_url().unwrap()).await;
}
#[tokio::test]
async fn album_track2() {
let bc = Bandcamp::new();
let album = bc.album_uid("3453236550t3835153004").await.unwrap();
insta::assert_ron_snapshot!(&album, {
".tracks[].streaming_url" => "[streaming_url]"
});
check_stream_urls(&album.tracks);
check_image(&album.img_url().unwrap()).await;
}
#[tokio::test]
async fn search() {
let bc = Bandcamp::new();