🎨 Code Examples¢

This is a quick guide on how to generate posters using BeatPrints through code.

Note

It is important for you to have the .env file in the same directory.

🎷 Track Posters¢

To generate a track poster, follow the steps below.

import os, dotenv
from BeatPrints import lyrics, poster, spotify

dotenv.load_dotenv()

# Spotify credentials
CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
CLIENT_SECRET = os.getenv("SPOTIFY_CLIENT_SECRET")

# Initialize components
ly = lyrics.Lyrics()
ps = poster.Poster("./")
sp = spotify.Spotify(CLIENT_ID, CLIENT_SECRET)

# Search for the track and fetch metadata
search = sp.get_track("Saturn - SZA", limit=1)

# Pick the first result
metadata = search[0]

# Get lyrics for the track
lyrics = ly.get_lyrics(metadata)

# Use the placeholder for instrumental tracks; otherwise, select specific lines
highlighted_lyrics = (
    lyrics if ly.check_instrumental(metadata) else ly.select_lines(lyrics, "5-9")
)

# Generate the track poster
ps.track(metadata, highlighted_lyrics)

Tip

You can create a helper function to display lyrics with line numbers in a nice format using rich. This is just a basic way to generate the poster. The sky’s the limit!

πŸ’ΏοΈ Album PostersΒΆ

Like tracks, you can also create an album poster, follow these steps below.

import os, dotenv
from BeatPrints import poster, spotify

dotenv.load_dotenv()

# Spotify credentials
CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
CLIENT_SECRET = os.getenv("SPOTIFY_CLIENT_SECRET")

# Initialize components
ps = poster.Poster("./")
sp = spotify.Spotify(CLIENT_ID, CLIENT_SECRET)

# Search for an album
search = sp.get_album("Charm - Clairo", limit=1)

# Get the album's metadata
metadata = search[0]

# Generate the album poster
ps.album(metadata)

This is a basic guide on generating your posters. You can extend it by creating your own functions to make them more useful.

Tip

Use a hyphen (-) between the track/album and the artist for more accurate results.

See also

For more details, see the Reference section on using BeatPrints.