fix: parse view count on shorts
This commit is contained in:
parent
9fbacb2318
commit
3a2e4c8abe
4 changed files with 61 additions and 54 deletions
|
|
@ -64,6 +64,9 @@ enum Commands {
|
|||
/// Get lyrics
|
||||
#[clap(long)]
|
||||
lyrics: bool,
|
||||
/// Get the player
|
||||
#[clap(long)]
|
||||
player: bool,
|
||||
},
|
||||
/// Search YouTube
|
||||
Search {
|
||||
|
|
@ -504,6 +507,7 @@ async fn main() {
|
|||
music,
|
||||
comments,
|
||||
lyrics,
|
||||
player,
|
||||
} => {
|
||||
let target = rp.query().resolve_string(&id, false).await.unwrap();
|
||||
|
||||
|
|
@ -521,6 +525,9 @@ async fn main() {
|
|||
} else if music {
|
||||
let details = rp.query().music_details(&id).await.unwrap();
|
||||
print_data(&details, format, pretty);
|
||||
} else if player {
|
||||
let player = rp.query().player(&id).await.unwrap();
|
||||
print_data(&player, format, pretty);
|
||||
} else {
|
||||
let mut details = rp.query().video_details(&id).await.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -486,7 +486,7 @@ impl<T> YouTubeListMapper<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn map_short_video(&mut self, video: ReelItemRenderer) -> VideoItem {
|
||||
fn map_short_video(&mut self, video: ReelItemRenderer, lang: Language) -> VideoItem {
|
||||
static ACCESSIBILITY_SEP_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(" [-\u{2013}] (.+) [-\u{2013}] ").unwrap());
|
||||
|
||||
|
|
@ -518,7 +518,7 @@ impl<T> YouTubeListMapper<T> {
|
|||
publish_date_txt: pub_date_txt,
|
||||
view_count: video
|
||||
.view_count_text
|
||||
.map(|txt| util::parse_numeric(&txt).unwrap_or_default()),
|
||||
.map(|txt| util::parse_large_numstr(&txt, lang).unwrap_or_default()),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -589,7 +589,7 @@ impl YouTubeListMapper<YouTubeItem> {
|
|||
self.items.push(mapped);
|
||||
}
|
||||
YouTubeListItem::ReelItemRenderer(video) => {
|
||||
let mapped = self.map_short_video(video);
|
||||
let mapped = self.map_short_video(video, self.lang);
|
||||
self.items.push(YouTubeItem::Video(mapped));
|
||||
}
|
||||
YouTubeListItem::PlaylistRenderer(playlist) => {
|
||||
|
|
@ -653,7 +653,7 @@ impl YouTubeListMapper<VideoItem> {
|
|||
self.items.push(mapped);
|
||||
}
|
||||
YouTubeListItem::ReelItemRenderer(video) => {
|
||||
let mapped = self.map_short_video(video);
|
||||
let mapped = self.map_short_video(video, self.lang);
|
||||
self.items.push(mapped);
|
||||
}
|
||||
YouTubeListItem::ContinuationItemRenderer {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 days ago"),
|
||||
view_count: Some(593),
|
||||
view_count: Some(593000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -165,7 +165,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("4 days ago"),
|
||||
view_count: Some(141),
|
||||
view_count: Some(141000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -191,7 +191,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("6 days ago"),
|
||||
view_count: Some(652),
|
||||
view_count: Some(652000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -217,7 +217,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("8 days ago"),
|
||||
view_count: Some(795),
|
||||
view_count: Some(795000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -243,7 +243,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("9 days ago"),
|
||||
view_count: Some(17),
|
||||
view_count: Some(1700000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -269,7 +269,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("11 days ago"),
|
||||
view_count: Some(1),
|
||||
view_count: Some(1000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -295,7 +295,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("13 days ago"),
|
||||
view_count: Some(15),
|
||||
view_count: Some(1500000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -321,7 +321,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(26),
|
||||
view_count: Some(2600000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -347,7 +347,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(864),
|
||||
view_count: Some(864000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -373,7 +373,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(21),
|
||||
view_count: Some(2100000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -399,7 +399,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(1),
|
||||
view_count: Some(1000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -425,7 +425,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(45),
|
||||
view_count: Some(4500000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -451,7 +451,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 weeks ago"),
|
||||
view_count: Some(18),
|
||||
view_count: Some(1800000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -477,7 +477,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 weeks ago"),
|
||||
view_count: Some(16),
|
||||
view_count: Some(1600000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -503,7 +503,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 weeks ago"),
|
||||
view_count: Some(13),
|
||||
view_count: Some(1300000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -529,7 +529,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(34),
|
||||
view_count: Some(3400000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -555,7 +555,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(13),
|
||||
view_count: Some(1300000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -581,7 +581,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(756),
|
||||
view_count: Some(756000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -607,7 +607,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(13),
|
||||
view_count: Some(1300000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -633,7 +633,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(39),
|
||||
view_count: Some(3900000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -659,7 +659,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(18),
|
||||
view_count: Some(1800000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -685,7 +685,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(31),
|
||||
view_count: Some(3100000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -711,7 +711,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(17),
|
||||
view_count: Some(1700000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -737,7 +737,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(18),
|
||||
view_count: Some(1800000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -763,7 +763,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(18),
|
||||
view_count: Some(1800000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -789,7 +789,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(11),
|
||||
view_count: Some(11000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -815,7 +815,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(31),
|
||||
view_count: Some(3100000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -841,7 +841,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(688),
|
||||
view_count: Some(688000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -867,7 +867,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(19),
|
||||
view_count: Some(1900000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -893,7 +893,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(1),
|
||||
view_count: Some(1000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -919,7 +919,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(64),
|
||||
view_count: Some(6400000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -945,7 +945,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(16),
|
||||
view_count: Some(16000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -971,7 +971,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(27),
|
||||
view_count: Some(2700000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -997,7 +997,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(25),
|
||||
view_count: Some(2500000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1023,7 +1023,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(2),
|
||||
view_count: Some(2000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1049,7 +1049,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(53),
|
||||
view_count: Some(5300000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1075,7 +1075,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(2),
|
||||
view_count: Some(2000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1101,7 +1101,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(91),
|
||||
view_count: Some(9100000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1127,7 +1127,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(26),
|
||||
view_count: Some(2600000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1153,7 +1153,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(65),
|
||||
view_count: Some(6500000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1179,7 +1179,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(22),
|
||||
view_count: Some(2200000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1205,7 +1205,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(66),
|
||||
view_count: Some(6600000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1231,7 +1231,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(39),
|
||||
view_count: Some(3900000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1257,7 +1257,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(978),
|
||||
view_count: Some(978000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1283,7 +1283,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(45),
|
||||
view_count: Some(4500000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1309,7 +1309,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(21),
|
||||
view_count: Some(2100000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1335,7 +1335,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(4),
|
||||
view_count: Some(4000000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
@ -1361,7 +1361,7 @@ Channel(
|
|||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(63),
|
||||
view_count: Some(6300000),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
is_upcoming: false,
|
||||
|
|
|
|||
|
|
@ -926,7 +926,6 @@ fn assert_channel_eevblog<T>(channel: &Channel<T>) {
|
|||
true
|
||||
)]
|
||||
#[case::music("UC-9-kyTW8ZkZNDHQJ6FgpwQ", "Music", false, false)]
|
||||
#[case::live("UC4R8DWoMoI7CAwX8_LjQHig", "Live", false, false)]
|
||||
#[case::news("UCYfdidRxbB8Qhf0Nx7ioOYw", "News", false, false)]
|
||||
fn channel_more(
|
||||
#[case] id: &str,
|
||||
|
|
@ -965,6 +964,7 @@ fn channel_more(
|
|||
#[case::movies("UCuJcl0Ju-gPDoksRjK1ya-w")]
|
||||
#[case::sports("UCEgdi0XIXXZ-qJOFPf4JSKw")]
|
||||
#[case::learning("UCtFRv9O2AHqOZjjynzrv-xg")]
|
||||
#[case::live("UC4R8DWoMoI7CAwX8_LjQHig")]
|
||||
fn channel_not_found(#[case] id: &str, rp: RustyPipe) {
|
||||
let err = tokio_test::block_on(rp.query().channel_videos(&id)).unwrap_err();
|
||||
|
||||
|
|
@ -1950,7 +1950,7 @@ fn music_charts(
|
|||
|
||||
assert_gte(charts.top_tracks.len(), 40, "top tracks");
|
||||
assert_gte(charts.artists.len(), 40, "top artists");
|
||||
assert_gte(charts.trending_tracks.len(), 20, "trending tracks");
|
||||
assert_gte(charts.trending_tracks.len(), 15, "trending tracks");
|
||||
|
||||
// Chart playlists only available in USA
|
||||
if country == Country::Us {
|
||||
|
|
|
|||
Reference in a new issue