Musyx Mobile: Android TV player for Yandex Music
Kotlin, Compose for TV and Media3 port of the desktop Musyx, with device-code sign-in, Home, My Wave, search, collection, detail pages, Now Playing with queue and lyrics, and settings for streaming quality, appearance, font size (small, medium, large) and language. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
46610d95fa
217 files changed
+26144
No files matched your search
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Draws the Musyx app icon (1024x1024 PNG) with no dependencies.
|
||||
|
||||
Aubergine squircle with amber wave lines, matching the My Wave hero.
|
||||
Usage: python3 tool/make_icon.py assets/icon/musyx.png
|
||||
"""
|
||||
import math
|
||||
import struct
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
SIZE = 1024
|
||||
# macOS icon grid: the body is 824px, centred, with a ~185px corner radius.
|
||||
BODY, RADIUS = 824, 185
|
||||
OFF = (SIZE - BODY) / 2
|
||||
TOP, BOTTOM = (0x35, 0x30, 0x42), (0x1C, 0x1A, 0x22)
|
||||
AMBER = (0xF0, 0xB2, 0x3E)
|
||||
LINES = 11
|
||||
|
||||
|
||||
def rounded_alpha(x, y):
|
||||
"""Coverage of the rounded square at pixel centre (x, y), anti-aliased."""
|
||||
px, py = x + 0.5 - OFF, y + 0.5 - OFF
|
||||
cx = min(max(px, RADIUS), BODY - RADIUS)
|
||||
cy = min(max(py, RADIUS), BODY - RADIUS)
|
||||
d = math.hypot(px - cx, py - cy) - RADIUS
|
||||
if px < 0 or py < 0 or px > BODY or py > BODY:
|
||||
d = max(d, 1.0)
|
||||
return min(max(0.5 - d, 0.0), 1.0)
|
||||
|
||||
|
||||
def wave(k, x):
|
||||
"""Height of line k at x, and its slope, in pixels."""
|
||||
u = (x - OFF) / BODY
|
||||
base = OFF + BODY * (0.34 + k * 0.034)
|
||||
amp = BODY * (0.045 + k * 0.006)
|
||||
f = 1.5 + k * 0.08
|
||||
ph = k * 0.55 + 1.1
|
||||
a = u * math.pi * f + ph
|
||||
b = u * math.pi * 4.2 - ph * 0.7
|
||||
y = base + math.sin(a) * amp + math.sin(b) * amp * 0.35
|
||||
dy = (math.cos(a) * amp * math.pi * f + math.cos(b) * amp * 0.35 * math.pi * 4.2) / BODY
|
||||
return y, dy
|
||||
|
||||
|
||||
def main(out):
|
||||
rows = []
|
||||
curves = [[wave(k, x + 0.5) for x in range(SIZE)] for k in range(LINES)]
|
||||
for y in range(SIZE):
|
||||
row = bytearray([0]) # filter: none
|
||||
t = y / SIZE
|
||||
bg = tuple(round(TOP[i] + (BOTTOM[i] - TOP[i]) * t) for i in range(3))
|
||||
for x in range(SIZE):
|
||||
cover = rounded_alpha(x, y)
|
||||
if cover == 0.0:
|
||||
row += b"\x00\x00\x00\x00"
|
||||
continue
|
||||
r, g, b = bg
|
||||
for k in range(LINES):
|
||||
cy, slope = curves[k][x]
|
||||
dist = abs(y + 0.5 - cy) / math.sqrt(1 + slope * slope)
|
||||
width = 4.0 + k * 0.9
|
||||
a = min(max(width / 2 - dist + 0.5, 0.0), 1.0)
|
||||
if a:
|
||||
a *= 0.18 + 0.82 * (k / (LINES - 1))
|
||||
r = r + (AMBER[0] - r) * a
|
||||
g = g + (AMBER[1] - g) * a
|
||||
b = b + (AMBER[2] - b) * a
|
||||
row += bytes((round(r), round(g), round(b), round(cover * 255)))
|
||||
rows.append(bytes(row))
|
||||
|
||||
def chunk(kind, data):
|
||||
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF)
|
||||
|
||||
png = b"\x89PNG\r\n\x1a\n"
|
||||
png += chunk(b"IHDR", struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0))
|
||||
png += chunk(b"IDAT", zlib.compress(b"".join(rows), 9))
|
||||
png += chunk(b"IEND", b"")
|
||||
with open(out, "wb") as f:
|
||||
f.write(png)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1] if len(sys.argv) > 1 else "musyx.png")
|
||||
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Draws the Android launcher assets from the shared design.
|
||||
|
||||
- The Android TV banner (320x180 px, drawable-xhdpi): the `musyx` wordmark in Unbounded
|
||||
SemiBold with the amber dot, centred on the dark `bg`, as in the desktop sidebar.
|
||||
- The launcher icons (mipmap-*dpi/ic_launcher.png), scaled from assets/icon/musyx.png
|
||||
(run tool/make_icon.py first if it changes).
|
||||
|
||||
Needs Pillow (pip install Pillow), unlike make_icon.py, because it sets type.
|
||||
Usage: python3 tool/make_tv_assets.py [app/src/main/res]
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
FONT = ROOT / "assets/fonts/Unbounded-SemiBold.ttf"
|
||||
ICON = ROOT / "assets/icon/musyx.png"
|
||||
|
||||
# DESIGN.md tokens (dark).
|
||||
BG = (0x1C, 0x1A, 0x22)
|
||||
FG = (0xEE, 0xEA, 0xF3)
|
||||
ACCENT = (0xF0, 0xB2, 0x3E)
|
||||
|
||||
BANNER = (320, 180)
|
||||
SUPERSAMPLE = 4
|
||||
# The wordmark is set at 20px with a 7px dot, 3px after the text, and -0.01em tracking.
|
||||
WORDMARK_PX = 20.0
|
||||
DOT, GAP, TRACKING = 7 / WORDMARK_PX, 3 / WORDMARK_PX, -0.01
|
||||
# Share of the banner width the wordmark spans.
|
||||
WIDTH_SHARE = 0.62
|
||||
|
||||
# Legacy launcher icon sizes, px per density bucket.
|
||||
MIPMAPS = {"mdpi": 48, "hdpi": 72, "xhdpi": 96, "xxhdpi": 144, "xxxhdpi": 192}
|
||||
# make_icon.py draws an 824px body on a 1024px canvas. Keep a thin margin around it.
|
||||
ICON_BODY, ICON_MARGIN = 824, 0.03
|
||||
|
||||
|
||||
def wordmark_width(font, em):
|
||||
advances = sum(font.getlength(c) for c in "musyx") + TRACKING * em * 4
|
||||
return advances + (GAP + DOT) * em
|
||||
|
||||
|
||||
def banner(out):
|
||||
w, h = (d * SUPERSAMPLE for d in BANNER)
|
||||
# Size the type so the whole wordmark spans WIDTH_SHARE of the banner.
|
||||
em = 100.0
|
||||
font = ImageFont.truetype(str(FONT), int(em))
|
||||
em *= w * WIDTH_SHARE / wordmark_width(font, em)
|
||||
font = ImageFont.truetype(str(FONT), round(em))
|
||||
total = wordmark_width(font, em)
|
||||
|
||||
img = Image.new("RGB", (w, h), BG)
|
||||
draw = ImageDraw.Draw(img)
|
||||
# Centre on the x-height band, which is what the eye reads for an all-lowercase word.
|
||||
x_height = font.getbbox("x", anchor="ls")[1]
|
||||
baseline = h / 2 - x_height / 2
|
||||
x = (w - total) / 2
|
||||
for c in "musyx":
|
||||
draw.text((x, baseline), c, font=font, fill=FG, anchor="ls")
|
||||
x += font.getlength(c) + TRACKING * em
|
||||
x += GAP * em - TRACKING * em
|
||||
d = DOT * em
|
||||
draw.ellipse((x, baseline - d, x + d, baseline), fill=ACCENT)
|
||||
|
||||
img = img.resize(BANNER, Image.LANCZOS)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
img.save(out, optimize=True)
|
||||
|
||||
|
||||
def launcher_icons(res):
|
||||
src = Image.open(ICON).convert("RGBA")
|
||||
side = src.width
|
||||
pad = (side - ICON_BODY) / 2 - ICON_BODY * ICON_MARGIN
|
||||
body = src.crop((round(pad), round(pad), round(side - pad), round(side - pad)))
|
||||
for bucket, px in MIPMAPS.items():
|
||||
out = res / f"mipmap-{bucket}" / "ic_launcher.png"
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
body.resize((px, px), Image.LANCZOS).save(out, optimize=True)
|
||||
|
||||
|
||||
def main(res):
|
||||
res = Path(res)
|
||||
banner(res / "drawable-xhdpi" / "banner.png")
|
||||
launcher_icons(res)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1] if len(sys.argv) > 1 else ROOT / "app/src/main/res")
|
||||
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Converts the Lucide SVGs in assets/icons to Android vector drawables (res/drawable/ic_<name>.xml).
|
||||
|
||||
Lucide draws everything in `currentColor`. The drawables keep that idea: every stroke and fill
|
||||
is plain white, which Compose's `Icon(tint = ...)` replaces with a theme token, so no design
|
||||
colour is baked in. Path data is re-tokenised so arc flags and packed numbers are unambiguous.
|
||||
|
||||
Usage: python3 tool/svg_to_vector.py [assets/icons] [app/src/main/res/drawable]
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
SVG = "{http://www.w3.org/2000/svg}"
|
||||
INK = "@android:color/white"
|
||||
ARGS = {"m": 2, "l": 2, "h": 1, "v": 1, "c": 6, "s": 4, "q": 4, "t": 2, "a": 7, "z": 0}
|
||||
NUMBER = re.compile(r"[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?")
|
||||
|
||||
|
||||
def fmt(v):
|
||||
s = f"{float(v):.3f}".rstrip("0").rstrip(".")
|
||||
return "0" if s == "-0" else s
|
||||
|
||||
|
||||
def normalise(d):
|
||||
"""Re-emits SVG path data with every command and argument separated by spaces."""
|
||||
out, i, cmd, args = [], 0, None, []
|
||||
while i < len(d):
|
||||
ch = d[i]
|
||||
if ch.isspace() or ch == ",":
|
||||
i += 1
|
||||
elif ch.isalpha():
|
||||
cmd = ch
|
||||
out.append(ch)
|
||||
args = []
|
||||
i += 1
|
||||
else:
|
||||
if cmd is None:
|
||||
raise ValueError(f"number before command in {d!r}")
|
||||
n = ARGS[cmd.lower()]
|
||||
# Arc flags are single digits and may be packed against the next number.
|
||||
if cmd.lower() == "a" and len(args) % 7 in (3, 4):
|
||||
tok = ch
|
||||
else:
|
||||
m = NUMBER.match(d, i)
|
||||
if not m:
|
||||
raise ValueError(f"bad path data at {d[i:]!r}")
|
||||
tok = m.group()
|
||||
args.append(tok)
|
||||
out.append(fmt(tok))
|
||||
i += len(tok)
|
||||
if n and len(args) % n == 0 and cmd in "Mm":
|
||||
# Extra pairs after a moveto are implicit linetos.
|
||||
cmd = "L" if cmd == "M" else "l"
|
||||
return " ".join(out)
|
||||
|
||||
|
||||
def shape_to_path(el):
|
||||
tag = el.tag.removeprefix(SVG)
|
||||
a = {k: float(v) for k, v in el.attrib.items() if k in ("cx", "cy", "r", "x", "y", "width", "height", "rx", "ry", "x1", "y1", "x2", "y2")}
|
||||
if tag == "path":
|
||||
return normalise(el.attrib["d"])
|
||||
if tag == "circle":
|
||||
cx, cy, r = a["cx"], a["cy"], a["r"]
|
||||
return f"M {fmt(cx - r)} {fmt(cy)} a {fmt(r)} {fmt(r)} 0 1 0 {fmt(2 * r)} 0 a {fmt(r)} {fmt(r)} 0 1 0 {fmt(-2 * r)} 0 Z"
|
||||
if tag == "line":
|
||||
return f"M {fmt(a['x1'])} {fmt(a['y1'])} L {fmt(a['x2'])} {fmt(a['y2'])}"
|
||||
if tag in ("polyline", "polygon"):
|
||||
nums = NUMBER.findall(el.attrib["points"])
|
||||
pts = [f"{fmt(nums[k])} {fmt(nums[k + 1])}" for k in range(0, len(nums), 2)]
|
||||
return "M " + " L ".join(pts) + (" Z" if tag == "polygon" else "")
|
||||
if tag == "rect":
|
||||
x, y, w, h = a.get("x", 0), a.get("y", 0), a["width"], a["height"]
|
||||
rx = a.get("rx", a.get("ry", 0))
|
||||
ry = a.get("ry", rx)
|
||||
if not rx:
|
||||
return f"M {fmt(x)} {fmt(y)} h {fmt(w)} v {fmt(h)} h {fmt(-w)} Z"
|
||||
return (
|
||||
f"M {fmt(x + rx)} {fmt(y)} h {fmt(w - 2 * rx)} a {fmt(rx)} {fmt(ry)} 0 0 1 {fmt(rx)} {fmt(ry)} "
|
||||
f"v {fmt(h - 2 * ry)} a {fmt(rx)} {fmt(ry)} 0 0 1 {fmt(-rx)} {fmt(ry)} "
|
||||
f"h {fmt(-(w - 2 * rx))} a {fmt(rx)} {fmt(ry)} 0 0 1 {fmt(-rx)} {fmt(-ry)} "
|
||||
f"v {fmt(-(h - 2 * ry))} a {fmt(rx)} {fmt(ry)} 0 0 1 {fmt(rx)} {fmt(-ry)} Z"
|
||||
)
|
||||
raise ValueError(f"unsupported element <{tag}>")
|
||||
|
||||
|
||||
def convert(svg_path):
|
||||
root = ET.parse(svg_path).getroot()
|
||||
vb = root.attrib["viewBox"].split()
|
||||
inherited = {k: root.attrib.get(k) for k in ("fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin")}
|
||||
lines = [
|
||||
'<?xml version="1.0" encoding="utf-8"?>',
|
||||
f"<!-- Lucide {svg_path.stem} (ISC, assets/icons/LICENSE.txt). Generated by tool/svg_to_vector.py; tint it in code. -->",
|
||||
'<vector xmlns:android="http://schemas.android.com/apk/res/android"',
|
||||
f' android:width="{fmt(vb[2])}dp"',
|
||||
f' android:height="{fmt(vb[3])}dp"',
|
||||
f' android:viewportWidth="{fmt(vb[2])}"',
|
||||
f' android:viewportHeight="{fmt(vb[3])}">',
|
||||
]
|
||||
for el in root.iter():
|
||||
if el is root:
|
||||
continue
|
||||
attrs = {**inherited, **{k: v for k, v in el.attrib.items() if k in inherited}}
|
||||
lines.append(" <path")
|
||||
lines.append(f' android:pathData="{shape_to_path(el)}"')
|
||||
if attrs["fill"] not in (None, "none"):
|
||||
lines.append(f' android:fillColor="{INK}"')
|
||||
if attrs["stroke"] not in (None, "none"):
|
||||
lines.append(f' android:strokeColor="{INK}"')
|
||||
lines.append(f' android:strokeWidth="{fmt(attrs["stroke-width"] or 1)}"')
|
||||
if attrs["stroke-linecap"]:
|
||||
lines.append(f' android:strokeLineCap="{attrs["stroke-linecap"]}"')
|
||||
if attrs["stroke-linejoin"]:
|
||||
lines.append(f' android:strokeLineJoin="{attrs["stroke-linejoin"]}"')
|
||||
lines[-1] += " />"
|
||||
lines.append("</vector>")
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
def main(src, dst):
|
||||
src, dst = Path(src), Path(dst)
|
||||
dst.mkdir(parents=True, exist_ok=True)
|
||||
for svg in sorted(src.glob("*.svg")):
|
||||
name = "ic_" + svg.stem.replace("-", "_")
|
||||
(dst / f"{name}.xml").write_text(convert(svg))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(
|
||||
sys.argv[1] if len(sys.argv) > 1 else ROOT / "assets/icons",
|
||||
sys.argv[2] if len(sys.argv) > 2 else ROOT / "app/src/main/res/drawable",
|
||||
)
|
||||
Reference in new issue
Block a user