Compare commits
5 commits
6c41ef2fb2
...
b4a6658e33
Author | SHA1 | Date | |
---|---|---|---|
b4a6658e33 | |||
16e0e28c48 | |||
8fbd6b95b6 | |||
77ee923778 | |||
a8fb337fae |
11 changed files with 112 additions and 82 deletions
|
@ -8,7 +8,7 @@ use futures::stream::{self, StreamExt};
|
|||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||
use reqwest::{Client, ClientBuilder};
|
||||
use rustypipe::{
|
||||
client::RustyPipe,
|
||||
client::{ClientType, RustyPipe},
|
||||
model::{UrlTarget, VideoId, YouTubeItem},
|
||||
param::{search_filter, ChannelVideoTab, Country, Language, StreamFilter},
|
||||
};
|
||||
|
@ -81,6 +81,8 @@ enum Commands {
|
|||
/// Get the player
|
||||
#[clap(long)]
|
||||
player: bool,
|
||||
#[clap(long)]
|
||||
player_type: Option<PlayerType>,
|
||||
},
|
||||
/// Search YouTube
|
||||
Search {
|
||||
|
@ -189,6 +191,14 @@ enum MusicSearchCategory {
|
|||
PlaylistsCommunity,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
|
||||
enum PlayerType {
|
||||
Desktop,
|
||||
Tv,
|
||||
Android,
|
||||
Ios,
|
||||
}
|
||||
|
||||
impl From<SearchItemType> for search_filter::ItemType {
|
||||
fn from(value: SearchItemType) -> Self {
|
||||
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)]
|
||||
async fn download_single_video(
|
||||
video_id: &str,
|
||||
|
@ -540,6 +561,7 @@ async fn main() {
|
|||
comments,
|
||||
lyrics,
|
||||
player,
|
||||
player_type,
|
||||
} => {
|
||||
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();
|
||||
print_data(&details, format, pretty);
|
||||
} 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);
|
||||
} else {
|
||||
let mut details = rp.query().video_details(&id).await.unwrap();
|
||||
|
|
|
@ -192,19 +192,15 @@ const YOUTUBE_MUSIC_V1_URL: &str = "https://music.youtube.com/youtubei/v1/";
|
|||
const YOUTUBE_HOME_URL: &str = "https://www.youtube.com/";
|
||||
const YOUTUBE_MUSIC_HOME_URL: &str = "https://music.youtube.com/";
|
||||
|
||||
const DISABLE_PRETTY_PRINT_PARAMETER: &str = "&prettyPrint=false";
|
||||
const DISABLE_PRETTY_PRINT_PARAMETER: &str = "prettyPrint=false";
|
||||
|
||||
// Desktop client
|
||||
const DESKTOP_CLIENT_VERSION: &str = "2.20230126.00.00";
|
||||
const DESKTOP_API_KEY: &str = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
|
||||
const TVHTML5_CLIENT_VERSION: &str = "2.0";
|
||||
const DESKTOP_MUSIC_API_KEY: &str = "AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30";
|
||||
const DESKTOP_MUSIC_CLIENT_VERSION: &str = "1.20230123.01.01";
|
||||
|
||||
// Mobile client
|
||||
const MOBILE_CLIENT_VERSION: &str = "18.03.33";
|
||||
const ANDROID_API_KEY: &str = "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w";
|
||||
const IOS_API_KEY: &str = "AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc";
|
||||
const IOS_DEVICE_MODEL: &str = "iPhone14,5";
|
||||
|
||||
static CLIENT_VERSION_REGEX: Lazy<Regex> =
|
||||
|
@ -1189,7 +1185,7 @@ impl RustyPipeQuery {
|
|||
.inner
|
||||
.http
|
||||
.post(format!(
|
||||
"{YOUTUBEI_V1_URL}{endpoint}?key={DESKTOP_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
"{YOUTUBEI_V1_URL}{endpoint}?{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
))
|
||||
.header(header::ORIGIN, YOUTUBE_HOME_URL)
|
||||
.header(header::REFERER, YOUTUBE_HOME_URL)
|
||||
|
@ -1204,7 +1200,7 @@ impl RustyPipeQuery {
|
|||
.inner
|
||||
.http
|
||||
.post(format!(
|
||||
"{YOUTUBE_MUSIC_V1_URL}{endpoint}?key={DESKTOP_MUSIC_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
"{YOUTUBE_MUSIC_V1_URL}{endpoint}?{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
))
|
||||
.header(header::ORIGIN, YOUTUBE_MUSIC_HOME_URL)
|
||||
.header(header::REFERER, YOUTUBE_MUSIC_HOME_URL)
|
||||
|
@ -1212,14 +1208,14 @@ impl RustyPipeQuery {
|
|||
.header("X-YouTube-Client-Name", "67")
|
||||
.header(
|
||||
"X-YouTube-Client-Version",
|
||||
self.client.get_music_client_version().await
|
||||
self.client.get_music_client_version().await,
|
||||
),
|
||||
ClientType::TvHtml5Embed => self
|
||||
.client
|
||||
.inner
|
||||
.http
|
||||
.post(format!(
|
||||
"{YOUTUBEI_V1_URL}{endpoint}?key={DESKTOP_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
"{YOUTUBEI_V1_URL}{endpoint}?{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
))
|
||||
.header(header::ORIGIN, YOUTUBE_HOME_URL)
|
||||
.header(header::REFERER, YOUTUBE_HOME_URL)
|
||||
|
@ -1230,7 +1226,7 @@ impl RustyPipeQuery {
|
|||
.inner
|
||||
.http
|
||||
.post(format!(
|
||||
"{YOUTUBEI_V1_GAPIS_URL}{endpoint}?key={ANDROID_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
"{YOUTUBEI_V1_GAPIS_URL}{endpoint}?{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
))
|
||||
.header(
|
||||
header::USER_AGENT,
|
||||
|
@ -1245,7 +1241,7 @@ impl RustyPipeQuery {
|
|||
.inner
|
||||
.http
|
||||
.post(format!(
|
||||
"{YOUTUBEI_V1_GAPIS_URL}{endpoint}?key={IOS_API_KEY}{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
"{YOUTUBEI_V1_GAPIS_URL}{endpoint}?{DISABLE_PRETTY_PRINT_PARAMETER}"
|
||||
))
|
||||
.header(
|
||||
header::USER_AGENT,
|
||||
|
|
|
@ -306,19 +306,14 @@ impl MapResponse<Lyrics> for response::MusicLyrics {
|
|||
) -> Result<MapResult<Lyrics>, ExtractionError> {
|
||||
let lyrics = self
|
||||
.contents
|
||||
.section_list_renderer
|
||||
.and_then(|sl| {
|
||||
sl.contents
|
||||
.into_res()
|
||||
.map_err(|msg| ExtractionError::NotFound {
|
||||
id: id.to_owned(),
|
||||
msg: msg.into(),
|
||||
})?
|
||||
.into_iter()
|
||||
.find_map(|item| item.music_description_shelf_renderer)
|
||||
})
|
||||
.ok_or(match self.contents.message_renderer {
|
||||
Some(msg) => ExtractionError::NotFound {
|
||||
id: id.to_owned(),
|
||||
msg: msg.text.into(),
|
||||
},
|
||||
None => ExtractionError::InvalidData(Cow::Borrowed("no content")),
|
||||
})?;
|
||||
.ok_or(ExtractionError::InvalidData(Cow::Borrowed("no content")))?;
|
||||
|
||||
Ok(MapResult {
|
||||
c: Lyrics {
|
||||
|
@ -333,18 +328,21 @@ impl MapResponse<Lyrics> for response::MusicLyrics {
|
|||
impl MapResponse<MusicRelated> for response::MusicRelated {
|
||||
fn map_response(
|
||||
self,
|
||||
_id: &str,
|
||||
id: &str,
|
||||
lang: Language,
|
||||
_deobf: Option<&crate::deobfuscate::DeobfData>,
|
||||
_vdata: Option<&str>,
|
||||
) -> Result<MapResult<MusicRelated>, ExtractionError> {
|
||||
let contents = self
|
||||
.contents
|
||||
.into_res()
|
||||
.map_err(|msg| ExtractionError::NotFound {
|
||||
id: id.to_owned(),
|
||||
msg: msg.into(),
|
||||
})?;
|
||||
|
||||
// Find artist
|
||||
let artist_id = self
|
||||
.contents
|
||||
.section_list_renderer
|
||||
.contents
|
||||
.iter()
|
||||
.find_map(|section| match section {
|
||||
let artist_id = contents.iter().find_map(|section| match section {
|
||||
response::music_item::ItemSection::MusicCarouselShelfRenderer(shelf) => {
|
||||
shelf.header.as_ref().and_then(|h| {
|
||||
h.music_carousel_shelf_basic_header_renderer
|
||||
|
@ -370,7 +368,7 @@ impl MapResponse<MusicRelated> for response::MusicRelated {
|
|||
None => MusicListMapper::new(lang),
|
||||
};
|
||||
|
||||
let mut sections = self.contents.section_list_renderer.contents.into_iter();
|
||||
let mut sections = contents.into_iter();
|
||||
if let Some(response::music_item::ItemSection::MusicCarouselShelfRenderer(shelf)) =
|
||||
sections.next()
|
||||
{
|
||||
|
|
|
@ -128,8 +128,8 @@ impl RustyPipeQuery {
|
|||
video_id,
|
||||
content_check_ok: true,
|
||||
racy_check_ok: true,
|
||||
// Source: https://github.com/TeamNewPipe/NewPipeExtractor/pull/1084
|
||||
params: Some("CgIQBg").filter(|_| client_type == ClientType::Android),
|
||||
// Source: https://github.com/TeamNewPipe/NewPipeExtractor/pull/1168
|
||||
params: Some("CgIIAQ%3D%3D").filter(|_| client_type == ClientType::Android),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use super::AlertRenderer;
|
|||
use super::ContentsRenderer;
|
||||
use super::{
|
||||
music_item::{ItemSection, PlaylistPanelRenderer},
|
||||
ContentRenderer, SectionList,
|
||||
ContentRenderer,
|
||||
};
|
||||
|
||||
/// Response model for YouTube Music track details
|
||||
|
@ -108,14 +108,14 @@ pub(crate) struct PlaylistPanel {
|
|||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct MusicLyrics {
|
||||
pub contents: LyricsContents,
|
||||
pub contents: ListOrMessage<LyricsSection>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct LyricsContents {
|
||||
pub message_renderer: Option<AlertRenderer>,
|
||||
pub section_list_renderer: Option<ContentsRenderer<LyricsSection>>,
|
||||
pub(crate) enum ListOrMessage<T> {
|
||||
SectionListRenderer(ContentsRenderer<T>),
|
||||
MessageRenderer(AlertRenderer),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -137,5 +137,14 @@ pub(crate) struct LyricsRenderer {
|
|||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct MusicRelated {
|
||||
pub contents: SectionList<ItemSection>,
|
||||
pub contents: ListOrMessage<ItemSection>,
|
||||
}
|
||||
|
||||
impl<T> ListOrMessage<T> {
|
||||
pub fn into_res(self) -> Result<Vec<T>, String> {
|
||||
match self {
|
||||
ListOrMessage::SectionListRenderer(c) => Ok(c.contents),
|
||||
ListOrMessage::MessageRenderer(msg) => Err(msg.text),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "aGd3VKSOTxY",
|
||||
name: "Ich wache auf",
|
||||
duration: Some(221),
|
||||
duration: Some(222),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -43,7 +43,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "Jz-26iiDuYs",
|
||||
name: "Waldbrand",
|
||||
duration: Some(208),
|
||||
duration: Some(209),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -64,7 +64,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "Bu26uFtpt58",
|
||||
name: "Verlernt",
|
||||
duration: Some(223),
|
||||
duration: Some(224),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -85,7 +85,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "RgwNqqiVqdY",
|
||||
name: "In Farbe",
|
||||
duration: Some(221),
|
||||
duration: Some(222),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -106,7 +106,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "2TuOh30XbCI",
|
||||
name: "Stadt im Hinterland",
|
||||
duration: Some(197),
|
||||
duration: Some(198),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
|
|
@ -22,7 +22,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "aGd3VKSOTxY",
|
||||
name: "[name]",
|
||||
duration: Some(221),
|
||||
duration: Some(222),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -43,7 +43,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "Jz-26iiDuYs",
|
||||
name: "[name]",
|
||||
duration: Some(208),
|
||||
duration: Some(209),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -64,7 +64,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "Bu26uFtpt58",
|
||||
name: "[name]",
|
||||
duration: Some(223),
|
||||
duration: Some(224),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -85,7 +85,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "RgwNqqiVqdY",
|
||||
name: "[name]",
|
||||
duration: Some(221),
|
||||
duration: Some(222),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -106,7 +106,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "2TuOh30XbCI",
|
||||
name: "[name]",
|
||||
duration: Some(197),
|
||||
duration: Some(198),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
|
|
@ -63,11 +63,11 @@ MusicAlbum(
|
|||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
id: Some("UCUhWwvF6gIPWTYlYb4-icLA"),
|
||||
id: Some("UC_KQPMiRQl3CFAIKTVfCHwA"),
|
||||
name: "L.r. Eswari",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCUhWwvF6gIPWTYlYb4-icLA"),
|
||||
artist_id: Some("UC_KQPMiRQl3CFAIKTVfCHwA"),
|
||||
album: Some(AlbumId(
|
||||
id: "MPREb_bqWA6mAZFWS",
|
||||
name: "Pedha Rasi Peddamma Katha",
|
||||
|
|
|
@ -63,11 +63,11 @@ MusicAlbum(
|
|||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
id: Some("UCUhWwvF6gIPWTYlYb4-icLA"),
|
||||
id: Some("UC_KQPMiRQl3CFAIKTVfCHwA"),
|
||||
name: "[name]",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCUhWwvF6gIPWTYlYb4-icLA"),
|
||||
artist_id: Some("UC_KQPMiRQl3CFAIKTVfCHwA"),
|
||||
album: Some(AlbumId(
|
||||
id: "MPREb_bqWA6mAZFWS",
|
||||
name: "[name]",
|
||||
|
|
|
@ -26,7 +26,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "AKJ3IJZKPWc",
|
||||
name: "Oh Javaraala",
|
||||
duration: Some(228),
|
||||
duration: Some(229),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -51,7 +51,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "WnpZuHNB33E",
|
||||
name: "Siva Manoranjani",
|
||||
duration: Some(266),
|
||||
duration: Some(267),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -72,7 +72,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "pRqoDGXg1-I",
|
||||
name: "Gulabi Buggalunna",
|
||||
duration: Some(154),
|
||||
duration: Some(155),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -93,7 +93,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "20vIKLJxjBY",
|
||||
name: "Kuluku Nadakula",
|
||||
duration: Some(178),
|
||||
duration: Some(179),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
|
|
@ -26,7 +26,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "AKJ3IJZKPWc",
|
||||
name: "[name]",
|
||||
duration: Some(228),
|
||||
duration: Some(229),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -51,7 +51,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "WnpZuHNB33E",
|
||||
name: "[name]",
|
||||
duration: Some(266),
|
||||
duration: Some(267),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -72,7 +72,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "pRqoDGXg1-I",
|
||||
name: "[name]",
|
||||
duration: Some(154),
|
||||
duration: Some(155),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
@ -93,7 +93,7 @@ MusicAlbum(
|
|||
TrackItem(
|
||||
id: "20vIKLJxjBY",
|
||||
name: "[name]",
|
||||
duration: Some(178),
|
||||
duration: Some(179),
|
||||
cover: [],
|
||||
artists: [
|
||||
ArtistId(
|
||||
|
|
Loading…
Reference in a new issue