Skip to content

Commit

Permalink
OpenGraph playlist tags: better description
Browse files Browse the repository at this point in the history
Use the playlist creator and number of items in the playlist instead of using the playlist description.
This should be more useful than the text description of the playlist.
  • Loading branch information
MonkeyDo committed Jan 13, 2025
1 parent 2179419 commit cedeaef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions listenbrainz/db/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,24 @@ def get_recordings_for_playlists(db_conn, ts_conn, playlist_ids: List[int]):
playlist_recordings_map[playlist_id] = []
return dict(playlist_recordings_map)

def get_recordings_count_for_playlist(ts_conn, playlist_id: int):
""" Get a count of recordings for a given playlist.
Arguments:
ts_conn: timsecale database connection
playlist_id: Numerical sequential id of a playlist (NOT its UUID)
Returns:
an integer of the number of recordings in the playlist """

query = text("""
SELECT COUNT(*)
FROM playlist.playlist_recording
WHERE playlist_id = :playlist_id
""")
result = ts_conn.execute(query, {"playlist_id": playlist_id})
return result.scalar()


def _remove_old_collaborative_playlists(ts_conn, creator_id: int, created_for_id: int, source_patch: str):
"""
Expand Down
3 changes: 2 additions & 1 deletion listenbrainz/webserver/views/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ def playlist_page(playlist_mbid: str):
if is_valid_uuid(playlist_mbid):
playlist = db_playlist.get_by_mbid(db_conn, ts_conn, playlist_mbid, False)
if playlist is not None and playlist.is_visible_by(current_user_id):
recordings_count = db_playlist.get_recordings_count_for_playlist(ts_conn, playlist.id)
og_meta_tags = {
"title": f'{playlist.name} — Playlist on ListenBrainz',
"description": playlist.description,
"description": f'Playlist by {playlist.creator}{recordings_count} track{"s" if recordings_count > 1 else ""} — ListenBrainz',
"type": "music:playlist",
"url": f'{current_app.config["SERVER_ROOT_URL"]}/playlist/{playlist_mbid}',
"music:creator": f'{current_app.config["SERVER_ROOT_URL"]}/user/{playlist.creator}',
Expand Down

0 comments on commit cedeaef

Please sign in to comment.