mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Music videos: keep video and audio, switch between them at the same moment
- Save as Video can also keep a matching audio file (on by default, recommended), copied losslessly from the video where possible - Songs with a video beside them get a video badge; video-only files play as songs - Video button (V) shows the music video in TV mode, kept in sync with the song, so switching between the cover and the video never interrupts playback
This commit is contained in:
@@ -173,6 +173,7 @@ cargo tauri build
|
|||||||
| `L` | Lyrics |
|
| `L` | Lyrics |
|
||||||
| `Q` | Queue |
|
| `Q` | Queue |
|
||||||
| `F` | TV mode |
|
| `F` | TV mode |
|
||||||
|
| `V` | Show the music video, when a song has one |
|
||||||
| `Ctrl K` | Search your library, or paste a link |
|
| `Ctrl K` | Search your library, or paste a link |
|
||||||
| `Ctrl L` | Get: the link and online search bar |
|
| `Ctrl L` | Get: the link and online search bar |
|
||||||
| `Ctrl B` | Collapse or expand the sidebar |
|
| `Ctrl B` | Collapse or expand the sidebar |
|
||||||
|
|||||||
@@ -352,6 +352,26 @@ impl Job {
|
|||||||
notes.push(format!("Saved, but your metadata edits couldn't be written ({e})."));
|
notes.push(format!("Saved, but your metadata edits couldn't be written ({e})."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let path = if plan.video && settings.video_keep_audio {
|
||||||
|
match (tools.ffmpeg.as_deref(), &path) {
|
||||||
|
(Some(ff), video) => match extract_audio(ff, video).await {
|
||||||
|
Ok(audio) => {
|
||||||
|
if settings.embed_metadata {
|
||||||
|
let _ = tagging::apply(&audio, &req.meta, &req.entry.url, Some(ff)).await;
|
||||||
|
}
|
||||||
|
notes.push("Saved the video and a matching audio file. Play it as a song, and show the video any time.".into());
|
||||||
|
audio
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
notes.push(format!("Saved the video, but the audio file couldn't be made ({e})."));
|
||||||
|
path
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => path,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
path
|
||||||
|
};
|
||||||
self.progress = 1.0;
|
self.progress = 1.0;
|
||||||
let note = (!notes.is_empty()).then(|| notes.join(" "));
|
let note = (!notes.is_empty()).then(|| notes.join(" "));
|
||||||
self.emit("done", note, Some(&path));
|
self.emit("done", note, Some(&path));
|
||||||
@@ -656,6 +676,29 @@ async fn cleanup(dir: &Path, stem: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn extract_audio(ffmpeg: &Path, video: &Path) -> Result<PathBuf> {
|
||||||
|
let mp4 = video.extension().is_some_and(|e| e.eq_ignore_ascii_case("mp4") || e.eq_ignore_ascii_case("m4v") || e.eq_ignore_ascii_case("mov"));
|
||||||
|
let attempts: Vec<(&str, Vec<&str>)> = if mp4 {
|
||||||
|
vec![("m4a", vec!["-c:a", "copy"]), ("m4a", vec!["-c:a", "aac", "-b:a", "256k"])]
|
||||||
|
} else {
|
||||||
|
vec![("opus", vec!["-c:a", "copy"]), ("m4a", vec!["-c:a", "aac", "-b:a", "256k"])]
|
||||||
|
};
|
||||||
|
for (ext, codec) in attempts {
|
||||||
|
let out = video.with_extension(ext);
|
||||||
|
let mut args: Vec<String> = ["-hide_banner", "-loglevel", "error", "-y", "-i"].map(String::from).into();
|
||||||
|
args.push(video.to_string_lossy().into_owned());
|
||||||
|
args.extend(["-map", "0:a:0", "-vn", "-map_metadata", "0"].map(String::from));
|
||||||
|
args.extend(codec.iter().map(|c| c.to_string()));
|
||||||
|
args.push(out.to_string_lossy().into_owned());
|
||||||
|
let ok = engine::command(ffmpeg).args(&args).stdout(Stdio::null()).stderr(Stdio::null()).status().await.is_ok_and(|s| s.success());
|
||||||
|
if ok && out.metadata().is_ok_and(|m| m.len() > 0) {
|
||||||
|
return Ok(out);
|
||||||
|
}
|
||||||
|
let _ = tokio::fs::remove_file(&out).await;
|
||||||
|
}
|
||||||
|
bail!("ffmpeg couldn't read the video's audio")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn target_dir(settings: &Settings, req: &JobRequest) -> PathBuf {
|
pub fn target_dir(settings: &Settings, req: &JobRequest) -> PathBuf {
|
||||||
let base = PathBuf::from(&settings.output_dir);
|
let base = PathBuf::from(&settings.output_dir);
|
||||||
let named = req.folder.as_deref().map(str::trim).filter(|n| !n.is_empty() && settings.collection_folders);
|
let named = req.folder.as_deref().map(str::trim).filter(|n| !n.is_empty() && settings.collection_folders);
|
||||||
@@ -772,6 +815,35 @@ mod tests {
|
|||||||
assert!(plan(&entry(Some(128), false, vec![720]), &save(SaveAs::Mp3, 320, 0), false).is_err());
|
assert!(plan(&entry(Some(128), false, vec![720]), &save(SaveAs::Mp3, 320, 0), false).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn keeps_an_audio_file_beside_a_video_and_pairs_them() {
|
||||||
|
let Some(ff) = engine::find_tool("ffmpeg") else { return };
|
||||||
|
let dir = std::env::temp_dir().join(format!("atmo-video-{}", std::process::id()));
|
||||||
|
let _ = std::fs::remove_dir_all(&dir);
|
||||||
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
|
let video = dir.join("Westwood - Eyes.mp4");
|
||||||
|
let made = engine::command(&ff)
|
||||||
|
.args(["-hide_banner", "-loglevel", "error", "-y", "-f", "lavfi", "-i", "testsrc=size=160x90:rate=10", "-f", "lavfi", "-i", "sine=frequency=440", "-t", "2", "-c:v", "libx264", "-c:a", "aac", "-shortest"])
|
||||||
|
.arg(&video)
|
||||||
|
.status()
|
||||||
|
.await
|
||||||
|
.is_ok_and(|s| s.success());
|
||||||
|
if !made {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let audio = extract_audio(&ff, &video).await.unwrap();
|
||||||
|
assert_eq!(audio.extension().unwrap(), "m4a");
|
||||||
|
assert!(crate::library::is_playable(&audio));
|
||||||
|
assert!(!crate::library::is_playable(&video));
|
||||||
|
let t = crate::library::read_track(&audio, None).unwrap();
|
||||||
|
assert_eq!(t.video.as_deref(), Some(&*video.to_string_lossy()));
|
||||||
|
std::fs::remove_file(&audio).unwrap();
|
||||||
|
assert!(crate::library::is_playable(&video));
|
||||||
|
let v = crate::library::read_track(&video, None).unwrap();
|
||||||
|
assert_eq!(v.video.as_deref(), Some(&*video.to_string_lossy()));
|
||||||
|
let _ = std::fs::remove_dir_all(&dir);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sorts_downloads_into_albums_playlists_and_tracks() {
|
fn sorts_downloads_into_albums_playlists_and_tracks() {
|
||||||
let settings = Settings { output_dir: "M".into(), playlists_dir: "M/Playlists".into(), collection_folders: true, ..Default::default() };
|
let settings = Settings { output_dir: "M".into(), playlists_dir: "M/Playlists".into(), collection_folders: true, ..Default::default() };
|
||||||
|
|||||||
+11
-3
@@ -66,11 +66,11 @@ fn apply_changes(app: &AppHandle, paths: HashSet<PathBuf>) {
|
|||||||
touched |= state.library.remove_under(&p) > 0;
|
touched |= state.library.remove_under(&p) > 0;
|
||||||
} else if p.is_dir() {
|
} else if p.is_dir() {
|
||||||
for e in walkdir::WalkDir::new(&p).into_iter().flatten().filter(|e| e.file_type().is_file()) {
|
for e in walkdir::WalkDir::new(&p).into_iter().flatten().filter(|e| e.file_type().is_file()) {
|
||||||
if crate::library::is_audio(e.path()) && !state.library.knows(e.path()) {
|
if crate::library::is_playable(e.path()) && !state.library.knows(e.path()) {
|
||||||
touched |= state.library.add_file(e.path(), &pl).is_ok();
|
touched |= state.library.add_file(e.path(), &pl).is_ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if crate::library::is_audio(&p) && !state.library.knows(&p) {
|
} else if crate::library::is_playable(&p) && !state.library.knows(&p) {
|
||||||
touched |= state.library.add_file(&p, &pl).is_ok();
|
touched |= state.library.add_file(&p, &pl).is_ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,12 +432,16 @@ pub fn set_fullscreen(app: AppHandle, on: bool) -> CmdResult<bool> {
|
|||||||
fn mime(path: &Path) -> &'static str {
|
fn mime(path: &Path) -> &'static str {
|
||||||
match path.extension().and_then(|e| e.to_str()).unwrap_or_default().to_ascii_lowercase().as_str() {
|
match path.extension().and_then(|e| e.to_str()).unwrap_or_default().to_ascii_lowercase().as_str() {
|
||||||
"mp3" => "audio/mpeg",
|
"mp3" => "audio/mpeg",
|
||||||
"m4a" | "mp4" | "aac" => "audio/mp4",
|
"m4a" | "aac" => "audio/mp4",
|
||||||
"flac" => "audio/flac",
|
"flac" => "audio/flac",
|
||||||
"ogg" => "audio/ogg",
|
"ogg" => "audio/ogg",
|
||||||
"opus" => "audio/ogg; codecs=opus",
|
"opus" => "audio/ogg; codecs=opus",
|
||||||
"wav" => "audio/wav",
|
"wav" => "audio/wav",
|
||||||
"aiff" | "aif" => "audio/aiff",
|
"aiff" | "aif" => "audio/aiff",
|
||||||
|
"mp4" | "m4v" => "video/mp4",
|
||||||
|
"webm" => "video/webm",
|
||||||
|
"mkv" => "video/x-matroska",
|
||||||
|
"mov" => "video/quicktime",
|
||||||
"jpg" | "jpeg" => "image/jpeg",
|
"jpg" | "jpeg" => "image/jpeg",
|
||||||
"png" => "image/png",
|
"png" => "image/png",
|
||||||
_ => "application/octet-stream",
|
_ => "application/octet-stream",
|
||||||
@@ -498,6 +502,10 @@ pub fn serve(app: &AppHandle, request: &Request<Vec<u8>>) -> Response<Vec<u8>> {
|
|||||||
Some(t) => stream(Path::new(&t.path), range),
|
Some(t) => stream(Path::new(&t.path), range),
|
||||||
None => respond(404, "text/plain", b"unknown track".to_vec(), &[]),
|
None => respond(404, "text/plain", b"unknown track".to_vec(), &[]),
|
||||||
},
|
},
|
||||||
|
"v" => match state.library.track(id).and_then(|t| t.video) {
|
||||||
|
Some(v) => stream(Path::new(&v), range),
|
||||||
|
None => respond(404, "text/plain", b"no video".to_vec(), &[]),
|
||||||
|
},
|
||||||
"a" => match state.library.art_path(id) {
|
"a" => match state.library.art_path(id) {
|
||||||
Some(p) if p.extension().is_some_and(|e| e == "png") => match std::fs::read(&p) {
|
Some(p) if p.extension().is_some_and(|e| e == "png") => match std::fs::read(&p) {
|
||||||
Ok(data) => respond(200, "image/png", data, &[("Cache-Control", "max-age=86400".into())]),
|
Ok(data) => respond(200, "image/png", data, &[("Cache-Control", "max-age=86400".into())]),
|
||||||
|
|||||||
+36
-3
@@ -13,6 +13,7 @@ use std::sync::RwLock;
|
|||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
pub const AUDIO_EXT: [&str; 9] = ["mp3", "m4a", "flac", "ogg", "opus", "wav", "aac", "aiff", "aif"];
|
pub const AUDIO_EXT: [&str; 9] = ["mp3", "m4a", "flac", "ogg", "opus", "wav", "aac", "aiff", "aif"];
|
||||||
|
pub const VIDEO_EXT: [&str; 5] = ["mp4", "m4v", "mkv", "webm", "mov"];
|
||||||
const ORDER_FILE: &str = "playlist.m3u8";
|
const ORDER_FILE: &str = "playlist.m3u8";
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
@@ -41,6 +42,7 @@ pub struct Track {
|
|||||||
pub gain_db: Option<f32>,
|
pub gain_db: Option<f32>,
|
||||||
pub sample_rate: Option<u32>,
|
pub sample_rate: Option<u32>,
|
||||||
pub channels: Option<u8>,
|
pub channels: Option<u8>,
|
||||||
|
pub video: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize)]
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
@@ -187,6 +189,20 @@ pub fn is_audio(p: &Path) -> bool {
|
|||||||
p.extension().and_then(|e| e.to_str()).is_some_and(|e| AUDIO_EXT.contains(&e.to_ascii_lowercase().as_str()))
|
p.extension().and_then(|e| e.to_str()).is_some_and(|e| AUDIO_EXT.contains(&e.to_ascii_lowercase().as_str()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_video(p: &Path) -> bool {
|
||||||
|
p.extension().and_then(|e| e.to_str()).is_some_and(|e| VIDEO_EXT.contains(&e.to_ascii_lowercase().as_str()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sibling(p: &Path, exts: &[&str]) -> Option<PathBuf> {
|
||||||
|
let stem = p.file_stem()?;
|
||||||
|
let dir = p.parent()?;
|
||||||
|
exts.iter().map(|e| dir.join(stem).with_extension(e)).find(|c| c != p && c.is_file())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_playable(p: &Path) -> bool {
|
||||||
|
is_audio(p) || (is_video(p) && sibling(p, &AUDIO_EXT).is_none())
|
||||||
|
}
|
||||||
|
|
||||||
fn file_stamp(p: &Path) -> Option<(u64, u64)> {
|
fn file_stamp(p: &Path) -> Option<(u64, u64)> {
|
||||||
let m = std::fs::metadata(p).ok()?;
|
let m = std::fs::metadata(p).ok()?;
|
||||||
let mtime = m.modified().ok()?.duration_since(UNIX_EPOCH).ok()?.as_secs();
|
let mtime = m.modified().ok()?.duration_since(UNIX_EPOCH).ok()?.as_secs();
|
||||||
@@ -214,6 +230,22 @@ fn year_of(s: &str) -> Option<u32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_track(path: &Path, playlist: Option<String>) -> Result<Track> {
|
pub fn read_track(path: &Path, playlist: Option<String>) -> Result<Track> {
|
||||||
|
let mut t = match read_tags(path, playlist.clone()) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err(e) if is_video(path) => {
|
||||||
|
let (size, mtime) = file_stamp(path).ok_or(e)?;
|
||||||
|
let path_s = path.to_string_lossy().into_owned();
|
||||||
|
let stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("Untitled").to_string();
|
||||||
|
let (artist, title) = crate::media::split_artist_title(&stem).unwrap_or((String::new(), stem));
|
||||||
|
Track { id: hash(&path_s), title, artist, format: path.extension().and_then(|e| e.to_str()).unwrap_or_default().to_ascii_lowercase(), size, mtime, playlist, added: now(), path: path_s, ..Default::default() }
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
};
|
||||||
|
t.video = if is_video(path) { Some(t.path.clone()) } else { sibling(path, &VIDEO_EXT).map(|v| v.to_string_lossy().into_owned()) };
|
||||||
|
Ok(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_tags(path: &Path, playlist: Option<String>) -> Result<Track> {
|
||||||
let (size, mtime) = file_stamp(path).ok_or_else(|| anyhow!("unreadable"))?;
|
let (size, mtime) = file_stamp(path).ok_or_else(|| anyhow!("unreadable"))?;
|
||||||
let file = lofty::read_from_path(path)?;
|
let file = lofty::read_from_path(path)?;
|
||||||
let props = file.properties();
|
let props = file.properties();
|
||||||
@@ -254,6 +286,7 @@ pub fn read_track(path: &Path, playlist: Option<String>) -> Result<Track> {
|
|||||||
gain_db,
|
gain_db,
|
||||||
sample_rate: props.sample_rate(),
|
sample_rate: props.sample_rate(),
|
||||||
channels: props.channels(),
|
channels: props.channels(),
|
||||||
|
video: None,
|
||||||
path: path_s,
|
path: path_s,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -311,7 +344,7 @@ impl Library {
|
|||||||
|
|
||||||
pub fn open_paths(&self, paths: &[PathBuf]) -> Vec<Track> {
|
pub fn open_paths(&self, paths: &[PathBuf]) -> Vec<Track> {
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
for p in paths.iter().filter(|p| p.is_file() && is_audio(p)) {
|
for p in paths.iter().filter(|p| p.is_file() && is_playable(p)) {
|
||||||
let key = p.to_string_lossy();
|
let key = p.to_string_lossy();
|
||||||
if let Some(t) = self.tracks.read().unwrap().values().find(|t| t.path == key).cloned() {
|
if let Some(t) = self.tracks.read().unwrap().values().find(|t| t.path == key).cloned() {
|
||||||
out.push(t);
|
out.push(t);
|
||||||
@@ -348,7 +381,7 @@ impl Library {
|
|||||||
for root in all_roots.iter().filter(|r| r.is_dir()) {
|
for root in all_roots.iter().filter(|r| r.is_dir()) {
|
||||||
for entry in walkdir::WalkDir::new(root).follow_links(false).into_iter().filter_entry(|e| !e.file_name().to_string_lossy().starts_with('.')).flatten() {
|
for entry in walkdir::WalkDir::new(root).follow_links(false).into_iter().filter_entry(|e| !e.file_name().to_string_lossy().starts_with('.')).flatten() {
|
||||||
let p = entry.path();
|
let p = entry.path();
|
||||||
if entry.file_type().is_file() && is_audio(p) && seen.insert(p.to_path_buf()) {
|
if entry.file_type().is_file() && is_playable(p) && seen.insert(p.to_path_buf()) {
|
||||||
files.push(p.to_path_buf());
|
files.push(p.to_path_buf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,7 +629,7 @@ impl Library {
|
|||||||
let mut found = Vec::new();
|
let mut found = Vec::new();
|
||||||
for e in walkdir::WalkDir::new(folder).follow_links(false).into_iter().filter_entry(|e| !e.file_name().to_string_lossy().starts_with('.')).flatten() {
|
for e in walkdir::WalkDir::new(folder).follow_links(false).into_iter().filter_entry(|e| !e.file_name().to_string_lossy().starts_with('.')).flatten() {
|
||||||
let p = e.path();
|
let p = e.path();
|
||||||
if e.file_type().is_file() && is_audio(p) && !hidden.contains(&*p.to_string_lossy()) {
|
if e.file_type().is_file() && is_playable(p) && !hidden.contains(&*p.to_string_lossy()) {
|
||||||
if let Ok(t) = read_track(p, self.playlist_for(p, playlists_dir)) {
|
if let Ok(t) = read_track(p, self.playlist_for(p, playlists_dir)) {
|
||||||
found.push(t);
|
found.push(t);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -48,6 +48,7 @@ pub struct Settings {
|
|||||||
pub mp3_bitrate: u32,
|
pub mp3_bitrate: u32,
|
||||||
pub video_height: u32,
|
pub video_height: u32,
|
||||||
pub video_container: String,
|
pub video_container: String,
|
||||||
|
pub video_keep_audio: bool,
|
||||||
pub concurrency: u8,
|
pub concurrency: u8,
|
||||||
pub filename_template: String,
|
pub filename_template: String,
|
||||||
pub embed_metadata: bool,
|
pub embed_metadata: bool,
|
||||||
@@ -95,6 +96,7 @@ impl Default for Settings {
|
|||||||
mp3_bitrate: 320,
|
mp3_bitrate: 320,
|
||||||
video_height: 1080,
|
video_height: 1080,
|
||||||
video_container: "mp4".into(),
|
video_container: "mp4".into(),
|
||||||
|
video_keep_audio: true,
|
||||||
concurrency: 3,
|
concurrency: 3,
|
||||||
filename_template: "{artist} - {title}".into(),
|
filename_template: "{artist} - {title}".into(),
|
||||||
embed_metadata: true,
|
embed_metadata: true,
|
||||||
@@ -140,6 +142,7 @@ pub struct SettingsPatch {
|
|||||||
pub mp3_bitrate: Option<u32>,
|
pub mp3_bitrate: Option<u32>,
|
||||||
pub video_height: Option<u32>,
|
pub video_height: Option<u32>,
|
||||||
pub video_container: Option<String>,
|
pub video_container: Option<String>,
|
||||||
|
pub video_keep_audio: Option<bool>,
|
||||||
pub concurrency: Option<u8>,
|
pub concurrency: Option<u8>,
|
||||||
pub filename_template: Option<String>,
|
pub filename_template: Option<String>,
|
||||||
pub embed_metadata: Option<bool>,
|
pub embed_metadata: Option<bool>,
|
||||||
@@ -207,7 +210,7 @@ impl Settings {
|
|||||||
($($f:ident),*) => { $( if let Some(v) = p.$f { self.$f = v; } )* };
|
($($f:ident),*) => { $( if let Some(v) = p.$f { self.$f = v; } )* };
|
||||||
}
|
}
|
||||||
set!(save_as, embed_metadata, collection_folders, number_tracks, skip_downloaded, sponsorblock, embed_subtitles, embed_chapters, watch_clipboard);
|
set!(save_as, embed_metadata, collection_folders, number_tracks, skip_downloaded, sponsorblock, embed_subtitles, embed_chapters, watch_clipboard);
|
||||||
set!(api_enabled, api_read, api_control, api_links, check_updates, artist_info);
|
set!(api_enabled, api_read, api_control, api_links, check_updates, artist_info, video_keep_audio);
|
||||||
if let Some(p) = p.api_port.filter(|p| *p >= 1024) {
|
if let Some(p) = p.api_port.filter(|p| *p >= 1024) {
|
||||||
self.api_port = p;
|
self.api_port = p;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1116,7 +1116,9 @@ function renderSaveMenu() {
|
|||||||
const heights = caps.heights.length ? caps.heights.filter((x) => x >= 360) : [2160, 1440, 1080, 720, 480];
|
const heights = caps.heights.length ? caps.heights.filter((x) => x >= 360) : [2160, 1440, 1080, 720, 480];
|
||||||
const vid = h("div", {},
|
const vid = h("div", {},
|
||||||
h("div", { class: "chips" }, h("button", { class: "chip", "aria-pressed": String(s.videoHeight === 0), onclick: () => patchSave({ videoHeight: 0 }) }, "Best"), ...heights.map((x) => h("button", { class: "chip", "aria-pressed": String(s.videoHeight === x), onclick: () => patchSave({ videoHeight: x }) }, `${x}p`))),
|
h("div", { class: "chips" }, h("button", { class: "chip", "aria-pressed": String(s.videoHeight === 0), onclick: () => patchSave({ videoHeight: 0 }) }, "Best"), ...heights.map((x) => h("button", { class: "chip", "aria-pressed": String(s.videoHeight === x), onclick: () => patchSave({ videoHeight: x }) }, `${x}p`))),
|
||||||
h("div", { class: "chips" }, ...["mp4", "mkv"].map((k) => h("button", { class: "chip", "aria-pressed": String(s.videoContainer === k), onclick: () => patchSave({ videoContainer: k }) }, k.toUpperCase())))
|
h("div", { class: "chips" }, ...["mp4", "mkv"].map((k) => h("button", { class: "chip", "aria-pressed": String(s.videoContainer === k), onclick: () => patchSave({ videoContainer: k }) }, k.toUpperCase()))),
|
||||||
|
h("label", { class: "keep-audio" }, h("input", { type: "checkbox", class: "switch", checked: s.videoKeepAudio !== false, onchange: (e) => patchSave({ videoKeepAudio: e.target.checked }) }),
|
||||||
|
h("span", {}, h("strong", {}, "Also keep an audio file"), h("small", {}, "Recommended. Play it as a song, and switch to the video at the same moment any time.")))
|
||||||
);
|
);
|
||||||
const lossless = h("div", { class: "chips" }, ...["flac", "wav"].map((k) => h("button", { class: "chip", "aria-pressed": String(s.saveAs === k), onclick: () => patchSave({ saveAs: k }) }, k.toUpperCase())));
|
const lossless = h("div", { class: "chips" }, ...["flac", "wav"].map((k) => h("button", { class: "chip", "aria-pressed": String(s.saveAs === k), onclick: () => patchSave({ saveAs: k }) }, k.toUpperCase())));
|
||||||
const noFf = !state.tools?.ffmpeg.path;
|
const noFf = !state.tools?.ffmpeg.path;
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -342,6 +342,7 @@
|
|||||||
<button class="icon-btn" id="lyricsBtn" aria-label="Lyrics" aria-pressed="false" title="Lyrics (L)"><span class="i" data-icon="microphone"></span></button>
|
<button class="icon-btn" id="lyricsBtn" aria-label="Lyrics" aria-pressed="false" title="Lyrics (L)"><span class="i" data-icon="microphone"></span></button>
|
||||||
<button class="icon-btn" id="queueBtn" aria-label="Queue" aria-pressed="false" title="Queue (Q)"><span class="i" data-icon="list"></span></button>
|
<button class="icon-btn" id="queueBtn" aria-label="Queue" aria-pressed="false" title="Queue (Q)"><span class="i" data-icon="list"></span></button>
|
||||||
<button class="icon-btn" id="sleepBtn" aria-label="Sleep timer" aria-pressed="false" title="Sleep timer" aria-haspopup="menu"><span class="i" data-icon="moon"></span></button>
|
<button class="icon-btn" id="sleepBtn" aria-label="Sleep timer" aria-pressed="false" title="Sleep timer" aria-haspopup="menu"><span class="i" data-icon="moon"></span></button>
|
||||||
|
<button class="icon-btn" id="videoBtn" aria-label="Show the music video" aria-pressed="false" title="Music video (V)" hidden><span class="i" data-icon="video"></span></button>
|
||||||
<button class="icon-btn" id="miniBtn" aria-label="Mini player" title="Mini player (P)"><span class="i" data-icon="picture-in-picture"></span></button>
|
<button class="icon-btn" id="miniBtn" aria-label="Mini player" title="Mini player (P)"><span class="i" data-icon="picture-in-picture"></span></button>
|
||||||
<button class="icon-btn" id="tvBtn" aria-label="TV mode" title="TV mode (F)"><span class="i" data-icon="device-tv"></span></button>
|
<button class="icon-btn" id="tvBtn" aria-label="TV mode" title="TV mode (F)"><span class="i" data-icon="device-tv"></span></button>
|
||||||
<button class="icon-btn" id="muteBtn" aria-label="Mute"></button>
|
<button class="icon-btn" id="muteBtn" aria-label="Mute"></button>
|
||||||
|
|||||||
+1
-1
@@ -202,7 +202,7 @@ function trackRow(t, i, ctx) {
|
|||||||
h("span", { class: "lt-num" }, playing ? eqBars() : label,
|
h("span", { class: "lt-num" }, playing ? eqBars() : label,
|
||||||
h("button", { class: "lt-play", "aria-label": `Play ${t.title}`, onclick: (e) => { e.stopPropagation(); playList(ctx.list, i); } }, icon("player-play-filled"))),
|
h("button", { class: "lt-play", "aria-label": `Play ${t.title}`, onclick: (e) => { e.stopPropagation(); playList(ctx.list, i); } }, icon("player-play-filled"))),
|
||||||
ctx.cover ? cover(t.art, "lt-cover") : null,
|
ctx.cover ? cover(t.art, "lt-cover") : null,
|
||||||
h("div", { class: "lt-main" }, h("span", { class: "lt-title" }, t.title), ctx.hideArtist && !ctx.showArtistFor?.(t) ? null : h("span", { class: "lt-sub" }, artistLinks(t))),
|
h("div", { class: "lt-main" }, h("span", { class: "lt-title" }, t.title, t.video ? h("span", { class: "badge-video", title: "Has a music video" }, icon("video")) : null), ctx.hideArtist && !ctx.showArtistFor?.(t) ? null : h("span", { class: "lt-sub" }, artistLinks(t))),
|
||||||
ctx.hideAlbum ? h("span") : h("span", { class: "lt-album" }, t.album ? h("button", { class: "link", onclick: (e) => { e.stopPropagation(); openLib("album", `${lnorm(t.albumArtist || primaryArtist(t.artist))}|${lnorm(t.album)}`); } }, t.album) : ""),
|
ctx.hideAlbum ? h("span") : h("span", { class: "lt-album" }, t.album ? h("button", { class: "link", onclick: (e) => { e.stopPropagation(); openLib("album", `${lnorm(t.albumArtist || primaryArtist(t.artist))}|${lnorm(t.album)}`); } }, t.album) : ""),
|
||||||
likeBtn(t),
|
likeBtn(t),
|
||||||
h("span", { class: "lt-dur" }, fmtDur(t.durationMs)),
|
h("span", { class: "lt-dur" }, fmtDur(t.durationMs)),
|
||||||
|
|||||||
+33
-1
@@ -206,9 +206,14 @@ function renderTv() {
|
|||||||
tv.classList.toggle("no-lyrics", !showCol);
|
tv.classList.toggle("no-lyrics", !showCol);
|
||||||
const note = !t ? null : Lyr.loading ? null : l?.instrumental ? "Instrumental" : !hasLyrics ? (Lyr.error ? "Lyrics sources unreachable" : "No lyrics found for this song") : `Lyrics · ${l.provider}`;
|
const note = !t ? null : Lyr.loading ? null : l?.instrumental ? "Instrumental" : !hasLyrics ? (Lyr.error ? "Lyrics sources unreachable" : "No lyrics found for this song") : `Lyrics · ${l.provider}`;
|
||||||
const bg = t?.art ? `background-image:url("${artUrl(t.art)}")` : "";
|
const bg = t?.art ? `background-image:url("${artUrl(t.art)}")` : "";
|
||||||
|
const withVideo = !!(t?.video && Player.showVideo);
|
||||||
|
tv.classList.toggle("video", withVideo);
|
||||||
|
const layer = withVideo ? h("video", { class: "tv-video", id: "tvVideo", src: mediaUrl("v", t.id), playsinline: true, preload: "auto" }) : h("div", { class: "tv-bg", style: bg });
|
||||||
|
if (withVideo) layer.muted = true;
|
||||||
tv.replaceChildren(
|
tv.replaceChildren(
|
||||||
h("div", { class: "tv-bg", style: bg }),
|
layer,
|
||||||
h("button", { class: "icon-btn tv-close", "aria-label": "Exit TV mode", onclick: closeTv }, icon("minimize")),
|
h("button", { class: "icon-btn tv-close", "aria-label": "Exit TV mode", onclick: closeTv }, icon("minimize")),
|
||||||
|
t?.video ? h("button", { class: `btn small tv-video-btn ${withVideo ? "on" : ""}`, onclick: () => { Player.showVideo = !Player.showVideo; renderTv(); updatePlayerBar(); } }, icon(withVideo ? "photo" : "video"), withVideo ? "Show cover" : "Show video") : null,
|
||||||
h("div", { class: "tv-stage" },
|
h("div", { class: "tv-stage" },
|
||||||
h("div", { class: "tv-now" },
|
h("div", { class: "tv-now" },
|
||||||
t ? cover(t.art, "tv-cover", t.album || t.title) : h("div", { class: "tv-cover ph" }, icon("music")),
|
t ? cover(t.art, "tv-cover", t.album || t.title) : h("div", { class: "tv-cover ph" }, icon("music")),
|
||||||
@@ -225,6 +230,33 @@ function renderTv() {
|
|||||||
);
|
);
|
||||||
Lyr.active = -1;
|
Lyr.active = -1;
|
||||||
startTick();
|
startTick();
|
||||||
|
if (withVideo) {
|
||||||
|
layer.addEventListener("loadedmetadata", syncVideo, { once: true });
|
||||||
|
syncVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncVideo() {
|
||||||
|
const v = $("#tvVideo");
|
||||||
|
if (!v) return;
|
||||||
|
const a = Player.audio;
|
||||||
|
v.playbackRate = a.playbackRate || 1;
|
||||||
|
if (v.readyState >= 1 && Math.abs(v.currentTime - a.currentTime) > 0.25) v.currentTime = Math.min(a.currentTime, Math.max(0, (v.duration || a.currentTime) - 0.05));
|
||||||
|
if (a.paused && !v.paused) v.pause();
|
||||||
|
else if (!a.paused && v.paused) v.play().catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleVideo() {
|
||||||
|
if (!Player.current?.video) return;
|
||||||
|
if (Lyr.tv && Player.showVideo) {
|
||||||
|
Player.showVideo = false;
|
||||||
|
renderTv();
|
||||||
|
} else {
|
||||||
|
Player.showVideo = true;
|
||||||
|
if (Lyr.tv) renderTv();
|
||||||
|
else openTv();
|
||||||
|
}
|
||||||
|
updatePlayerBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawViz() {
|
function drawViz() {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ function rangeFill(el) {
|
|||||||
function updatePlayerBar() {
|
function updatePlayerBar() {
|
||||||
const t = Player.current;
|
const t = Player.current;
|
||||||
$("#player").classList.toggle("idle", !t);
|
$("#player").classList.toggle("idle", !t);
|
||||||
|
$("#videoBtn").hidden = !t?.video;
|
||||||
|
$("#videoBtn").setAttribute("aria-pressed", String(!!(t?.video && Player.showVideo && Lyr.tv)));
|
||||||
$("#npArt").replaceChildren(t ? cover(t.art, "np-cover", t.album || t.title) : h("div", { class: "np-cover ph" }, icon("music")));
|
$("#npArt").replaceChildren(t ? cover(t.art, "np-cover", t.album || t.title) : h("div", { class: "np-cover ph" }, icon("music")));
|
||||||
$("#npTitle").textContent = t ? t.title : "Nothing playing";
|
$("#npTitle").textContent = t ? t.title : "Nothing playing";
|
||||||
$("#npArtist").replaceChildren(t ? artistLinks(t) : h("span", { class: "muted" }, "Pick something from your library"));
|
$("#npArtist").replaceChildren(t ? artistLinks(t) : h("span", { class: "muted" }, "Pick something from your library"));
|
||||||
@@ -301,9 +303,11 @@ function bindPlayer() {
|
|||||||
$("#queueBtn").addEventListener("click", () => toggleDrawer("#queuePanel", "#queueBtn", renderQueue));
|
$("#queueBtn").addEventListener("click", () => toggleDrawer("#queuePanel", "#queueBtn", renderQueue));
|
||||||
$("#lyricsBtn").addEventListener("click", () => toggleDrawer("#lyricsPanel", "#lyricsBtn", renderLyricsPanel));
|
$("#lyricsBtn").addEventListener("click", () => toggleDrawer("#lyricsPanel", "#lyricsBtn", renderLyricsPanel));
|
||||||
$("#tvBtn").addEventListener("click", (e) => chooseTvScreen(e.currentTarget));
|
$("#tvBtn").addEventListener("click", (e) => chooseTvScreen(e.currentTarget));
|
||||||
|
$("#videoBtn").addEventListener("click", toggleVideo);
|
||||||
document.addEventListener("click", (e) => { if (e.target.isConnected && !$("#fxPanel").hidden && !e.target.closest("#fxPanel, #fxBtn, .modal-wrap")) closeFx(); });
|
document.addEventListener("click", (e) => { if (e.target.isConnected && !$("#fxPanel").hidden && !e.target.closest("#fxPanel, #fxBtn, .modal-wrap")) closeFx(); });
|
||||||
window.addEventListener("player", (e) => {
|
window.addEventListener("player", (e) => {
|
||||||
const type = e.detail.type;
|
const type = e.detail.type;
|
||||||
|
if (Lyr.tv && type !== "volume" && type !== "fx") syncVideo();
|
||||||
if (type === "time") return updateTime();
|
if (type === "time") return updateTime();
|
||||||
if (type === "volume") return updateVolume();
|
if (type === "volume") return updateVolume();
|
||||||
if (type === "fx") return $("#fxBtn").setAttribute("aria-pressed", String(fxActive()));
|
if (type === "fx") return $("#fxBtn").setAttribute("aria-pressed", String(fxActive()));
|
||||||
@@ -325,6 +329,7 @@ function bindPlayer() {
|
|||||||
else if (k.toLowerCase() === "l" && !mod) $("#lyricsBtn").click();
|
else if (k.toLowerCase() === "l" && !mod) $("#lyricsBtn").click();
|
||||||
else if (k.toLowerCase() === "q" && !mod) $("#queueBtn").click();
|
else if (k.toLowerCase() === "q" && !mod) $("#queueBtn").click();
|
||||||
else if (k.toLowerCase() === "f" && !mod) openTv();
|
else if (k.toLowerCase() === "f" && !mod) openTv();
|
||||||
|
else if (k.toLowerCase() === "v" && !mod && Player.current?.video) toggleVideo();
|
||||||
});
|
});
|
||||||
updatePlayerBar();
|
updatePlayerBar();
|
||||||
updateTime();
|
updateTime();
|
||||||
|
|||||||
@@ -1170,3 +1170,16 @@ body.mini-mode > *:not(#mini):not(.toasts):not(.modal-wrap):not(script) { displa
|
|||||||
.move-paths { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: var(--s2); align-items: center; }
|
.move-paths { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: var(--s2); align-items: center; }
|
||||||
.move-paths code { font-size: 12px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2, var(--surface)); border: 1px solid var(--hairline); overflow-wrap: anywhere; }
|
.move-paths code { font-size: 12px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2, var(--surface)); border: 1px solid var(--hairline); overflow-wrap: anywhere; }
|
||||||
.move-paths .i { color: var(--text-3); }
|
.move-paths .i { color: var(--text-3); }
|
||||||
|
|
||||||
|
/* music videos */
|
||||||
|
.tv-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; z-index: 0; }
|
||||||
|
.tv.video .tv-stage { background: linear-gradient(90deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.15) 45%, rgba(0, 0, 0, 0)); }
|
||||||
|
.tv.video .tv-now .tv-cover { display: none; }
|
||||||
|
.tv-video-btn { position: absolute; top: 18px; right: 64px; z-index: 3; background: rgba(10, 12, 18, 0.55); color: #fff; border-color: rgba(255, 255, 255, 0.18); }
|
||||||
|
.tv-video-btn.on { background: rgba(255, 255, 255, 0.16); }
|
||||||
|
.badge-video { display: inline-grid; place-items: center; margin-left: 6px; vertical-align: -2px; color: var(--text-3); }
|
||||||
|
.badge-video .i svg { width: 14px; height: 14px; }
|
||||||
|
#videoBtn[aria-pressed="true"] { color: var(--accent); }
|
||||||
|
.keep-audio { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); align-items: start; margin-top: var(--s3); cursor: pointer; }
|
||||||
|
.keep-audio span { display: grid; gap: 2px; }
|
||||||
|
.keep-audio small { color: var(--text-3); font-size: 11.5px; line-height: 1.4; }
|
||||||
|
|||||||
Reference in New Issue
Block a user