11use std:: {
2- path:: Path , string:: FromUtf8Error , time:: { SystemTime , UNIX_EPOCH }
2+ path:: Path ,
3+ string:: FromUtf8Error ,
4+ time:: { SystemTime , UNIX_EPOCH } ,
35} ;
46
57use json_extractor:: {
@@ -48,20 +50,22 @@ fn get_headers() -> HeaderMap {
4850}
4951
5052#[ cfg( test) ]
51- fn get_account_id ( ) -> Option < String > {
53+ fn get_account_id ( ) -> Option < String > {
5254 let file = std:: fs:: read_to_string ( "../account_id.txt" ) . unwrap ( ) ;
5355 let account_id = match std:: fs:: read_to_string ( file) {
5456 Ok ( id) => Some ( id) ,
5557 Err ( _) => None ,
5658 } ;
57- return account_id;
59+ return account_id;
5860}
5961
6062#[ test]
6163fn advanced_like ( ) {
6264 use tokio:: runtime:: Runtime ;
6365 Runtime :: new ( ) . unwrap ( ) . block_on ( async {
64- let ytm = YoutubeMusicInstance :: new ( get_headers ( ) , get_account_id ( ) ) . await . unwrap ( ) ;
66+ let ytm = YoutubeMusicInstance :: new ( get_headers ( ) , get_account_id ( ) )
67+ . await
68+ . unwrap ( ) ;
6569 println ! ( "{}" , ytm. compute_sapi_hash( ) ) ;
6670 let search = ytm
6771 . get_library ( & Endpoint :: MusicLibraryLanding , 0 )
@@ -77,7 +81,9 @@ fn advanced_like() {
7781fn advanced_test ( ) {
7882 use tokio:: runtime:: Runtime ;
7983 Runtime :: new ( ) . unwrap ( ) . block_on ( async {
80- let ytm = YoutubeMusicInstance :: new ( get_headers ( ) , get_account_id ( ) ) . await . unwrap ( ) ;
84+ let ytm = YoutubeMusicInstance :: new ( get_headers ( ) , get_account_id ( ) )
85+ . await
86+ . unwrap ( ) ;
8187 let search = ytm. search ( "j'ai la danse qui va avec" , 0 ) . await . unwrap ( ) ;
8288 assert_eq ! ( search. videos. is_empty( ) , false ) ;
8389 assert_eq ! ( search. playlists. is_empty( ) , false ) ;
@@ -90,7 +96,9 @@ fn advanced_test() {
9096fn home_test ( ) {
9197 use tokio:: runtime:: Runtime ;
9298 Runtime :: new ( ) . unwrap ( ) . block_on ( async {
93- let ytm = YoutubeMusicInstance :: new ( get_headers ( ) , get_account_id ( ) ) . await . unwrap ( ) ;
99+ let ytm = YoutubeMusicInstance :: new ( get_headers ( ) , get_account_id ( ) )
100+ . await
101+ . unwrap ( ) ;
94102 let search = ytm. get_home ( 0 ) . await . unwrap ( ) ;
95103 println ! ( "{:?}" , search. playlists) ;
96104 assert_eq ! ( search. playlists. is_empty( ) , false ) ;
@@ -111,7 +119,7 @@ pub struct YoutubeMusicInstance {
111119 innertube_api_key : String ,
112120 client_version : String ,
113121 cookies : String ,
114- account_id : Option < String >
122+ account_id : Option < String > ,
115123}
116124
117125impl YoutubeMusicInstance {
@@ -148,7 +156,10 @@ impl YoutubeMusicInstance {
148156 . unwrap ( ) ,
149157 ) ;
150158 }
151- let account_path = path. parent ( ) . unwrap_or ( Path :: new ( "../" ) ) . join ( "account_id.txt" ) ;
159+ let account_path = path
160+ . parent ( )
161+ . unwrap_or ( Path :: new ( "../" ) )
162+ . join ( "account_id.txt" ) ;
152163 let account_id = match tokio:: fs:: read_to_string ( account_path) . await {
153164 Ok ( mut id) => {
154165 if id. ends_with ( "\n " ) {
@@ -158,7 +169,7 @@ impl YoutubeMusicInstance {
158169 }
159170 }
160171 Some ( id)
161- } ,
172+ }
162173 Err ( _) => None , //don't care if there is no files or nothing in the file
163174 } ;
164175 Self :: new ( headers, account_id) . await
@@ -217,7 +228,7 @@ impl YoutubeMusicInstance {
217228 innertube_api_key : innertube_api_key. to_string ( ) ,
218229 client_version : client_version. to_string ( ) ,
219230 cookies,
220- account_id
231+ account_id,
221232 } )
222233 }
223234 fn compute_sapi_hash ( & self ) -> String {
@@ -281,7 +292,7 @@ impl YoutubeMusicInstance {
281292 None => format ! (
282293 r#"{{"context":{{"client":{{"clientName":"WEB_REMIX","clientVersion":"{}"}}}}}}"# ,
283294 self . client_version
284- )
295+ ) ,
285296 } ;
286297 reqwest:: Client :: new ( )
287298 . post ( & url)
@@ -319,7 +330,7 @@ impl YoutubeMusicInstance {
319330 None => format ! (
320331 r#"{{"context":{{"client":{{"clientName":"WEB_REMIX","clientVersion":"{}"}}}},"{endpoint_key}":"{endpoint_param}"}}"# ,
321332 self . client_version
322- )
333+ ) ,
323334 } ;
324335 reqwest:: Client :: new ( )
325336 . post ( & url)
0 commit comments