@@ -2,7 +2,7 @@ use std::collections::HashMap;
22
33use concat_string:: concat_string;
44use serde:: Deserialize ;
5- use unm_types:: { Song , Album , Artist } ;
5+ use unm_types:: { Album , Artist , Song } ;
66
77use super :: identifier:: QQResourceIdentifier ;
88
@@ -33,7 +33,7 @@ pub struct QQSongEntry {
3333 pub singer : Vec < QQSongSinger > ,
3434
3535 /// The media ID of this song entry.
36- ///
36+ ///
3737 /// If no `media_mid` is provided, we return an empty string.
3838 /// You may want to filter it with [`Iterator::filter`].
3939 #[ serde( default ) ]
@@ -64,7 +64,7 @@ pub struct QQSingleResponse {
6464 pub sip : Vec < String > ,
6565
6666 /// The segment of audio URLs to receive.
67- pub midurlinfo : Vec < QQSingleUrlInfo >
67+ pub midurlinfo : Vec < QQSingleUrlInfo > ,
6868}
6969
7070#[ derive( Debug , Deserialize ) ]
@@ -74,7 +74,7 @@ pub struct QQSingleUrlInfo {
7474 pub filename : String ,
7575
7676 /// The URL segment of this audio.
77- ///
77+ ///
7878 /// You can combine this segment with the server
7979 /// in the `sip` field of [`QQSingleResponse`].
8080 pub purl : String ,
@@ -90,18 +90,22 @@ impl From<QQSongEntry> for Song {
9090 Album :: builder ( )
9191 . id ( entry. albumid . to_string ( ) )
9292 . name ( entry. albumname )
93- . build ( )
93+ . build ( ) ,
9494 ) )
9595 . artists ( entry. singer . into_iter ( ) . map ( Into :: into) . collect ( ) )
9696 . context ( {
9797 let mut ctx = HashMap :: new ( ) ;
9898 let songmid = entry. songmid ;
9999 let media_mid = entry. media_mid ;
100100
101- ctx. insert ( "identifier" . into ( ) , QQResourceIdentifier {
102- mid : & songmid,
103- file : & media_mid,
104- } . serialize ( ) ) ;
101+ ctx. insert (
102+ "identifier" . into ( ) ,
103+ QQResourceIdentifier {
104+ mid : & songmid,
105+ file : & media_mid,
106+ }
107+ . serialize ( ) ,
108+ ) ;
105109 ctx. insert ( "songmid" . into ( ) , songmid) ;
106110 ctx. insert ( "media_mid" . into ( ) , media_mid) ;
107111
@@ -124,13 +128,15 @@ impl QQSingleResponse {
124128 pub fn get_url ( & self ) -> Result < String , FieldNotPickable > {
125129 log:: info!( "Extracting the URL from the single response…" ) ;
126130
127- let server = self . sip
131+ let server = self
132+ . sip
128133 . get ( fastrand:: usize ( 0 ..self . sip . len ( ) ) )
129134 . ok_or ( FieldNotPickable ( "sip" ) ) ?;
130- let url_info = self . midurlinfo
135+ let url_info = self
136+ . midurlinfo
131137 . get ( 0 )
132138 . ok_or ( FieldNotPickable ( "midurlinfo" ) ) ?;
133-
139+
134140 Ok ( concat_string ! ( server, url_info. purl) )
135141 }
136142}
@@ -155,29 +161,36 @@ mod tests {
155161 let single_response = QQSingleResponse {
156162 sip : vec ! [ "http://helloworld.com/" . into( ) ] ,
157163 midurlinfo : vec ! [ QQSingleUrlInfo {
158- filename: "filename" . into( ) , purl: "purl?114514" . into( )
164+ filename: "filename" . into( ) ,
165+ purl: "purl?114514" . into( ) ,
159166 } ] ,
160167 } ;
161168
162- assert_eq ! ( single_response. get_url( ) . unwrap( ) , "http://helloworld.com/purl?114514" ) ;
169+ assert_eq ! (
170+ single_response. get_url( ) . unwrap( ) ,
171+ "http://helloworld.com/purl?114514"
172+ ) ;
163173 }
164174
165175 #[ test]
166176 fn test_single_response_get_url_with_multiple_sip ( ) {
167177 let single_response = QQSingleResponse {
168- sip : vec ! [ "http://helloworld.com/" . into( ) , "http://helloworld.org/" . into( ) ] ,
169- midurlinfo : vec ! [
170- QQSingleUrlInfo {
171- filename: "filename" . into( ) , purl: "purl?114514" . into( )
172- } ,
178+ sip : vec ! [
179+ "http://helloworld.com/" . into( ) ,
180+ "http://helloworld.org/" . into( ) ,
173181 ] ,
182+ midurlinfo : vec ! [ QQSingleUrlInfo {
183+ filename: "filename" . into( ) ,
184+ purl: "purl?114514" . into( ) ,
185+ } ] ,
174186 } ;
175187
176188 let data = single_response. get_url ( ) . unwrap ( ) ;
177189 assert ! ( vec![
178190 "http://helloworld.com/purl?114514" ,
179191 "http://helloworld.org/purl?114514"
180- ] . contains( & data. as_str( ) ) ) ;
192+ ]
193+ . contains( & data. as_str( ) ) ) ;
181194 }
182195
183196 #[ test]
@@ -186,14 +199,19 @@ mod tests {
186199 sip : vec ! [ "http://helloworld.com/" . into( ) ] ,
187200 midurlinfo : vec ! [
188201 QQSingleUrlInfo {
189- filename: "filename" . into( ) , purl: "purl?114514" . into( )
202+ filename: "filename" . into( ) ,
203+ purl: "purl?114514" . into( ) ,
190204 } ,
191205 QQSingleUrlInfo {
192- filename: "DO_NOT_PICK_THIS" . into( ) , purl: "!!!DONTPICKTHIS!!!" . into( )
206+ filename: "DO_NOT_PICK_THIS" . into( ) ,
207+ purl: "!!!DONTPICKTHIS!!!" . into( ) ,
193208 } ,
194209 ] ,
195210 } ;
196211
197- assert_eq ! ( single_response. get_url( ) . unwrap( ) , "http://helloworld.com/purl?114514" ) ;
212+ assert_eq ! (
213+ single_response. get_url( ) . unwrap( ) ,
214+ "http://helloworld.com/purl?114514"
215+ ) ;
198216 }
199- }
217+ }
0 commit comments