Repository navigation
feat(player): crossfade, gapless playback and AutoMix #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2dbc557
c166f04
fe46a7d
aacd4cb
114519b
ed1df2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,42 +23,59 @@ in front of it. | |
| | `lyrics` | `trackId` | Lyrics and the providers that had them | 100 | | ||
| | `artists` | `id` | Cached artist pages | 100 | | ||
|
|
||
| AutoMix keeps its song analyses (silence at either end, loudness, whether a song fades | ||
| out) in a separate small IndexedDB, `liner_analysis_v1`, so clearing cached audio | ||
| doesn't throw them away. Songs are only analysed from audio already on the device. | ||
|
|
||
| The audio cache is limited to 3 GB by default (`liner_audio_cache_limit_bytes`, minimum | ||
| 250 MB, changed in Settings → Cache & Storage). Over the limit, the least recently | ||
| played tracks are evicted (`src/shared/storage/audioCache.ts`). | ||
|
|
||
| ## Files managed by the main process | ||
|
|
||
| | Path | Holds | Code | | ||
| | ---------------------------------- | ---------------------------------------------- | ---------------------------------- | | ||
| | `auth/session.json` | Liner session, encrypted with `safeStorage` | `electron/auth-session-store.ts` | | ||
| | `auth/youtube-session.json` | YouTube account tokens, encrypted the same way | `electron/auth-session-ipc.ts` | | ||
| | `local-tracks/library.json` | Index of imported audio files | `electron/local-tracks/library.ts` | | ||
| | `local-tracks/audio/<hash>.<ext>` | Copies of imported audio files | same | | ||
| | `local-tracks/covers/<hash>.<ext>` | Artwork taken from their tags | same | | ||
| | Path | Holds | Code | | ||
| | ------------------------------------------------- | ------------------------------------------------ | ---------------------------------- | | ||
| | `auth/session.json` | Liner session, encrypted with `safeStorage` | `electron/auth-session-store.ts` | | ||
| | `auth/youtube-session.json` | YouTube account tokens, encrypted the same way | `electron/auth-session-ipc.ts` | | ||
| | `local-tracks/library.json` | Index of imported audio files | `electron/local-tracks/library.ts` | | ||
| | `local-tracks/audio/<hash>.<ext>` | Copies of imported audio files | same | | ||
| | `local-tracks/covers/<hash>.<ext>` | Artwork taken from their tags | same | | ||
| | `playlist-covers/index.json` | Index of custom playlist covers, per account | `electron/user-media/library.ts` | | ||
| | `playlist-covers/<key>.<ext>` | The cropped cover (or an animated GIF/WebP) | `electron/playlist-covers/ipc.ts` | | ||
| | `wallpapers/index.json`, `wallpapers/<key>.<ext>` | The wallpaper gallery (last 8 pictures or clips) | `electron/wallpapers/ipc.ts` | | ||
|
|
||
| Imported files are copies, so the originals can be moved or deleted. They are served to | ||
| the renderer through the `liner-local://audio/<hash>` and `liner-local://cover/<hash>` | ||
| protocol (`electron/local-tracks/protocol.ts`), never through IndexedDB. | ||
|
|
||
| Custom playlist covers are served as `liner-local://playlist-cover/<key>`. The key is | ||
| `sha1(userId + "\0" + playlistId)`, so only files in the index can be reached, and the | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the truncated cover key.
|
||
| file type comes from the bytes (`electron/user-media/sniff.ts`), not from the renderer. | ||
| They stay on this device until the API has a cover field. When it does, a cover the | ||
| server returns wins over the local one, and the adapter in | ||
| `src/features/covers/playlistCovers/playlistCoverStore.ts` can upload instead. The web | ||
| build keeps them in IndexedDB (`liner_playlist_covers_v1`). | ||
|
|
||
| ## localStorage | ||
|
|
||
| Settings and small state, as zustand `persist` stores or plain keys. | ||
|
|
||
| | Key | Holds | | ||
| | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | | ||
| | `liner_player_session_v2` | Repeat, shuffle, volume and player settings; the queue and position only when "resume" is the start mode | | ||
| | `liner_lyrics_session_v1` | Lyrics view settings | | ||
| | `liner_customization_v1` | Appearance settings | | ||
| | `liner_shortcuts_settings_v1` | Keyboard shortcuts | | ||
| | `liner_overlay_settings_v1` | Overlay settings | | ||
| | `liner_discord_settings_v1` | Discord Rich Presence settings | | ||
| | `liner_youtube_preferences` | YouTube playback and sync settings | | ||
| | `liner_youtube_page_id` | The brand channel picked for the YouTube account | | ||
| | `liner_search_history` | Recent searches | | ||
| | `liner_library_view_mode` | Grid or list in the library | | ||
| | `liner_locale`, `theme` | Language and theme | | ||
| | `liner_lyrics_*`, `liner:artist:*`, `liner:search:*`, `liner:query:*` | Small caches | | ||
| | Key | Holds | | ||
| | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | | ||
| | `liner_player_session_v2` | Repeat, shuffle, volume and player settings; the queue and position only when "resume" is the start mode | | ||
| | `liner_lyrics_session_v1` | Lyrics view settings | | ||
| | `liner_appearance_v2` | Colour theme, accent, wallpaper choice and its blur/dim/tint (`liner_customization_v1` is read once for old blur and dim) | | ||
| | `liner_shortcuts_settings_v1` | Keyboard shortcuts | | ||
| | `liner_overlay_settings_v1` | Overlay settings | | ||
| | `liner_discord_settings_v1` | Discord Rich Presence settings | | ||
| | `liner_youtube_preferences` | YouTube playback and sync settings | | ||
| | `liner_youtube_page_id` | The brand channel picked for the YouTube account | | ||
| | `liner_search_history` | Recent searches | | ||
| | `liner_recent_playlists_v1` | The five playlists songs were added to most recently | | ||
| | `liner_downloads_v1` | Songs, playlists and albums picked for download, per account (the files are in `saved-tracks/`) | | ||
| | `liner_library_view_mode` | Grid or list in the library | | ||
| | `liner_locale`, `theme` | Language and theme | | ||
| | `liner_lyrics_*`, `liner:artist:*`, `liner:search:*`, `liner:query:*` | Small caches | | ||
|
|
||
| `liner_auth_session` and `liner_youtube_tv_session` are legacy keys. They are moved | ||
| into the encrypted files above on first launch and then removed. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { Readable } from "node:stream"; | |
| import { protocol } from "electron"; | ||
| import type { LocalTrackLibrary } from "./library.js"; | ||
| import type { SavedTrackLibrary } from "../saved-tracks/library.js"; | ||
| import type { UserMediaLibrary } from "../user-media/library.js"; | ||
|
|
||
| export const LOCAL_TRACK_SCHEME = "liner-local"; | ||
|
|
||
|
|
@@ -13,8 +14,12 @@ const IMAGE_MIME: Record<string, string> = { | |
| ".png": "image/png", | ||
| ".webp": "image/webp", | ||
| ".gif": "image/gif", | ||
| ".avif": "image/avif", | ||
| }; | ||
|
|
||
| /** extra hosts served from user-media libraries (playlist covers, wallpapers) */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the added JSDoc comment. As per path instructions, “No comments of any kind in code (no //, /* */, JSDoc).” Remove this comment.
|
||
| export type UserMediaHosts = Partial<Record<string, UserMediaLibrary>>; | ||
|
|
||
| const BASE_HEADERS = { | ||
| "access-control-allow-origin": "*", | ||
| "accept-ranges": "bytes", | ||
|
|
@@ -88,6 +93,7 @@ async function locateFile( | |
| id: string, | ||
| library: LocalTrackLibrary, | ||
| saved: SavedTrackLibrary, | ||
| media: UserMediaHosts, | ||
| ): Promise<{ path: string; mimeType?: string } | null> { | ||
| if (host === "audio" || host === "cover") { | ||
| const located = await library.locate(host, id); | ||
|
|
@@ -99,17 +105,20 @@ async function locateFile( | |
| } | ||
| if (host === "saved-audio") return saved.locate("audio", id); | ||
| if (host === "saved-cover") return saved.locate("cover", id); | ||
| const userMedia = Object.hasOwn(media, host) ? media[host] : undefined; | ||
| if (userMedia) return userMedia.locate(id); | ||
| return null; | ||
| } | ||
|
|
||
| export function handleLocalTrackScheme( | ||
| library: LocalTrackLibrary, | ||
| saved: SavedTrackLibrary, | ||
| media: UserMediaHosts = {}, | ||
| ) { | ||
| protocol.handle(LOCAL_TRACK_SCHEME, async (request) => { | ||
| const url = new URL(request.url); | ||
| const id = url.pathname.replace(/^\/+/, ""); | ||
| const located = await locateFile(url.hostname, id, library, saved); | ||
| const located = await locateFile(url.hostname, id, library, saved, media); | ||
| if (!located) { | ||
| console.warn( | ||
| `[local-tracks] ${url.hostname} ${id} is not in the library`, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1326,6 +1326,8 @@ export class OverlayManager { | |
| this.focusMainWindow(); | ||
| return; | ||
| } | ||
| // the playlist picker is a dialog in the main window: bring it forward | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the new code comment. Keep the As per path instructions, “No comments of any kind in code (no //, /* */, JSDoc). Flag every one.”
|
||
| if (action.type === "addToPlaylist") this.focusMainWindow(); | ||
| if (this.mainWindow && !this.mainWindow.isDestroyed()) { | ||
| this.mainWindow.webContents.send("overlay:action", action); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import path from "node:path"; | ||
| import { app } from "electron"; | ||
| import { handleTrusted } from "../ipc-guard.js"; | ||
| import { | ||
| UserMediaLibrary, | ||
| UserMediaRejection, | ||
| type UserMediaRecord, | ||
| } from "../user-media/library.js"; | ||
| import type { MediaMime } from "../user-media/sniff.js"; | ||
| import type { PlaylistCoverSetResult, PlaylistCoverView } from "./types.js"; | ||
|
|
||
| /** the renderer crops + re-encodes, so 8 MB is plenty (animated GIFs stay as is) */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the prohibited limit comment. Remove this comment. Keep any required explanation of the upload limit in separate documentation. As per path instructions, “No comments of any kind in code.”
|
||
| export const MAX_PLAYLIST_COVER_BYTES = 8 * 1024 * 1024; | ||
|
|
||
| const ACCEPT = new Set<MediaMime>([ | ||
| "image/png", | ||
| "image/jpeg", | ||
| "image/webp", | ||
| "image/gif", | ||
| "image/avif", | ||
| ]); | ||
|
|
||
| const id = (value: unknown, max = 200): string | null => | ||
| typeof value === "string" && value.length > 0 && value.length <= max | ||
| ? value | ||
| : null; | ||
|
|
||
| function toView(record: UserMediaRecord): PlaylistCoverView { | ||
| return { | ||
| key: record.key, | ||
| playlistId: record.ref, | ||
| mimeType: record.mimeType, | ||
| byteSize: record.byteSize, | ||
| updatedAt: record.updatedAt, | ||
| }; | ||
| } | ||
|
|
||
| export function createPlaylistCoverLibrary() { | ||
| return new UserMediaLibrary( | ||
| path.join(app.getPath("userData"), "playlist-covers"), | ||
| { accept: ACCEPT, maxBytes: MAX_PLAYLIST_COVER_BYTES }, | ||
| ); | ||
| } | ||
|
|
||
| export function setupPlaylistCovers(library: UserMediaLibrary) { | ||
| handleTrusted( | ||
| "playlist-covers:set", | ||
| async (_event, input: unknown): Promise<PlaylistCoverSetResult> => { | ||
| const raw = (input ?? {}) as Record<string, unknown>; | ||
| const userId = id(raw.userId); | ||
| const playlistId = id(raw.playlistId); | ||
| if (!userId || !playlistId || !(raw.bytes instanceof Uint8Array)) { | ||
| return { ok: false, reason: "invalid" }; | ||
| } | ||
| try { | ||
| const record = await library.set(userId, playlistId, raw.bytes); | ||
| return { ok: true, cover: toView(record) }; | ||
| } catch (error) { | ||
| return { | ||
| ok: false, | ||
| reason: | ||
| error instanceof UserMediaRejection ? error.reason : "write-failed", | ||
| }; | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| handleTrusted("playlist-covers:remove", (_event, input: unknown) => { | ||
| const raw = (input ?? {}) as Record<string, unknown>; | ||
| const userId = id(raw.userId); | ||
| const playlistId = id(raw.playlistId); | ||
| if (!userId || !playlistId) return false; | ||
| return library.remove(userId, playlistId); | ||
| }); | ||
|
|
||
| handleTrusted("playlist-covers:list", async (_event, userId: unknown) => { | ||
| const owner = id(userId); | ||
| if (!owner) return []; | ||
| return (await library.list(owner)).map(toView); | ||
| }); | ||
|
|
||
| handleTrusted("playlist-covers:usage", () => library.usage()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export interface PlaylistCoverView { | ||
| /** 20-hex key; served as liner-local://playlist-cover/<key> */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the prohibited property comments. Remove both comments from As per path instructions, “No comments of any kind in code.” Also applies to: 7-7
|
||
| key: string; | ||
| playlistId: string; | ||
| mimeType: string; | ||
| byteSize: number; | ||
| /** epoch ms, appended to the url to bust caches */ | ||
| updatedAt: number; | ||
| } | ||
|
|
||
| export type PlaylistCoverSetResult = | ||
| | { ok: true; cover: PlaylistCoverView } | ||
| | { | ||
| ok: false; | ||
| reason: | ||
| "invalid" | "unsupported-type" | "too-large" | "empty" | "write-failed"; | ||
| }; | ||
|
|
||
| export interface PlaylistCoverSetInput { | ||
| userId: string; | ||
| playlistId: string; | ||
| bytes: Uint8Array; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qualify the analysis-retention claim for all-category clears.
Lines 26-28 state that clearing cached audio keeps the AutoMix analyses. That holds only for the Audio category. When all cache categories are selected, the guide's own table at line 97 says the whole IndexedDB is removed. That removal includes
liner_analysis_v1. The guide should state this exception.Suggested fix
Committable suggestion