ytmapi-rs 0.0.21

An asynchronous (tokio) pure Rust API for Youtube Music using Google's internal API
Documentation
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
//! Due to quota limits - all live api tests are extracted out into their own
//! integration tests module.
use common::{EpisodeID, LikeStatus, PodcastChannelID, PodcastChannelParams, PodcastID, VideoID};
use parse::{GetArtistAlbumsAlbum, Lyrics};
use std::time::Duration;
use ytmapi_rs::common::{
    ApiOutcome, ArtistChannelID, FeedbackTokenAddToLibrary, FeedbackTokenRemoveFromLibrary,
};
use ytmapi_rs::common::{LyricsID, PlaylistID, YoutubeID};
use ytmapi_rs::error::ErrorKind;
use ytmapi_rs::parse::{ArtistParams, GetAlbum, ParseFrom};
use ytmapi_rs::query::*;
use ytmapi_rs::{auth::*, *};

use crate::utils::{new_standard_api, new_standard_oauth_api, INVALID_COOKIE};

#[macro_use]
mod utils;

#[tokio::test]
async fn test_refresh_expired_oauth() {
    let mut api = utils::new_standard_oauth_api().await.unwrap();
    api.refresh_token().await.unwrap();
}

#[tokio::test]
async fn test_get_oauth_code() {
    let client = crate::client::Client::new().unwrap();
    let _code = OAuthTokenGenerator::new(&client).await.unwrap();
}

// NOTE: Internal only - due to use of error.is_oauth_expired()
#[tokio::test]
#[ignore = "Oauth is broken https://github.com/nick42d/youtui/issues/179"]
async fn test_expired_oauth() {
    // XXX: Assuming this error only occurs for expired headers.
    // This assumption may be incorrect.
    let api = new_standard_oauth_api().await.unwrap();
    // Library query needs authentication.
    let res = api.json_query(GetLibraryPlaylistsQuery).await;
    // TODO: Add matching functions to error type. Current method not very
    // ergonomic.
    let Err(error) = res else {
        panic!("Expected an error")
    };
    assert!(matches!(
        error.into_kind(),
        ErrorKind::OAuthTokenExpired { .. }
    ));
}
// Placeholder for future implementation.
// #[tokio::test]
// async fn test_expired_header() {
// }
#[tokio::test]
async fn test_invalid_header() {
    let api = YtMusic::from_cookie(INVALID_COOKIE).await;
    // Library query needs authentication.
    let res = api.unwrap().json_query(GetLibraryPlaylistsQuery).await;
    // TODO: Add matching functions to error type. Current method not very
    // ergonomic.
    let Err(error) = res else {
        eprintln!("{:#?}", res);
        panic!("Expected an error")
    };
    assert!(matches!(
        error.into_kind(),
        ErrorKind::BrowserAuthenticationFailed
    ));
}
// Placeholder for future implementation
// #[tokio::test]
// async fn test_invalid_expired_oauth() {
//     let oauth_token: OAuthToken =
// serde_json::from_str(INVALID_EXPIRED_OAUTH).unwrap();     let api =
// YtMusic::from_oauth_token(oauth_token);     // Library query needs
// authentication.     let res = api.json_query(GetLibraryPlaylistsQuery).await;
//     // TODO: Add matching functions to error type. Current method not very
// ergonomic.     let Err(error) = res else {
//         eprintln!("{:#?}", res);
//         panic!("Expected an error")
//     };
//     eprintln!("{:#?}", error);
//     assert!(error.is_browser_authentication_failed());
// }

#[tokio::test]
async fn test_new() {
    new_standard_api().await.unwrap();
    new_standard_oauth_api().await.unwrap();
}
//// BASIC STREAM TESTS
generate_stream_test!(
    test_stream_get_library_songs,
    GetLibrarySongsQuery::default()
);
generate_stream_test!(
    #[ignore = "Ignored by default due to quota"]
    test_stream_get_library_artist_subscriptions,
    GetLibraryArtistSubscriptionsQuery::default()
);
generate_stream_test!(
    #[ignore = "Ignored by default due to quota"]
    test_stream_get_library_playlists,
    GetLibraryPlaylistsQuery
);
generate_stream_test!(
    #[ignore = "Ignored by default due to quota"]
    test_stream_get_library_albums,
    GetLibraryAlbumsQuery::default()
);
generate_stream_test!(
    test_stream_get_library_artists,
    GetLibraryArtistsQuery::default()
);
generate_query_test!(
    test_search_suggestions,
    GetSearchSuggestionsQuery::new("faded")
);

generate_query_test!(test_get_mood_categories, GetMoodCategoriesQuery);
// NOTE: Set Taste Profile test is not implemented, to avoid impact to my YTM
// recommendations.
generate_query_test!(test_get_taste_profile, GetTasteProfileQuery);
generate_query_test!(test_get_history, GetHistoryQuery);
generate_query_test!(
    test_get_channel,
    // Rustacean Station
    GetChannelQuery::new(PodcastChannelID::from_raw("UCzYLos4qc2oC4r0Efd-tSuw"),)
);
// NOTE: Can be flaky - visiting this page on the website seems to reset it.
generate_query_test!(
    test_get_channel_episodes,
    // Rustacean Station
    GetChannelEpisodesQuery::new(
        PodcastChannelID::from_raw("UCzYLos4qc2oC4r0Efd-tSuw"),
        PodcastChannelParams::from_raw("6gPmAUdxa0JXcGtCQ3BZQkNpUjVkRjl3WVdkbFgzTnVZWEJ6YUc5MFgyMTFjMmxqWDNCaFoyVmZjbVZuYVc5dVlXd1NIM05mUzNKVGJtWlphemhuWmtWUWEzaDRSRVpqWWxSS1R6UXllbDlIYUdzYVRRQUFaVzR0UjBJQUFVRlZBQUZCVlFBQkFFWkZiWFZ6YVdOZlpHVjBZV2xzWDJGeWRHbHpkQUFCQVVNQUFBRUFBQUVCQUZWRGVsbE1iM00wY1dNeWIwTTBjakJGWm1RdGRGTjFkd0FCOHRxenFnb0hRQUJJQUZDYkFR")
    )
);
generate_query_test!(
    test_get_podcast,
    // Rustacean Station
    GetPodcastQuery::new(PodcastID::from_raw(
        "MPSPPLWnnGn_Lw9os50MbtFCouWYsArlq2s8ct"
    ))
);
generate_query_test!(
    test_get_episode,
    // Chasing scratch S7E21
    GetEpisodeQuery::new(EpisodeID::from_raw("MPED2i5poDoWjFU"))
);
generate_query_test!(test_get_new_episodes_playlist, GetNewEpisodesQuery);
generate_query_test!(
    test_get_playlist,
    GetPlaylistQuery::new(PlaylistID::from_raw("VLPL0jp-uZ7a4g9FQWW5R_u0pz4yzV4RiOXu"))
);
generate_query_test!(
    test_get_artist,
    GetArtistQuery::new(ArtistChannelID::from_raw("UC2XdaAVUannpujzv32jcouQ",))
);
generate_query_test!(
    #[ignore = "Ignored by default due to quota"]
    test_get_library_upload_songs,
    GetLibraryUploadSongsQuery::default()
);
generate_query_test!(
    #[ignore = "Ignored by default due to quota"]
    test_get_library_upload_albums,
    GetLibraryUploadAlbumsQuery::default()
);
generate_query_test!(
    #[ignore = "Ignored by default due to quota"]
    test_get_library_upload_artists,
    GetLibraryUploadArtistsQuery::default()
);
generate_query_test!(
    #[ignore = "Ignored by default due to quota"]
    test_get_library_songs,
    GetLibrarySongsQuery::default()
);
generate_query_test!(test_get_library_albums, GetLibraryAlbumsQuery::default());
generate_query_test!(
    test_get_library_artist_subscriptions,
    GetLibraryArtistSubscriptionsQuery::default()
);
generate_query_test!(test_basic_search, SearchQuery::new("Beatles"));
generate_query_test!(
    test_basic_search_alternate_query_1,
    SearchQuery::new("Beaten")
);
generate_query_test!(
    test_basic_search_alternate_query_2,
    SearchQuery::new("Chasing scratch")
);
generate_query_test!(
    test_basic_search_alternate_query_3_genre,
    SearchQuery::new("Metal")
);
generate_query_test!(
    test_basic_search_alternate_query_no_results,
    SearchQuery::new("aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbcccccccccccccccccc")
);
generate_query_test!(
    test_search_artists,
    SearchQuery::new("Beatles").with_filter(ArtistsFilter)
);
generate_query_test!(
    test_search_songs,
    SearchQuery::new("Beatles").with_filter(SongsFilter)
);
generate_query_test!(
    test_search_albums,
    SearchQuery::new("Beatles").with_filter(AlbumsFilter)
);
generate_query_test!(
    test_search_videos,
    SearchQuery::new("Beatles").with_filter(VideosFilter)
);
generate_query_test!(
    test_search_episodes,
    SearchQuery::new("Beatles").with_filter(EpisodesFilter)
);
generate_query_test!(
    test_search_podcasts,
    SearchQuery::new("Beatles").with_filter(PodcastsFilter)
);
generate_query_test!(
    test_search_profiles,
    SearchQuery::new("Beatles").with_filter(ProfilesFilter)
);
generate_query_test!(
    test_search_featured_playlists,
    SearchQuery::new("Beatles").with_filter(FeaturedPlaylistsFilter)
);
generate_query_test!(
    test_search_community_playlists,
    SearchQuery::new("Beatles").with_filter(CommunityPlaylistsFilter)
);
generate_query_test!(
    test_search_playlists,
    SearchQuery::new("Beatles").with_filter(PlaylistsFilter)
);

// # MULTISTAGE TESTS

#[tokio::test]
async fn test_get_mood_playlists() {
    let browser_api = crate::utils::new_standard_api().await.unwrap();
    let first_mood_playlist = browser_api
        .query(GetMoodCategoriesQuery)
        .await
        .unwrap()
        .into_iter()
        .next()
        .unwrap()
        .mood_categories
        .into_iter()
        .next()
        .unwrap();
    let query = GetMoodPlaylistsQuery::new(first_mood_playlist.params);
    browser_api.query(query.clone()).await.unwrap();
}

#[ignore = "Ignored by default due to quota"]
#[tokio::test]
async fn test_get_library_upload_artist() {
    let browser_api = crate::utils::new_standard_api().await.unwrap();
    let first_artist = browser_api
        .query(GetLibraryUploadArtistsQuery::default())
        .await
        .unwrap()
        .into_iter()
        .next()
        .expect("To run this test, you will need to upload songs from at least one artist");
    let query = GetLibraryUploadArtistQuery::new(first_artist.artist_id);
    browser_api.query(query.clone()).await.unwrap();
}

#[ignore = "Ignored by default due to quota"]
#[tokio::test]
async fn test_get_library_upload_album() {
    let browser_api = crate::utils::new_standard_api().await.unwrap();
    let first_album = browser_api
        .query(GetLibraryUploadAlbumsQuery::default())
        .await
        .unwrap()
        .into_iter()
        .next()
        .expect("To run this test, you will need to upload songs from at least one album");
    let query = GetLibraryUploadAlbumQuery::new(first_album.album_id);
    browser_api.query(query.clone()).await.unwrap();
}

#[tokio::test]
async fn test_get_artist_albums() {
    let now = std::time::Instant::now();
    let api = new_standard_api().await.unwrap();
    println!("API took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    let q = GetArtistQuery::new(ArtistChannelID::from_raw(
        // Metallica
        "UCGexNm_Kw4rdQjLxmpb2EKw",
    ));
    let res = api.raw_query(&q).await.unwrap();
    println!("Get artist took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    let res = res.process().unwrap();
    let res: ArtistParams = ParseFrom::parse_from(res).unwrap();
    println!("Parse artist took {} ms", now.elapsed().as_millis());
    let _now = std::time::Instant::now();
    let albums = res.top_releases.albums.unwrap();
    let params = albums.params.unwrap();
    let channel_id = albums.browse_id.unwrap();
    api.get_artist_albums(channel_id, params).await.unwrap();
    let now = std::time::Instant::now();
    println!("Get albums took {} ms", now.elapsed().as_millis());
}

#[tokio::test]
async fn test_get_artist_album_songs() {
    let now = std::time::Instant::now();
    let api = new_standard_api().await.unwrap();
    println!("API took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    let q = GetArtistQuery::new(ArtistChannelID::from_raw(
        // Metallica
        "UCGexNm_Kw4rdQjLxmpb2EKw",
    ));
    let res = api.raw_query(&q).await.unwrap();
    println!("Get artist took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    // TODO: fix temporary value dropped while borrowed error.
    // This won't compile:
    // let res = res.process().unwrap().parse().unwrap();
    let res = res.process().unwrap();
    let res = ArtistParams::parse_from(res).unwrap();
    println!("Parse artist took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    let albums = res.top_releases.albums.unwrap();
    let params = albums.params.unwrap();
    let channel_id = &albums.browse_id.unwrap();
    let q = GetArtistAlbumsQuery::new(ArtistChannelID::from_raw(channel_id.get_raw()), params);
    let res = api.raw_query(&q).await.unwrap();
    println!("Get albums took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    let res = res.process().unwrap();
    let res: Vec<GetArtistAlbumsAlbum> = ParseFrom::parse_from(res).unwrap();
    println!("Process albums took {} ms", now.elapsed().as_millis());
    let now = std::time::Instant::now();
    let browse_id = &res[0].browse_id;
    let q = GetAlbumQuery::new(browse_id.clone());
    let res = api.raw_query(&q).await.unwrap();
    println!(
        "Get album {} took {} ms",
        browse_id.get_raw(),
        now.elapsed().as_millis()
    );
    let now = std::time::Instant::now();
    let res = res.process().unwrap();
    let _ = GetAlbum::parse_from(res).unwrap();
    println!("Process album took {} ms", now.elapsed().as_millis());
}

// # STATEFUL TESTS

#[tokio::test]
async fn test_add_remove_history_items() {
    // Timeout to avoid flaky test
    const GET_HISTORY_TIMEOUT: Duration = Duration::from_millis(2000);
    // TODO: Oauth.
    let api = new_standard_api().await.unwrap();
    let song = api
        .search_songs("Ride the lightning")
        .await
        .unwrap()
        .into_iter()
        .next()
        .unwrap();
    let song_url = api.get_song_tracking_url(&song.video_id).await.unwrap();
    api.add_history_item(song_url).await.unwrap();
    // Get history has a slight lag.
    tokio::time::sleep(GET_HISTORY_TIMEOUT).await;
    let history = api.get_history().await.unwrap();
    let first_history_item_period = history.first().unwrap().period_name.clone();
    let (first_history_item_name, delete_token) =
        match history.first().unwrap().items.first().unwrap() {
            parse::HistoryItem::Song(i) => (i.title.as_str(), i.feedback_token_remove.clone()),
            parse::HistoryItem::Video(i) => (i.title.as_str(), i.feedback_token_remove.clone()),
            parse::HistoryItem::Episode(i) => (i.title.as_str(), i.feedback_token_remove.clone()),
            parse::HistoryItem::UploadSong(i) => {
                (i.title.as_str(), i.feedback_token_remove.clone())
            }
        };
    pretty_assertions::assert_eq!(first_history_item_name, song.title);
    assert!(matches!(
        api.remove_history_items(vec![delete_token])
            .await
            .unwrap()
            .first(),
        Some(ApiOutcome::Success)
    ));
    // Get history has a slight lag.
    tokio::time::sleep(GET_HISTORY_TIMEOUT).await;
    let history = api.get_history().await.unwrap();
    let first_history_item_period_new = history.first().unwrap().period_name.clone();
    let first_history_item_name_new = match history.first().unwrap().items.first().unwrap() {
        parse::HistoryItem::Song(i) => i.title.as_str(),
        parse::HistoryItem::Video(i) => i.title.as_str(),
        parse::HistoryItem::Episode(i) => i.title.as_str(),
        parse::HistoryItem::UploadSong(i) => i.title.as_str(),
    };
    // It's not enough to check last song isn't the one we added - as it may exist
    // on the previous day too :)
    pretty_assertions::assert_ne!(
        (first_history_item_name_new, first_history_item_period),
        (song.title.as_str(), first_history_item_period_new)
    );
}

#[tokio::test]
#[ignore = "Ignored by default due to quota, also oauth is broken"]
async fn test_delete_create_playlist_oauth() {
    let mut api = new_standard_oauth_api().await.unwrap();
    // Don't stuff around trying the keep the local OAuth secret up to date, just
    // refresh it each time.
    api.refresh_token().await.unwrap();
    let id = api
        .create_playlist(CreatePlaylistQuery::new(
            "TEST PLAYLIST",
            None,
            PrivacyStatus::Unlisted,
        ))
        .await
        .unwrap();
    api.delete_playlist(id).await.unwrap();
}
#[tokio::test]
#[ignore = "Ignored by default due to quota"]
async fn test_delete_create_playlist() {
    // TODO: Add siginficantly more queries.
    let api = new_standard_api().await.unwrap();
    let id = api
        .create_playlist(CreatePlaylistQuery::new(
            "TEST PLAYLIST",
            None,
            PrivacyStatus::Unlisted,
        ))
        .await
        .unwrap();
    api.delete_playlist(id).await.unwrap();
}
#[tokio::test]
// TODO: Test to see if status can be queried after adding / removing.
async fn test_add_remove_songs_from_library() {
    // TODO: Add siginficantly more queries.
    let api = new_standard_api().await.unwrap();
    // TODO: Confirm what songs these are.
    // Here Comes The Sun (Remastered 2009)
    let song1_add = FeedbackTokenAddToLibrary::from_raw("AB9zfpLNiumq5xDBgjkDSZZyCueh__JX4POenJBVzci5sOatPL8q7zs8D9LIYfLPEJ7k3N4OLy4vMfFr7os-GRla9I8RgMFf0A");
    let song1_rem = FeedbackTokenRemoveFromLibrary::from_raw("AB9zfpJpKmgLWemXCSIlIUIcrBZumoOPWw0Y0NKniqn8ZBFe2Knndo6LnKBMrFjKM1iZYZBYgzKTzATqdMZh-V8nq36Svggu5w");
    // Let It Be
    let song2_add = FeedbackTokenAddToLibrary::from_raw("AB9zfpIy-gtxCX1XAx__pFt0APQ_fgGGtuUqY7D7Sz4Oupazo6dxxP-VJEfvnon4eigVa_aYBVPfW99DA2Y9Ns0AEVgbJUeDyQ");
    let song2_rem = FeedbackTokenRemoveFromLibrary::from_raw("AB9zfpLqhDJMIguP_8vxw5e-pV69_x5IVqe8KOy8jBEDoncBCCfAxOcvhaJPRi2NHLiKAukdmZgIlX7uoWcsOvqLA2zgNGUNAw");
    let q1 = EditSongLibraryStatusQuery::new_from_add_to_library_feedback_tokens(vec![song1_add]);
    let q2 = EditSongLibraryStatusQuery::new_from_add_to_library_feedback_tokens(vec![song2_add])
        .with_remove_from_library_feedback_tokens(vec![song1_rem]);
    let q3 =
        EditSongLibraryStatusQuery::new_from_remove_from_library_feedback_tokens(vec![song2_rem]);
    assert!(!api
        .query(q1)
        .await
        .unwrap()
        .into_iter()
        .collect::<Vec<_>>()
        .into_iter()
        .any(|x| x == ApiOutcome::Failure));
    assert!(!api
        .query(q2)
        .await
        .unwrap()
        .into_iter()
        .collect::<Vec<_>>()
        .into_iter()
        .any(|x| x == ApiOutcome::Failure));
    assert!(!api
        .query(q3)
        .await
        .unwrap()
        .into_iter()
        .collect::<Vec<_>>()
        .into_iter()
        .any(|x| x == ApiOutcome::Failure));
}
#[tokio::test]
async fn test_rate_songs() {
    // TODO: Add siginficantly more queries.
    let api = new_standard_api().await.unwrap();
    // TODO: Confirm what songs these are.
    api.rate_song(VideoID::from_raw("kfSQkZuIx84"), LikeStatus::Liked)
        .await
        .unwrap();
    api.rate_song(VideoID::from_raw("EjHzPrBCgf0"), LikeStatus::Disliked)
        .await
        .unwrap();
    api.rate_song(VideoID::from_raw("kfSQkZuIx84"), LikeStatus::Indifferent)
        .await
        .unwrap();
    api.rate_song(VideoID::from_raw("EjHzPrBCgf0"), LikeStatus::Indifferent)
        .await
        .unwrap();
}
#[tokio::test]
async fn test_rate_playlists() {
    // TODO: Add siginficantly more queries.
    let api = new_standard_api().await.unwrap();
    api.rate_playlist(
        // Beatles Jukebox (Featured Playlist)
        PlaylistID::from_raw("RDCLAK5uy_lHIiCEeknPkpJOowyykpfBu-ECJB9Q32I"),
        LikeStatus::Liked,
    )
    .await
    .unwrap();
    api.rate_playlist(
        // The Beatles - Beatles 100 (Community Playlist)
        PlaylistID::from_raw("PL0jp-uZ7a4g9FQWW5R_u0pz4yzV4RiOXu"),
        LikeStatus::Disliked,
    )
    .await
    .unwrap();
    api.rate_playlist(
        // Beatles Jukebox (Featured Playlist)
        PlaylistID::from_raw("RDCLAK5uy_lHIiCEeknPkpJOowyykpfBu-ECJB9Q32I"),
        LikeStatus::Indifferent,
    )
    .await
    .unwrap();
    api.rate_playlist(
        // The Beatles - Beatles 100 (Community Playlist)
        PlaylistID::from_raw("PL0jp-uZ7a4g9FQWW5R_u0pz4yzV4RiOXu"),
        LikeStatus::Indifferent,
    )
    .await
    .unwrap();
}
#[tokio::test]
#[ignore = "Ignored by default due to quota"]
async fn test_delete_create_playlist_complex() {
    // TODO: Add siginficantly more queries.
    // TODO: Oauth.
    let api = new_standard_api().await.unwrap();
    let id = api
        .create_playlist(
            CreatePlaylistQuery::new(
                "TEST PLAYLIST",
                Some("TEST DESCRIPTION"),
                PrivacyStatus::Unlisted,
            )
            .with_video_ids(vec![
                VideoID::from_raw("kfSQkZuIx84"),
                VideoID::from_raw("EjHzPrBCgf0"),
                VideoID::from_raw("Av-gUkwzvzk"),
            ]),
        )
        .await
        .unwrap();
    api.delete_playlist(id).await.unwrap();
}
#[tokio::test]
#[ignore = "Ignored by default due to quota"]
async fn test_add_remove_playlist_items() {
    // TODO: Oauth.
    let api = new_standard_api().await.unwrap();
    let id = api
        .create_playlist(CreatePlaylistQuery::new(
            "TEST PLAYLIST",
            None,
            PrivacyStatus::Unlisted,
        ))
        .await
        .unwrap();
    let set_video_ids = api
        .add_video_items_to_playlist(&id, vec![VideoID::from_raw("kfSQkZuIx84")])
        .await
        .unwrap()
        .into_iter()
        .map(|item| item.set_video_id)
        .collect();
    api.remove_playlist_items(&id, set_video_ids).await.unwrap();
    api.delete_playlist(id).await.unwrap();
}
#[tokio::test]
#[ignore = "Ignored by default due to quota"]
async fn test_edit_playlist() {
    // TODO: Add siginficantly more queries.
    // TODO: Oauth.
    let api = new_standard_api().await.unwrap();
    let id = api
        .create_playlist(CreatePlaylistQuery::new(
            "TEST PLAYLIST",
            None,
            PrivacyStatus::Unlisted,
        ))
        .await
        .unwrap();
    assert_eq!(
        api.query(EditPlaylistQuery::new_title(id.clone(), "TEST_EDIT"))
            .await
            .unwrap(),
        ApiOutcome::Success
    );
    api.delete_playlist(id).await.unwrap();
}

// # BASIC TESTS WITH ADDITIONAL ASSERTIONS

#[tokio::test]
#[ignore = "Oauth is broken https://github.com/nick42d/youtui/issues/179"]
async fn test_get_library_playlists_oauth() {
    let mut api = new_standard_oauth_api().await.unwrap();
    // Don't stuff around trying the keep the local OAuth secret up to date, just
    // refresh it each time.
    api.refresh_token().await.unwrap();
    let res = api.get_library_playlists().await.unwrap();
    assert!(!res.playlists.is_empty());
}
#[tokio::test]
async fn test_get_library_playlists() {
    let api = new_standard_api().await.unwrap();
    let res = api.get_library_playlists().await.unwrap();
    assert!(!res.playlists.is_empty());
}
#[tokio::test]
#[ignore = "Oauth is broken https://github.com/nick42d/youtui/issues/179"]
async fn test_get_library_artists_oauth() {
    let mut api = new_standard_oauth_api().await.unwrap();
    // Don't stuff around trying the keep the local OAuth secret up to date, just
    // refresh it each time.
    api.refresh_token().await.unwrap();
    let res = api.get_library_artists().await.unwrap();
    assert!(!res.artists.is_empty());
}
#[tokio::test]
async fn test_get_library_artists() {
    let api = new_standard_api().await.unwrap();
    let res = api.get_library_artists().await.unwrap();
    assert!(!res.artists.is_empty());
}
#[tokio::test]
async fn test_watch_playlist() {
    // TODO: Make more generic
    let api = new_standard_api().await.unwrap();
    let res = api
        .get_watch_playlist_from_video_id(VideoID::from_raw("9mWr4c_ig54"))
        .await
        .unwrap();
    assert_eq!(
        res.playlist_id,
        Some(PlaylistID::from_raw("RDAMVM9mWr4c_ig54"))
    );
    assert_eq!(res.lyrics_id, LyricsID::from_raw("MPLYt_C8aRK1qmsDJ-1"));
}
#[tokio::test]
async fn test_get_lyrics() {
    // TODO: Make more generic
    let api = new_standard_api().await.unwrap();
    let res = api
        .get_watch_playlist_from_video_id(VideoID::from_raw("9mWr4c_ig54"))
        .await
        .unwrap();
    let res = api.get_lyrics(res.lyrics_id).await.unwrap();
    let example = serde_json::json! ({
        "lyrics": "You're my lesson I had to learn\nAnother page I'll have to turn\nI got one more message, always tryna be heard\nBut you never listen to a word\n\nHeaven knows we came so close\nBut this ain't real, it's just a dream\nWake me up, I've been fast asleep\nLetting go of fantasies\nBeen caught up in who I needed you to be\nHow foolish of me\n\nFoolish of me\nFoolish of me\nFoolish of me\nFoolish of me\n\nJust give me one second and I'll be fine\nJust let me catch my breath and come back to life\nI finally get the message, you were never meant to be mine\nCouldn't see the truth, I was blind (meant to be mine)\n\nWhoa, heaven knows we came so close\nBut this ain't real, it's just a dream\nWake me up, I've been fast asleep\nLetting go of fantasies\nBeen caught up in who I needed you to be\nHow foolish of me\n\nFoolish of me\nFoolish of me\nFoolish of me\nFoolish of me\n\nLetting go, we came so close (how foolish of me)\nOh, I'm letting go of fantasies\nBeen caught up in who I needed you to be\nHow foolish of me",
        "source": "Source: Musixmatch",
    });
    let example: Lyrics = serde_json::from_value(example).unwrap();
    assert_eq!(res, example)
}