feat: Add support for specifying cli spotify image size
This commit is contained in:
@@ -48,8 +48,8 @@ def image_url_to_ascii(url, new_width=40):
|
|||||||
# Since we are using '██' (double width), we effectively make each "cell" square.
|
# Since we are using '██' (double width), we effectively make each "cell" square.
|
||||||
# So we can just scale by aspect ratio directly without additional correction factor.
|
# So we can just scale by aspect ratio directly without additional correction factor.
|
||||||
new_height = int(aspect_ratio * new_width)
|
new_height = int(aspect_ratio * new_width)
|
||||||
if new_height > 60:
|
if new_height > height:
|
||||||
new_height = 60
|
new_height = height
|
||||||
new_width = int(new_height / aspect_ratio)
|
new_width = int(new_height / aspect_ratio)
|
||||||
|
|
||||||
# Resize and ensure RGB mode
|
# Resize and ensure RGB mode
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ def callback():
|
|||||||
def currently_playing():
|
def currently_playing():
|
||||||
"""Public endpoint showing your current track."""
|
"""Public endpoint showing your current track."""
|
||||||
track = get_playing_spotify_track()
|
track = get_playing_spotify_track()
|
||||||
|
# Get terminal width for ASCII art scaling
|
||||||
|
width = request.args.get("width", default=40, type=int)
|
||||||
|
|
||||||
if isCLI(request):
|
if isCLI(request):
|
||||||
if "album_art" in track:
|
if "album_art" in track:
|
||||||
track["ascii_art"] = image_url_to_ascii(track["album_art"], new_width=40)
|
track["ascii_art"] = image_url_to_ascii(track["album_art"], new_width=width)
|
||||||
return render_template("spotify.ascii", track=track)
|
return render_template("spotify.ascii", track=track)
|
||||||
|
|
||||||
# Render a simple HTML page for browsers
|
# Render a simple HTML page for browsers
|
||||||
|
|||||||
@@ -18,4 +18,5 @@ URL: {{ track.url }}
|
|||||||
|
|
||||||
Progress: {{ track.progress_ms // 60000 }}:{{ '%02d' % ((track.progress_ms // 1000) % 60) }} / {{ track.duration_ms // 60000 }}:{{ '%02d' % ((track.duration_ms // 1000) % 60) }}
|
Progress: {{ track.progress_ms // 60000 }}:{{ '%02d' % ((track.progress_ms // 1000) % 60) }} / {{ track.duration_ms // 60000 }}:{{ '%02d' % ((track.duration_ms // 1000) % 60) }}
|
||||||
Status: {{ 'Playing' if track.is_playing else 'Paused' }}
|
Status: {{ 'Playing' if track.is_playing else 'Paused' }}
|
||||||
|
Note: Specify width with ?width=80 (default 40)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user