Musyx Mobile: Android TV player for Yandex Music
Kotlin, Compose for TV and Media3 port of the desktop Musyx, with device-code sign-in, Home, My Wave, search, collection, detail pages, Now Playing with queue and lyrics, and settings for streaming quality, appearance, font size (small, medium, large) and language. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
46610d95fa
217 files changed
+26144
No files matched your search
@@ -0,0 +1,163 @@
|
||||
//! Headless-ish visual check: render one screen, save it as a PNG, quit.
|
||||
//!
|
||||
//! ```sh
|
||||
//! MUSYX_SNAPSHOT=home.png MUSYX_SNAPSHOT_ROUTE=wave MUSYX_SNAPSHOT_DRAWER=queue \
|
||||
//! MUSYX_SNAPSHOT_THEME=light MUSYX_SNAPSHOT_LANG=ru cargo run -p musyx --features snapshot
|
||||
//! ```
|
||||
//! iced's own `window::screenshot` is used, so it needs no screen-recording permission.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
|
||||
use iced::Task;
|
||||
use iced::theme::Mode;
|
||||
use iced::window;
|
||||
|
||||
use ym_api::{Account, YmClient};
|
||||
|
||||
use crate::app::Session;
|
||||
use crate::i18n::Lang;
|
||||
use crate::route::Route;
|
||||
use crate::widgets::drawer::Panel;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub out: PathBuf,
|
||||
/// `MUSYX_SNAPSHOT_ROUTE=signin` shows the sign-in page instead of a signed-in shell.
|
||||
pub signed_out: bool,
|
||||
pub route: Option<Route>,
|
||||
pub drawer: Option<Panel>,
|
||||
pub mode: Option<Mode>,
|
||||
/// `MUSYX_SNAPSHOT_LIVE=1`: sign in with the stored account instead of sample data.
|
||||
pub live: bool,
|
||||
/// `MUSYX_SNAPSHOT_LANG=ru` or `en` overrides the language setting.
|
||||
pub lang: Option<Lang>,
|
||||
/// `MUSYX_SNAPSHOT_DELAY` in ms before capturing (default 1500; live runs need longer).
|
||||
pub delay: Duration,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_env() -> Option<Self> {
|
||||
let out = PathBuf::from(std::env::var_os("MUSYX_SNAPSHOT")?);
|
||||
let var = |k: &str| std::env::var(k).ok().map(|v| v.to_ascii_lowercase());
|
||||
let signed_out = var("MUSYX_SNAPSHOT_ROUTE").as_deref() == Some("signin");
|
||||
let route = var("MUSYX_SNAPSHOT_ROUTE").and_then(|r| {
|
||||
Some(match r.as_str() {
|
||||
"home" => Route::Home,
|
||||
"wave" => Route::Wave,
|
||||
"search" => Route::Search,
|
||||
"collection" => Route::Collection,
|
||||
"podcasts" => Route::Podcasts,
|
||||
"settings" => Route::Settings,
|
||||
"album" => Route::Album(1),
|
||||
"chart" => Route::Chart,
|
||||
// `artist:41075`, for live runs.
|
||||
other => Route::Artist(other.strip_prefix("artist:")?.parse().ok()?),
|
||||
})
|
||||
});
|
||||
let drawer = var("MUSYX_SNAPSHOT_DRAWER").and_then(|d| match d.as_str() {
|
||||
"queue" => Some(Panel::Queue),
|
||||
"lyrics" => Some(Panel::Lyrics),
|
||||
_ => None,
|
||||
});
|
||||
let mode = var("MUSYX_SNAPSHOT_THEME").and_then(|m| match m.as_str() {
|
||||
"light" => Some(Mode::Light),
|
||||
"dark" => Some(Mode::Dark),
|
||||
_ => None,
|
||||
});
|
||||
let lang = var("MUSYX_SNAPSHOT_LANG").map(|l| Lang::from_tag(&l));
|
||||
let live = var("MUSYX_SNAPSHOT_LIVE").is_some_and(|v| v == "1");
|
||||
let delay = var("MUSYX_SNAPSHOT_DELAY")
|
||||
.and_then(|d| d.parse().ok())
|
||||
.map_or(Duration::from_millis(if live { 8000 } else { 1500 }), Duration::from_millis);
|
||||
Some(Self { out, signed_out, route, drawer, mode, lang, live, delay })
|
||||
}
|
||||
|
||||
/// A made-up account so the shell renders without a network or keychain.
|
||||
pub fn session(&self) -> Session {
|
||||
if self.signed_out {
|
||||
return Session::SignedOut(Box::default());
|
||||
}
|
||||
Session::SignedIn {
|
||||
client: YmClient::unauthenticated().expect("client"),
|
||||
account: Account {
|
||||
uid: 1,
|
||||
login: "sample.listener".into(),
|
||||
name: "Sample Listener".into(),
|
||||
has_plus: true,
|
||||
subscription_end: Some("2027-01-05T00:00:00+03:00".into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Sample liked tracks so the Collection list has rows.
|
||||
pub fn sample_liked(&self) -> Vec<ym_api::Track> {
|
||||
[
|
||||
("1", "Звезда по имени Солнце", "Кино", 7, "Звезда по имени Солнце", 225),
|
||||
("2", "Хочешь?", "Земфира", 3, "Прости меня моя любовь", 225),
|
||||
("3", "Выхода нет", "Сплин", 25, "Гранатовый альбом", 230),
|
||||
("4", "Полковнику никто не пишет", "Би-2", 280, "Би-2", 285),
|
||||
("5", "Владивосток 2000", "Мумий Тролль", 185, "Морская", 165),
|
||||
("6", "Город золотой", "Аквариум", 48, "Десять стрел", 205),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(id, title, artist, album, album_title, secs)| {
|
||||
ym_api::Track::from_json(&format!(
|
||||
r#"{{"id":"{id}","title":"{title}","durationMs":{ms},"artists":[{{"name":"{artist}"}}],
|
||||
"albums":[{{"id":{album},"title":"{album_title}"}}]}}"#,
|
||||
ms = secs * 1000
|
||||
))
|
||||
.expect("sample track")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A sample album page for `MUSYX_SNAPSHOT_ROUTE=album`.
|
||||
pub fn sample_album(&self) -> crate::screens::detail::Page {
|
||||
let tracks: Vec<String> = [
|
||||
("Группа крови", 286), ("Закрой за мной дверь, я ухожу", 256), ("Война", 274),
|
||||
("Попробуй спеть вместе со мной", 283), ("Звезда по имени Солнце", 225), ("Спокойная ночь", 366),
|
||||
]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, (title, secs))| {
|
||||
format!(r#"{{"id":{},"title":"{title}","durationMs":{},"artists":[{{"id":1,"name":"Кино"}}]}}"#, i + 1, secs * 1000)
|
||||
})
|
||||
.collect();
|
||||
let json = format!(
|
||||
r#"{{"id":1,"title":"Группа крови","year":1988,"artists":[{{"id":1,"name":"Кино"}}],
|
||||
"labels":["Мелодия"],"volumes":[[{}]]}}"#,
|
||||
tracks.join(",")
|
||||
);
|
||||
let mut info = ym_api::AlbumPage::from_json(&json).expect("sample album");
|
||||
let tracks = std::mem::take(&mut info.tracks).into();
|
||||
crate::screens::detail::Page::Album { info, tracks }
|
||||
}
|
||||
|
||||
/// Waits for fonts and the first frames, captures the window, writes the PNG, exits.
|
||||
pub fn capture<M: Send + 'static>(self) -> Task<M> {
|
||||
Task::future(tokio::time::sleep(self.delay))
|
||||
.then(|()| window::latest())
|
||||
.then(|id| match id {
|
||||
Some(id) => window::screenshot(id),
|
||||
None => Task::none(),
|
||||
})
|
||||
.then(move |shot| {
|
||||
if let Err(e) = write_png(&self.out, &shot) {
|
||||
eprintln!("snapshot: {e}");
|
||||
} else {
|
||||
eprintln!("snapshot: wrote {}", self.out.display());
|
||||
}
|
||||
iced::exit()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn write_png(path: &std::path::Path, shot: &window::Screenshot) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let file = std::io::BufWriter::new(std::fs::File::create(path)?);
|
||||
let mut encoder = png::Encoder::new(file, shot.size.width, shot.size.height);
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
encoder.set_depth(png::BitDepth::Eight);
|
||||
encoder.write_header()?.write_image_data(&shot.rgba)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user