forked from trav/lintunes
File → Export Playlist…, and the same item on a playlist's right-click
menu. A sibling of device_sync: pure plan_export() first, then a worker
on a daemon thread sharing the status-bar progress widgets. The manifest
(index.html / .m3u) is written last, so an interrupted export never
leaves a page naming files that aren't there.
Two destinations. A folder gives the audio under "Artist - Title" names
plus an extended .m3u. A web mix gives a self-contained static site
reproducing the hand-made yearly mixes, with a dialog for title,
description and hero image.
audio.js and jQuery are gone. The old pages shipped ~293 KB: a build of
audio.js whose upstream hasn't moved since 2012, plus jQuery 3.2.1
(CVE-2019-11358, CVE-2020-11022, CVE-2020-11023 — unexploitable on a
static page, since nothing untrusted reaches a jQuery HTML sink, but
dead weight regardless). audio.js never used jQuery; jQuery was there
for ~25 lines of tracklist glue. Both are replaced by a dependency-free
player.js plus a player.css transcribed from the customized audio.js
skin, so the page looks identical — same 250px #c7b563 bar, same
player-graphics.gif (byte-identical: it's an animated GIF whose loading
frame is a spinner), same shortcuts. ~293 KB → ~6 KB. The Flash
fallback went too; audio.js gated it on !canPlayType("audio/mpeg;"),
unreachable since ~2010.
Conversion happens only when a browser genuinely can't decode a file,
never because of bitrate — a 320 kbps MP3 is copied verbatim. Everything
that does convert targets FLAC, so a conversion cannot cost a bit; a
test asserts the exported FLAC's decoded PCM hashes identical to the
ALAC source. Against the real library that's 105 Apple Lossless and 8
AIFF out of 21,382 tracks. DRM'd tracks are reported in a confirmation
dialog, never silently dropped and never attempted. ffmpeg is the CLI
binary here, not Qt's ffmpeg backend, so it's detected at runtime.
Verified in Chromium 151 and Firefox 153 over CDP/Marionette: every
exported format decodes including the converted FLAC, the player builds,
click / space / arrows / scrubber-seek / autoplay-next all work, and the
network log shows no request for jquery, audio.min.js or any .swf.
mix-example/ removed; the template reproduces it.
130 lines
4.9 KiB
Python
130 lines
4.9 KiB
Python
"""The two dialogs behind File → Export Playlist…
|
|
|
|
`ExportKindDialog` asks folder-or-website; `WebMixDialog` collects the bits of
|
|
a web mix that can't be inferred — title, blurb, hero image. Per-track liner
|
|
notes are deliberately absent: the hand-made mixes carry a numbered paragraph
|
|
per track, which is far too much to type into a form, so the generated
|
|
index.html leaves a commented-out block in the right place instead.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from PyQt6.QtCore import Qt
|
|
from PyQt6.QtWidgets import (
|
|
QDialog, QDialogButtonBox, QFileDialog, QFormLayout, QHBoxLayout, QLabel,
|
|
QLineEdit, QPlainTextEdit, QPushButton, QRadioButton, QVBoxLayout)
|
|
|
|
from lintunes.export import exporter
|
|
|
|
_IMAGE_FILTER = "Images (*.png *.jpg *.jpeg *.gif *.webp)"
|
|
|
|
|
|
class ExportKindDialog(QDialog):
|
|
"""Folder of music files, or a self-contained web mix."""
|
|
|
|
def __init__(self, playlist_name: str, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("Export Playlist")
|
|
self.setMinimumWidth(420)
|
|
layout = QVBoxLayout(self)
|
|
|
|
layout.addWidget(QLabel(f"Export “{playlist_name}” as:"))
|
|
|
|
self._folder = QRadioButton("A folder of music files")
|
|
self._folder.setChecked(True)
|
|
layout.addWidget(self._folder)
|
|
hint = QLabel("The audio files, named “Artist - Title”, plus an .m3u "
|
|
"playlist. Files are copied exactly as they are.")
|
|
hint.setWordWrap(True)
|
|
hint.setIndent(24)
|
|
hint.setEnabled(False)
|
|
layout.addWidget(hint)
|
|
|
|
self._web = QRadioButton("A website")
|
|
layout.addWidget(self._web)
|
|
web_hint = QLabel(
|
|
"A self-contained page with a player and the tracklist, ready to "
|
|
"copy into a web directory. Anything a browser can't play is "
|
|
"converted to FLAC, losslessly.")
|
|
web_hint.setWordWrap(True)
|
|
web_hint.setIndent(24)
|
|
web_hint.setEnabled(False)
|
|
layout.addWidget(web_hint)
|
|
|
|
layout.addSpacing(8)
|
|
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
|
| QDialogButtonBox.StandardButton.Cancel)
|
|
buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Continue")
|
|
buttons.accepted.connect(self.accept)
|
|
buttons.rejected.connect(self.reject)
|
|
layout.addWidget(buttons)
|
|
|
|
def kind(self) -> str:
|
|
return exporter.WEB if self._web.isChecked() else exporter.FOLDER
|
|
|
|
|
|
class WebMixDialog(QDialog):
|
|
"""Title, description and hero image for a web mix."""
|
|
|
|
def __init__(self, playlist_name: str, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("Export Web Mix")
|
|
self.setMinimumWidth(520)
|
|
layout = QVBoxLayout(self)
|
|
form = QFormLayout()
|
|
form.setFieldGrowthPolicy(
|
|
QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
|
|
|
|
self._title = QLineEdit(playlist_name)
|
|
form.addRow("Title:", self._title)
|
|
|
|
self._description = QPlainTextEdit()
|
|
self._description.setPlainText(exporter.DEFAULT_DESCRIPTION)
|
|
self._description.setMinimumHeight(140)
|
|
form.addRow("Description:", self._description)
|
|
|
|
image_row = QHBoxLayout()
|
|
self._image = QLineEdit()
|
|
self._image.setPlaceholderText("(a gray placeholder)")
|
|
self._image.setReadOnly(True)
|
|
image_row.addWidget(self._image, stretch=1)
|
|
browse = QPushButton("Browse…")
|
|
browse.clicked.connect(self._choose_image)
|
|
image_row.addWidget(browse)
|
|
clear = QPushButton("Clear")
|
|
clear.clicked.connect(lambda: self._image.clear())
|
|
image_row.addWidget(clear)
|
|
form.addRow("Image:", image_row)
|
|
layout.addLayout(form)
|
|
|
|
note = QLabel(
|
|
"The description is plain HTML — links and <br> work. "
|
|
"Per-track liner notes aren't asked for here; index.html has a "
|
|
"commented-out block in the right spot for them.")
|
|
note.setWordWrap(True)
|
|
note.setTextFormat(Qt.TextFormat.RichText)
|
|
note.setEnabled(False)
|
|
layout.addWidget(note)
|
|
|
|
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
|
| QDialogButtonBox.StandardButton.Cancel)
|
|
buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Export")
|
|
buttons.accepted.connect(self.accept)
|
|
buttons.rejected.connect(self.reject)
|
|
layout.addWidget(buttons)
|
|
|
|
def _choose_image(self):
|
|
start = str(Path(self._image.text()).parent) if self._image.text() else ""
|
|
name, _filter = QFileDialog.getOpenFileName(
|
|
self, "Choose Image", start, _IMAGE_FILTER)
|
|
if name:
|
|
self._image.setText(name)
|
|
|
|
def values(self) -> dict:
|
|
text = self._image.text().strip()
|
|
return {
|
|
"title": self._title.text().strip(),
|
|
"description": self._description.toPlainText().strip(),
|
|
"image": Path(text) if text else None,
|
|
}
|