forked from trav/lintunes
v0.49.0: a web mix can carry several images, one after another under the description
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.48.2"
|
||||
__version__ = "0.49.0"
|
||||
|
||||
+29
-15
@@ -107,7 +107,7 @@ class ExportPlan:
|
||||
m3u_name: str # "" for a web mix, which writes no m3u
|
||||
title: str = ""
|
||||
description: str = ""
|
||||
image: Path | None = None # None = ship the gray placeholder
|
||||
images: list = field(default_factory=list) # [] = the gray placeholder
|
||||
accent: str = DEFAULT_ACCENT # hover backgrounds + the progress fill
|
||||
items: list = field(default_factory=list)
|
||||
skipped: list = field(default_factory=list) # (display, reason)
|
||||
@@ -208,18 +208,21 @@ def build_tracklist(items: list) -> str:
|
||||
return "\n".join(rows)
|
||||
|
||||
|
||||
def build_index_html(plan: ExportPlan, image_name: str | None) -> str:
|
||||
def build_index_html(plan: ExportPlan, image_names) -> str:
|
||||
"""Render index.html for `plan`.
|
||||
|
||||
The title and track names are escaped; the description deliberately is
|
||||
**not**, because the hand-made mixes lean on inline links and <br> in
|
||||
exactly that spot and the dialog says so.
|
||||
|
||||
`image_names` are the copied images, shown one after another with a
|
||||
blank line between each (a single name still works).
|
||||
"""
|
||||
if image_name:
|
||||
image_tag = (f' <img src="{html.escape(image_name, quote=True)}"'
|
||||
f' width="400"><br>')
|
||||
else:
|
||||
image_tag = ""
|
||||
if isinstance(image_names, str):
|
||||
image_names = [image_names]
|
||||
image_tag = "\n <br><br>\n".join(
|
||||
f' <img src="{html.escape(name, quote=True)}" width="400"><br>'
|
||||
for name in image_names or [])
|
||||
accent = normalize_accent(plan.accent)
|
||||
tmpl = string.Template((templates() / "index.html.tmpl").read_text(encoding="utf-8"))
|
||||
return tmpl.substitute(
|
||||
@@ -383,16 +386,27 @@ class ExportWorker(QObject):
|
||||
if plan.kind == WEB:
|
||||
for name in _WEB_ASSETS:
|
||||
shutil.copyfile(templates() / name, plan.dest_dir / name)
|
||||
if plan.image is not None and Path(plan.image).is_file():
|
||||
image_name = sanitize_name(Path(plan.image).stem) \
|
||||
+ Path(plan.image).suffix.lower()
|
||||
shutil.copyfile(plan.image, plan.dest_dir / image_name)
|
||||
else:
|
||||
image_name = "placeholder.png"
|
||||
image_names = []
|
||||
for image in plan.images:
|
||||
image = Path(image)
|
||||
if not image.is_file():
|
||||
continue
|
||||
name = sanitize_name(image.stem) + image.suffix.lower()
|
||||
# Two pictures called cover.jpg from different folders must
|
||||
# not overwrite each other.
|
||||
stem, ext = os.path.splitext(name)
|
||||
n = 2
|
||||
while name in image_names:
|
||||
name = f"{stem} {n}{ext}"
|
||||
n += 1
|
||||
shutil.copyfile(image, plan.dest_dir / name)
|
||||
image_names.append(name)
|
||||
if not image_names:
|
||||
image_names = ["placeholder.png"]
|
||||
shutil.copyfile(templates() / "placeholder.png",
|
||||
plan.dest_dir / image_name)
|
||||
plan.dest_dir / "placeholder.png")
|
||||
(plan.dest_dir / "index.html").write_text(
|
||||
build_index_html(plan, image_name), encoding="utf-8")
|
||||
build_index_html(plan, image_names), encoding="utf-8")
|
||||
return
|
||||
|
||||
entries = [(item.dest_name, item.secs, item.display)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""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, accent color —
|
||||
a web mix that can't be inferred — title, blurb, images, accent color —
|
||||
and whether to upload it to the web server set in Preferences (Round 81).
|
||||
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
|
||||
@@ -15,7 +15,7 @@ from PyQt6.QtGui import QColor
|
||||
from PyQt6.QtWidgets import (
|
||||
QCheckBox, QColorDialog, QDialog, QDialogButtonBox, QFileDialog,
|
||||
QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPlainTextEdit,
|
||||
QPushButton, QRadioButton, QVBoxLayout)
|
||||
QPushButton, QRadioButton, QVBoxLayout, QWidget)
|
||||
|
||||
from lintunes import theme
|
||||
from lintunes.export import exporter, upload
|
||||
@@ -68,7 +68,7 @@ class ExportKindDialog(QDialog):
|
||||
|
||||
|
||||
class WebMixDialog(QDialog):
|
||||
"""Title, description, hero image and accent color for a web mix.
|
||||
"""Title, description, images and accent color for a web mix.
|
||||
|
||||
The accent isn't remembered between exports: it opens on
|
||||
``exporter.DEFAULT_ACCENT`` every time, so an export nobody touched comes
|
||||
@@ -97,18 +97,15 @@ class WebMixDialog(QDialog):
|
||||
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)
|
||||
# One row per image, always with an empty one at the end: choosing a
|
||||
# file in the last row adds another below it, and clearing any other
|
||||
# row removes it.
|
||||
images = QWidget()
|
||||
self._image_rows = QVBoxLayout(images)
|
||||
self._image_rows.setContentsMargins(0, 0, 0, 0)
|
||||
self._images: list[QLineEdit] = []
|
||||
self._add_image_row()
|
||||
form.addRow("Images:", images)
|
||||
|
||||
color_row = QHBoxLayout()
|
||||
self._accent = exporter.DEFAULT_ACCENT
|
||||
@@ -208,12 +205,49 @@ class WebMixDialog(QDialog):
|
||||
return
|
||||
super().accept()
|
||||
|
||||
def _choose_image(self):
|
||||
start = str(Path(self._image.text()).parent) if self._image.text() else ""
|
||||
def _add_image_row(self):
|
||||
row = QWidget()
|
||||
layout = QHBoxLayout(row)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
field = QLineEdit()
|
||||
field.setReadOnly(True)
|
||||
field.setPlaceholderText("(a gray placeholder)" if not self._images
|
||||
else "(add another image)")
|
||||
layout.addWidget(field, stretch=1)
|
||||
browse = QPushButton("Browse…")
|
||||
browse.clicked.connect(lambda: self._choose_image(field))
|
||||
layout.addWidget(browse)
|
||||
clear = QPushButton("Clear")
|
||||
clear.clicked.connect(lambda: self._clear_image(field))
|
||||
layout.addWidget(clear)
|
||||
self._images.append(field)
|
||||
self._image_rows.addWidget(row)
|
||||
|
||||
def _choose_image(self, field: QLineEdit):
|
||||
# Start where this row's image is, or where the last one came from.
|
||||
near = field.text() or next(
|
||||
(f.text() for f in reversed(self._images) if f.text()), "")
|
||||
start = str(Path(near).parent) if near else ""
|
||||
name, _filter = QFileDialog.getOpenFileName(
|
||||
self, "Choose Image", start, _IMAGE_FILTER)
|
||||
if name:
|
||||
self._image.setText(name)
|
||||
self._set_image(field, name)
|
||||
|
||||
def _set_image(self, field: QLineEdit, path: str):
|
||||
field.setText(path)
|
||||
if field is self._images[-1]:
|
||||
self._add_image_row()
|
||||
|
||||
def _clear_image(self, field: QLineEdit):
|
||||
if field is self._images[-1]:
|
||||
field.clear()
|
||||
return
|
||||
index = self._images.index(field)
|
||||
self._images.pop(index)
|
||||
row = self._image_rows.takeAt(index).widget()
|
||||
row.deleteLater()
|
||||
# The first row's placeholder says what an export with none gets.
|
||||
self._images[0].setPlaceholderText("(a gray placeholder)")
|
||||
|
||||
def _set_accent(self, color_hex: str):
|
||||
self._accent = exporter.normalize_accent(color_hex)
|
||||
@@ -227,11 +261,11 @@ class WebMixDialog(QDialog):
|
||||
self._set_accent(color.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,
|
||||
"images": [Path(f.text().strip()) for f in self._images
|
||||
if f.text().strip()],
|
||||
"accent": self._accent,
|
||||
"upload": self._upload.isChecked(),
|
||||
"slug": self._slug.text().strip(),
|
||||
|
||||
@@ -975,7 +975,7 @@ class MainWindow(QMainWindow):
|
||||
if details is not None:
|
||||
plan.title = details["title"] or playlist.name
|
||||
plan.description = details["description"]
|
||||
plan.image = details["image"]
|
||||
plan.images = details["images"]
|
||||
plan.accent = details["accent"]
|
||||
|
||||
if not self._confirm_export(plan):
|
||||
@@ -1022,7 +1022,7 @@ class MainWindow(QMainWindow):
|
||||
return
|
||||
plan.title = details["title"] or playlist.name
|
||||
plan.description = details["description"]
|
||||
plan.image = details["image"]
|
||||
plan.images = details["images"]
|
||||
plan.accent = details["accent"]
|
||||
if not self._confirm_export(plan, local=False):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user