Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Proposal : Update playlist cover image #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spotnik/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from spotnik.bans import *
import random
from spotnik.post_description import *
from spotnik.update_cover import *
from spotnik.api import *
from rich import print

Expand Down Expand Up @@ -123,6 +124,9 @@ def main():
# change the playlist description to a random fact
post_description(spotify, job)

# change the playlist cover to a random predefined image
update_cover(spotify, job)

return "Success!"


Expand Down
2 changes: 1 addition & 1 deletion spotnik/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from rich import print

SPOTIFY_SCOPE = "playlist-modify-private, playlist-modify-public, user-library-read, playlist-read-private, user-library-modify, user-read-recently-played"
SPOTIFY_SCOPE = "playlist-modify-private, playlist-modify-public, user-library-read, playlist-read-private, user-library-modify, user-read-recently-played, ugc-image-upload"
SPOTIFY_SCOPE_WARNING = "signing into spotify...\nIf this program or another program with the same client_id\nhas changed scopes, you'll need to reauthorize each time.\nMake sure all programs have the same scope."
SPOTIFY_USER = os.getenv("SPOTIFY_USER")
SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
Expand Down
2 changes: 2 additions & 0 deletions spotnik/data/_example_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name": "Spotnik Example Playlist 1",
"description": "These are the songs I'm listening to today.",
"remove_low_energy": False,
"randomize_cover": True,
"last_track_ids": ["3eWGQXWe5cDY8xNQwaXtzs"],
"banned_artist_names": [
"khalid",
Expand Down Expand Up @@ -65,6 +66,7 @@
"name": "Spotnik Example Playlist 2",
"description": "These are the songs I'm lifting to today.",
"remove_low_energy": True,
"randomize_cover": False,
"last_track_ids": [],
},
]
19 changes: 19 additions & 0 deletions spotnik/update_cover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os, random, base64

def getImage():
# get random image cover
imgDir = "spotnik/data/images/"
randomImage = random.choice(os.listdir(imgDir))

with open(imgDir + randomImage, "rb") as img_file:
my_string = base64.b64encode(img_file.read())

return my_string.decode('utf-8')

def update_cover(spotify, job):
if job['randomize_cover']:

image = getImage()
spotify.playlist_upload_cover_image(
job["playlist_id"], image_b64=image
)