@@ -28,19 +28,30 @@ pub fn print_top(entries: &Vec<SongEntry>, asp: Aspect, num: usize) {
28
28
pub fn print_top_from_artist ( entries : & Vec < SongEntry > , asp : Aspect , artist : & Artist , num : usize ) {
29
29
match asp {
30
30
Aspect :: Songs => {
31
- println ! ( "=== TOP {} SONGS FROM {} ===" , num, artist. name ) ;
31
+ println ! ( "=== TOP {} SONGS FROM {} ===" , num, artist) ;
32
32
print_top_helper ( gather_songs_with_artist ( entries, artist) , num) ;
33
33
println ! ( ) ;
34
34
}
35
35
Aspect :: Albums => {
36
- println ! ( "=== TOP {} ALBUMS FROM {} ===" , num, artist. name ) ;
36
+ println ! ( "=== TOP {} ALBUMS FROM {} ===" , num, artist) ;
37
37
print_top_helper ( gather_albums_with_artist ( entries, artist) , num) ;
38
38
println ! ( ) ;
39
39
}
40
40
_ => println ! ( "gay" ) ,
41
41
}
42
42
}
43
43
44
+ pub fn print_top_from_album ( entries : & Vec < SongEntry > , asp : Aspect , album : & Album , num : usize ) {
45
+ match asp {
46
+ Aspect :: Songs => {
47
+ println ! ( "=== TOP {} SONGS FROM {} ===" , num, album) ;
48
+ print_top_helper ( gather_songs_with_album ( entries, album) , num) ;
49
+ println ! ( ) ;
50
+ }
51
+ _ => println ! ( "gay" ) ,
52
+ }
53
+ }
54
+
44
55
fn print_top_helper < T : Music > ( music_dict : HashMap < T , u32 > , num : usize ) {
45
56
// https://stackoverflow.com/q/34555837/6694963
46
57
let mut music_vec: Vec < ( & T , & u32 ) > = music_dict. iter ( ) . collect ( ) ;
@@ -116,6 +127,32 @@ fn gather_songs_with_artist(entries: &Vec<SongEntry>, art: &Artist) -> HashMap<S
116
127
songs
117
128
}
118
129
130
+ fn gather_songs_with_album ( entries : & Vec < SongEntry > , alb : & Album ) -> HashMap < Song , u32 > {
131
+ let mut songs: HashMap < Song , u32 > = HashMap :: new ( ) ;
132
+
133
+ for entry in entries {
134
+ let artist = Artist {
135
+ name : entry. artist . clone ( ) ,
136
+ } ;
137
+ let album = Album {
138
+ name : entry. album . clone ( ) ,
139
+ artist : artist. clone ( ) ,
140
+ } ;
141
+ if album != * alb {
142
+ continue ;
143
+ }
144
+ let song = Song {
145
+ name : entry. track . clone ( ) ,
146
+ album : album. clone ( ) ,
147
+ id : entry. id . clone ( ) ,
148
+ } ;
149
+
150
+ * songs. entry ( song) . or_insert ( 0 ) += 1 ;
151
+ }
152
+
153
+ songs
154
+ }
155
+
119
156
fn gather_albums ( entries : & Vec < SongEntry > ) -> HashMap < Album , u32 > {
120
157
let mut albums: HashMap < Album , u32 > = HashMap :: new ( ) ;
121
158
0 commit comments