From 3332923610dfb5f8b7699ee6d3fe71c7be1a666d Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 19 Nov 2026 01:37:56 -0500 Subject: [PATCH] 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 --- README.md | 1 + src/downloader.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++ src/libcmd.rs | 14 +++++++-- src/library.rs | 39 +++++++++++++++++++++++-- src/settings.rs | 5 +++- ui/app.js | 4 ++- ui/icons.js | 2 +- ui/index.html | 1 + ui/library.js | 2 +- ui/lyrics.js | 34 +++++++++++++++++++++- ui/nowplaying.js | 5 ++++ ui/styles.css | 13 +++++++++ 12 files changed, 181 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fd094e2..7cf4eb3 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ cargo tauri build | `L` | Lyrics | | `Q` | Queue | | `F` | TV mode | +| `V` | Show the music video, when a song has one | | `Ctrl K` | Search your library, or paste a link | | `Ctrl L` | Get: the link and online search bar | | `Ctrl B` | Collapse or expand the sidebar | diff --git a/src/downloader.rs b/src/downloader.rs index 6246a49..0a22b52 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -352,6 +352,26 @@ impl Job { 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; let note = (!notes.is_empty()).then(|| notes.join(" ")); 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 { + 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 = ["-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 { let base = PathBuf::from(&settings.output_dir); 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()); } + #[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] 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() }; diff --git a/src/libcmd.rs b/src/libcmd.rs index 1320060..b95b2f1 100644 --- a/src/libcmd.rs +++ b/src/libcmd.rs @@ -66,11 +66,11 @@ fn apply_changes(app: &AppHandle, paths: HashSet) { touched |= state.library.remove_under(&p) > 0; } else if p.is_dir() { 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(); } } - } 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(); } } @@ -432,12 +432,16 @@ pub fn set_fullscreen(app: AppHandle, on: bool) -> CmdResult { fn mime(path: &Path) -> &'static str { match path.extension().and_then(|e| e.to_str()).unwrap_or_default().to_ascii_lowercase().as_str() { "mp3" => "audio/mpeg", - "m4a" | "mp4" | "aac" => "audio/mp4", + "m4a" | "aac" => "audio/mp4", "flac" => "audio/flac", "ogg" => "audio/ogg", "opus" => "audio/ogg; codecs=opus", "wav" => "audio/wav", "aiff" | "aif" => "audio/aiff", + "mp4" | "m4v" => "video/mp4", + "webm" => "video/webm", + "mkv" => "video/x-matroska", + "mov" => "video/quicktime", "jpg" | "jpeg" => "image/jpeg", "png" => "image/png", _ => "application/octet-stream", @@ -498,6 +502,10 @@ pub fn serve(app: &AppHandle, request: &Request>) -> Response> { Some(t) => stream(Path::new(&t.path), range), 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) { 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())]), diff --git a/src/library.rs b/src/library.rs index feabbae..b231ef7 100644 --- a/src/library.rs +++ b/src/library.rs @@ -13,6 +13,7 @@ use std::sync::RwLock; use std::time::{SystemTime, UNIX_EPOCH}; 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"; #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -41,6 +42,7 @@ pub struct Track { pub gain_db: Option, pub sample_rate: Option, pub channels: Option, + pub video: Option, } #[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())) } +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 { + 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)> { let m = std::fs::metadata(p).ok()?; let mtime = m.modified().ok()?.duration_since(UNIX_EPOCH).ok()?.as_secs(); @@ -214,6 +230,22 @@ fn year_of(s: &str) -> Option { } pub fn read_track(path: &Path, playlist: Option) -> Result { + 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) -> Result { let (size, mtime) = file_stamp(path).ok_or_else(|| anyhow!("unreadable"))?; let file = lofty::read_from_path(path)?; let props = file.properties(); @@ -254,6 +286,7 @@ pub fn read_track(path: &Path, playlist: Option) -> Result { gain_db, sample_rate: props.sample_rate(), channels: props.channels(), + video: None, path: path_s, }) } @@ -311,7 +344,7 @@ impl Library { pub fn open_paths(&self, paths: &[PathBuf]) -> Vec { 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(); if let Some(t) = self.tracks.read().unwrap().values().find(|t| t.path == key).cloned() { out.push(t); @@ -348,7 +381,7 @@ impl Library { 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() { 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()); } } @@ -596,7 +629,7 @@ impl Library { 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() { 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)) { found.push(t); } diff --git a/src/settings.rs b/src/settings.rs index d18fa01..89825a6 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -48,6 +48,7 @@ pub struct Settings { pub mp3_bitrate: u32, pub video_height: u32, pub video_container: String, + pub video_keep_audio: bool, pub concurrency: u8, pub filename_template: String, pub embed_metadata: bool, @@ -95,6 +96,7 @@ impl Default for Settings { mp3_bitrate: 320, video_height: 1080, video_container: "mp4".into(), + video_keep_audio: true, concurrency: 3, filename_template: "{artist} - {title}".into(), embed_metadata: true, @@ -140,6 +142,7 @@ pub struct SettingsPatch { pub mp3_bitrate: Option, pub video_height: Option, pub video_container: Option, + pub video_keep_audio: Option, pub concurrency: Option, pub filename_template: Option, pub embed_metadata: Option, @@ -207,7 +210,7 @@ impl Settings { ($($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!(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) { self.api_port = p; } diff --git a/ui/app.js b/ui/app.js index 2d94453..a884295 100644 --- a/ui/app.js +++ b/ui/app.js @@ -1116,7 +1116,9 @@ function renderSaveMenu() { const heights = caps.heights.length ? caps.heights.filter((x) => x >= 360) : [2160, 1440, 1080, 720, 480]; 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" }, ...["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 noFf = !state.tools?.ffmpeg.path; diff --git a/ui/icons.js b/ui/icons.js index 1e2e376..b7888d7 100644 --- a/ui/icons.js +++ b/ui/icons.js @@ -1,2 +1,2 @@ /* atmosphere · icons.js · Tabler icon set (MIT, via Iconify) bundled as inline SVG markup for the UI. */ -window.ICONS = {"moon":"","home":"","layout-sidebar-left-expand":"","layout-sidebar-left-collapse":"","picture-in-picture":"","arrows-maximize":"","pinned":"","pin":"","droplet":"","grip-vertical":"","adjustments-horizontal":"","alert-circle":"","arrow-down-circle":"","arrow-left":"","arrow-right":"","arrows-shuffle":"","arrows-sort":"","brand-bandcamp":"","brand-instagram":"","brand-soundcloud":"","brand-tiktok":"","brand-twitch":"","brand-vimeo":"","brand-x":"","brand-youtube":"","calendar":"","chart-bar":"","check":"","chevron-down":"","chevron-left":"","chevron-right":"","circle-check":"","clipboard":"","clock":"","cloud-download":"","copy":"","device-tv":"","disc-filled":"","disc":"","dots":"","download":"","external-link":"","file-music":"","flame":"","folder-open":"","folder-plus":"","folder":"","headphones":"","heart-filled":"","heart":"","info-circle":"","layout-grid":"","link":"","list-details":"","list":"","loader-2":"","maximize":"","microphone-2":"","microphone":"","minimize":"","music":"","pencil":"","photo-down":"","photo":"","player-pause-filled":"","player-play-filled":"","player-play":"","player-skip-back-filled":"","player-skip-forward-filled":"","playlist-add":"","playlist":"","plus":"","refresh":"","repeat-once":"","repeat":"","scissors":"","search":"","settings":"","share":"","sparkles":"","trash":"","user-circle":"","user":"","volume-off":"","volume":"","wave-sine":"","world":"","x":""}; +window.ICONS = {"video":"","moon":"","home":"","layout-sidebar-left-expand":"","layout-sidebar-left-collapse":"","picture-in-picture":"","arrows-maximize":"","pinned":"","pin":"","droplet":"","grip-vertical":"","adjustments-horizontal":"","alert-circle":"","arrow-down-circle":"","arrow-left":"","arrow-right":"","arrows-shuffle":"","arrows-sort":"","brand-bandcamp":"","brand-instagram":"","brand-soundcloud":"","brand-tiktok":"","brand-twitch":"","brand-vimeo":"","brand-x":"","brand-youtube":"","calendar":"","chart-bar":"","check":"","chevron-down":"","chevron-left":"","chevron-right":"","circle-check":"","clipboard":"","clock":"","cloud-download":"","copy":"","device-tv":"","disc-filled":"","disc":"","dots":"","download":"","external-link":"","file-music":"","flame":"","folder-open":"","folder-plus":"","folder":"","headphones":"","heart-filled":"","heart":"","info-circle":"","layout-grid":"","link":"","list-details":"","list":"","loader-2":"","maximize":"","microphone-2":"","microphone":"","minimize":"","music":"","pencil":"","photo-down":"","photo":"","player-pause-filled":"","player-play-filled":"","player-play":"","player-skip-back-filled":"","player-skip-forward-filled":"","playlist-add":"","playlist":"","plus":"","refresh":"","repeat-once":"","repeat":"","scissors":"","search":"","settings":"","share":"","sparkles":"","trash":"","user-circle":"","user":"","volume-off":"","volume":"","wave-sine":"","world":"","x":""}; diff --git a/ui/index.html b/ui/index.html index 0e0b86f..93c9634 100644 --- a/ui/index.html +++ b/ui/index.html @@ -342,6 +342,7 @@ + diff --git a/ui/library.js b/ui/library.js index e9158e4..a73871c 100644 --- a/ui/library.js +++ b/ui/library.js @@ -202,7 +202,7 @@ function trackRow(t, i, ctx) { 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"))), 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) : ""), likeBtn(t), h("span", { class: "lt-dur" }, fmtDur(t.durationMs)), diff --git a/ui/lyrics.js b/ui/lyrics.js index 8dc488e..573bc9b 100644 --- a/ui/lyrics.js +++ b/ui/lyrics.js @@ -206,9 +206,14 @@ function renderTv() { 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 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( - h("div", { class: "tv-bg", style: bg }), + layer, 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-now" }, 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; 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() { diff --git a/ui/nowplaying.js b/ui/nowplaying.js index 5925531..26b4aa0 100644 --- a/ui/nowplaying.js +++ b/ui/nowplaying.js @@ -11,6 +11,8 @@ function rangeFill(el) { function updatePlayerBar() { const t = Player.current; $("#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"))); $("#npTitle").textContent = t ? t.title : "Nothing playing"; $("#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)); $("#lyricsBtn").addEventListener("click", () => toggleDrawer("#lyricsPanel", "#lyricsBtn", renderLyricsPanel)); $("#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(); }); window.addEventListener("player", (e) => { const type = e.detail.type; + if (Lyr.tv && type !== "volume" && type !== "fx") syncVideo(); if (type === "time") return updateTime(); if (type === "volume") return updateVolume(); 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() === "q" && !mod) $("#queueBtn").click(); else if (k.toLowerCase() === "f" && !mod) openTv(); + else if (k.toLowerCase() === "v" && !mod && Player.current?.video) toggleVideo(); }); updatePlayerBar(); updateTime(); diff --git a/ui/styles.css b/ui/styles.css index e04e7aa..1040ab0 100644 --- a/ui/styles.css +++ b/ui/styles.css @@ -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 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); } + +/* 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; }