Skip to content

Commit

Permalink
Add default album art for dylanaraps#11
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 30, 2019
1 parent 228dfec commit 1177283
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bum/song.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_art(cache_dir, size, client):

if len(song) < 2:
print("album: Nothing currently playing.")
util.bytes_to_file(util.default_album_art(), cache_dir / "current.jpg")
return

file_name = f"{song['artist']}_{song['album']}_{size}.jpg".replace("/", "")
Expand All @@ -43,8 +44,10 @@ def get_art(cache_dir, size, client):
brainz.init()
album_art = brainz.get_cover(song, size)

if album_art:
util.bytes_to_file(album_art, cache_dir / file_name)
util.bytes_to_file(album_art, cache_dir / "current.jpg")
if not album_art:
album_art = util.default_album_art()

print(f"album: Swapped art to {song['artist']}, {song['album']}.")
util.bytes_to_file(album_art, cache_dir / file_name)
util.bytes_to_file(album_art, cache_dir / "current.jpg")

print(f"album: Swapped art to {song['artist']}, {song['album']}.")
20 changes: 20 additions & 0 deletions bum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Util functions.
"""
import pathlib
import base64


def bytes_to_file(input_data, output_file):
Expand All @@ -10,3 +11,22 @@ def bytes_to_file(input_data, output_file):

with open(output_file, "wb") as file:
file.write(input_data)


def default_album_art():
return base64.b64decode("""
iVBORw0KGgoAAAANSUhEUgAAAOYAAADmAQMAAAD7pGv4AAAABGdBTUEAALGPC/xhBQAAAAFzUkdC
AK7OHOkAAAAGUExURf///yIkJdTndBEAAAKFSURBVFjDpdmxbSMxEIVhGhdMxgpYhEKWxdDhZdfW
VXA1sBAHlheCIGlnvuBE2IC1lLn8d8mZN4+tvdEu7JvoXW2gd7ded378bVH3/vr981O1OP69av24
ddXGMe2qzdtvhdsAvG/3rnBbDXywlsBxH6DCrYHHfeIVbg28HkbIcUvg22wDuCVwPA2R41bA42nq
OW4FvF7GyHAL4PtcA7gFcJwGyXBz4HGafIabA69klJbcrQM3BX6gTIAjHSa72QZuBjyLv8/fH8BN
gJ/mGcBNgKMc6HyrDdwz8MSn128P4J6AX2YZwD19DA7VOY1BhEn8xUe39dhPLyWaXujTheBS6Vxm
g0t0cnkvbo2tbZVsumjasA+XgqGgM4wMhqDJ8LUY+rbCZhpUoykg3y8GQ31nmhhMMZPpaTG1baXF
ImlGU8K9XQ6m8k4ZMCghJuXHonTZkj2lKIomQXV0BKVap8wblIiT8nJRmm7JWojeaBLM166gFO+U
8YMlgAqECdwf4I3eDtwrMHCvwH9U8Hz8Yz30xd7PN3q//n9WJvLT8JP0W/Ab9NvnyvGq84r1avdO
8S7zDvXuZmRwVHFEcjRzJHQUdQR29Gbkd9ZwxnG2cqZzlnSGdXZmZrcqsKKwGrGSsQqygrL6onKz
6rNitNq0UrXKtUK2uqYyt6p3ReBqwpWIqxhXQK6eWHm5anPF52rRlaarVFe4ro5ZWbsqd0VvN8BO
gl0IOxh2P+ic2HWxY2O3x06RXSY7VHa36IzZVbMjZzfPTqBdRDuQi8lrK/HZNbXjarfWTq9dYjvM
i+JkS9jYFbejbjfeTr5PAXyCsCg+t4SrTz18YuLTFp/U+JTHJ0QX9F7aG+0bqTynufgX4tAAAAAA
SUVORK5CYII=
""")

0 comments on commit 1177283

Please sign in to comment.