use crate::{py_err, py_to_json, with_gil, Result, YTMusic};
use pyo3::prelude::*;
use pyo3::types::PyDict;
use serde_json::Value;
impl YTMusic {
pub fn get_home(&self, limit: Option<u32>) -> Result<Value> {
with_gil(|py| {
let inner = self.inner.bind(py);
let kw = PyDict::new(py);
if let Some(v) = limit { kw.set_item("limit", v)?; }
let result = inner.call_method("get_home", (), Some(&kw))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_artist(&self, channel_id: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_artist", (channel_id,))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_artist_albums(
&self,
channel_id: &str,
params: &str,
limit: Option<u32>,
order: Option<&str>,
) -> Result<Value> {
with_gil(|py| {
let kw = PyDict::new(py);
kw.set_item("channelId", channel_id)?;
kw.set_item("params", params)?;
if let Some(v) = limit { kw.set_item("limit", v)?; }
if let Some(v) = order { kw.set_item("order", v)?; }
let result = self.inner.bind(py).call_method("get_artist_albums", (), Some(&kw))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_album(&self, browse_id: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_album", (browse_id,))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_album_browse_id(&self, audio_playlist_id: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_album_browse_id", (audio_playlist_id,))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_song(&self, video_id: &str, signature_timestamp: Option<u64>) -> Result<Value> {
with_gil(|py| {
let inner = self.inner.bind(py);
let kw = PyDict::new(py);
kw.set_item("videoId", video_id)?;
if let Some(v) = signature_timestamp { kw.set_item("signatureTimestamp", v)?; }
let result = inner.call_method("get_song", (), Some(&kw))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_song_related(&self, browse_id: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_song_related", (browse_id,))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_lyrics(&self, browse_id: &str, timestamps: Option<bool>) -> Result<Value> {
with_gil(|py| {
let kw = PyDict::new(py);
kw.set_item("browseId", browse_id)?;
if let Some(v) = timestamps { kw.set_item("timestamps", v)?; }
let result = self.inner.bind(py).call_method("get_lyrics", (), Some(&kw))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_user(&self, channel_id: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_user", (channel_id,))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_user_playlists(&self, channel_id: &str, params: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_user_playlists", (channel_id, params))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_user_videos(&self, channel_id: &str, params: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_user_videos", (channel_id, params))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
pub fn get_song_credits(&self, browse_id: &str) -> Result<Value> {
with_gil(|py| {
let result = self.inner.bind(py).call_method1("get_song_credits", (browse_id,))?;
py_to_json(py, &result)
})
.map_err(py_err)
}
}