Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenGraph meta tags: Add OG tags for artist page
Browse files Browse the repository at this point in the history
MonkeyDo committed Jan 9, 2025
1 parent 53b24df commit 4621fad
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions listenbrainz/webserver/views/entity_pages.py
Original file line number Diff line number Diff line change
@@ -111,14 +111,35 @@ def release_redirect(release_mbid):


@artist_bp.route("/", defaults={'path': ''})
@artist_bp.route('/<path:path>/')
def artist_page(path):
return render_template("index.html")
@artist_bp.route("/<artist_mbid>/", methods=["GET"])
def artist_page(artist_mbid:str):
og_meta_tags = None
if is_valid_uuid(artist_mbid) and artist_mbid not in {"89ad4ac3-39f7-470e-963a-56509c546377"}:
artist_data = get_metadata_for_artist(ts_conn, [artist_mbid])
if len(artist_data) == 0:
pass
else:
artist = artist_data[0]
artist_name = artist.artist_data.get("name")
release_group_mbids = [rg["mbid"] for rg in artist.release_group_data]
album_count = artist.release_group_data.count()
popularity_data, _ = popularity.get_counts(ts_conn, "release_group", release_group_mbids)
total_listen_count = sum(rg["total_listen_count"] for rg in popularity_data)

og_meta_tags = {
"title": f'{artist_name}',
"description": f'Artist - {total_listen_count} listens — {album_count} albums — ListenBrainz',
"type": "profile",
"profile:username": artist_name,
"profile.gender": artist.artist_data.get("gender"),
"url": f'{current_app.config["SERVER_ROOT_URL"]}/artist/{artist.artist_mbid}',
}
return render_template("index.html", og_meta_tags=og_meta_tags)


@artist_bp.route("/<artist_mbid>/", methods=["POST"])
@web_listenstore_needed
def artist_entity(artist_mbid):
def artist_entity(artist_mbid:str):
""" Show a artist page with all their relevant information """
# VA artist mbid
if artist_mbid in {"89ad4ac3-39f7-470e-963a-56509c546377"}:

0 comments on commit 4621fad

Please sign in to comment.