feat: CLI: setting player type

This commit is contained in:
ThetaDev 2024-04-26 16:09:13 +02:00
parent 5f1e1a2a5c
commit 2f132c047b

View file

@ -8,7 +8,7 @@ use futures::stream::{self, StreamExt};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use reqwest::{Client, ClientBuilder}; use reqwest::{Client, ClientBuilder};
use rustypipe::{ use rustypipe::{
client::RustyPipe, client::{ClientType, RustyPipe},
model::{UrlTarget, VideoId, YouTubeItem}, model::{UrlTarget, VideoId, YouTubeItem},
param::{search_filter, ChannelVideoTab, Country, Language, StreamFilter}, param::{search_filter, ChannelVideoTab, Country, Language, StreamFilter},
}; };
@ -81,6 +81,8 @@ enum Commands {
/// Get the player /// Get the player
#[clap(long)] #[clap(long)]
player: bool, player: bool,
#[clap(long)]
player_type: Option<PlayerType>,
}, },
/// Search YouTube /// Search YouTube
Search { Search {
@ -189,6 +191,14 @@ enum MusicSearchCategory {
PlaylistsCommunity, PlaylistsCommunity,
} }
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
enum PlayerType {
Desktop,
Tv,
Android,
Ios,
}
impl From<SearchItemType> for search_filter::ItemType { impl From<SearchItemType> for search_filter::ItemType {
fn from(value: SearchItemType) -> Self { fn from(value: SearchItemType) -> Self {
match value { match value {
@ -231,6 +241,17 @@ impl From<SearchOrder> for search_filter::Order {
} }
} }
impl From<PlayerType> for ClientType {
fn from(value: PlayerType) -> Self {
match value {
PlayerType::Desktop => Self::Desktop,
PlayerType::Tv => Self::TvHtml5Embed,
PlayerType::Android => Self::Android,
PlayerType::Ios => Self::Ios,
}
}
}
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn download_single_video( async fn download_single_video(
video_id: &str, video_id: &str,
@ -540,6 +561,7 @@ async fn main() {
comments, comments,
lyrics, lyrics,
player, player,
player_type,
} => { } => {
let target = rp.query().resolve_string(&id, false).await.unwrap(); let target = rp.query().resolve_string(&id, false).await.unwrap();
@ -558,7 +580,12 @@ async fn main() {
let details = rp.query().music_details(&id).await.unwrap(); let details = rp.query().music_details(&id).await.unwrap();
print_data(&details, format, pretty); print_data(&details, format, pretty);
} else if player { } else if player {
let player = rp.query().player(&id).await.unwrap(); let player = if let Some(player_type) = player_type {
rp.query().player_from_client(&id, player_type.into()).await
} else {
rp.query().player(&id).await
}
.unwrap();
print_data(&player, format, pretty); print_data(&player, format, pretty);
} else { } else {
let mut details = rp.query().video_details(&id).await.unwrap(); let mut details = rp.query().video_details(&id).await.unwrap();