1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crate::key::Key;
use crate::mode::Mode;
use crate::score::Score;
#[derive(Debug, Clone)]
pub struct TrackEntity {
pub id: String,
pub title: String,
pub artist: String,
pub image: String,
pub mode: Mode,
pub key: Key,
pub bpm: f32,
pub time: u64,
pub popularity: Score,
pub danceability: Score,
pub energy: Score,
pub valence: Score,
pub acousticness: Score,
pub instrumentalness: Score,
pub liveness: Score,
pub speechiness: Score,
}
impl TrackEntity {
pub fn from(
id: String,
title: String,
artist: String,
image: String,
mode: Mode,
key: Key,
bpm: f32,
time: u64,
popularity: Score,
danceability: Score,
energy: Score,
valence: Score,
acousticness: Score,
instrumentalness: Score,
liveness: Score,
speechiness: Score,
) -> Self {
Self {
id,
title,
artist,
image,
mode,
key,
bpm,
time,
popularity,
danceability,
energy,
valence,
acousticness,
instrumentalness,
liveness,
speechiness,
}
}
pub fn is_live(&self) -> bool {
let live = match Score::try_from(80) {
Ok(t) => t,
Err(_) => return false,
};
self.liveness >= live
}
pub fn is_speech(&self) -> bool {
let live = match Score::try_from(33) {
Ok(t) => t,
Err(_) => return false,
};
self.speechiness >= live
}
}