Merge branch 'russian-locale'
This commit is contained in:
commit
33c48de638
35 files changed
+1073
-308
No files matched your search
@@ -116,17 +116,50 @@ impl std::fmt::Debug for YmClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// The language Yandex writes its own titles in: genres, Home blocks, stations.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ContentLanguage {
|
||||
Russian,
|
||||
English,
|
||||
}
|
||||
|
||||
impl ContentLanguage {
|
||||
fn yamuse(self) -> yamuse::Language {
|
||||
match self {
|
||||
ContentLanguage::Russian => yamuse::Language::Ru,
|
||||
ContentLanguage::English => yamuse::Language::En,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl YmClient {
|
||||
/// Builds a client for `credentials` and loads the account. Fails with
|
||||
/// [`crate::Error::Unauthorized`] when the token is no longer valid.
|
||||
pub async fn connect(credentials: &Credentials) -> Result<(Self, Account)> {
|
||||
let inner = yamuse::Client::builder().token(&credentials.access_token).build()?;
|
||||
pub async fn connect(credentials: &Credentials, language: ContentLanguage) -> Result<(Self, Account)> {
|
||||
let inner = yamuse::Client::builder()
|
||||
.token(&credentials.access_token)
|
||||
.language(language.yamuse())
|
||||
.build()?;
|
||||
let status = inner.refresh_account().await?;
|
||||
let account = Account::from_status(status)
|
||||
.ok_or_else(|| Error::Unauthorized("account status has no user".into()))?;
|
||||
Ok((Self { inner, token: Some(credentials.access_token.as_str().into()) }, account))
|
||||
}
|
||||
|
||||
/// The same account, with Yandex answering in `language`. Loads the account
|
||||
/// again, since that's how the client learns whose library it reads.
|
||||
pub async fn in_language(&self, language: ContentLanguage) -> Result<Self> {
|
||||
let mut builder = yamuse::Client::builder().language(language.yamuse());
|
||||
if let Some(token) = &self.token {
|
||||
builder = builder.token(token.as_ref());
|
||||
}
|
||||
let inner = builder.build()?;
|
||||
if self.token.is_some() {
|
||||
inner.init().await?;
|
||||
}
|
||||
Ok(Self { inner, token: self.token.clone() })
|
||||
}
|
||||
|
||||
/// A client with no token, for previews and tests. Every account call fails.
|
||||
pub fn unauthenticated() -> Result<Self> {
|
||||
Ok(Self { inner: yamuse::Client::anonymous()?, token: None })
|
||||
|
||||
@@ -13,7 +13,7 @@ mod library;
|
||||
mod models;
|
||||
mod wave;
|
||||
|
||||
pub use client::{Account, YmClient};
|
||||
pub use client::{Account, ContentLanguage, YmClient};
|
||||
pub use clips::Clip;
|
||||
pub use library::{
|
||||
AlbumKind, AlbumPage, AlbumSummary, ArtistPage, ArtistSummary, LibraryPlaylists, PlaylistId,
|
||||
|
||||
@@ -16,6 +16,9 @@ pub enum AlbumKind {
|
||||
}
|
||||
|
||||
impl AlbumKind {
|
||||
pub const ALL: [AlbumKind; 5] =
|
||||
[AlbumKind::Album, AlbumKind::Single, AlbumKind::Compilation, AlbumKind::Podcast, AlbumKind::Audiobook];
|
||||
|
||||
fn from_api(meta_type: Option<&str>, kind: Option<&str>) -> Self {
|
||||
match (meta_type, kind) {
|
||||
(Some("podcast"), _) | (_, Some("podcast")) => AlbumKind::Podcast,
|
||||
|
||||
Reference in new issue
Block a user