+ {%- block head -%}
+
+
+ {% block title %}{{user_name|safe}}'s' pin - ListenBrainz{% endblock
+ %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {# The css file has a .less extension in the manifest file entry (due to its
+ original name in Webpack entry) #}
+
+ {%- endblock -%}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/listenbrainz/webserver/templates/widgets/playing_now.html b/listenbrainz/webserver/templates/widgets/playing_now.html
new file mode 100644
index 0000000000..df913600db
--- /dev/null
+++ b/listenbrainz/webserver/templates/widgets/playing_now.html
@@ -0,0 +1,246 @@
+
+
+
+ {%- block head -%}
+
+
+ {% block title %}{{user_name|safe}} playing now - ListenBrainz{% endblock
+ %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {# The css file has a .less extension in the manifest file entry (due to its
+ original name in Webpack entry) #}
+
+ {%- endblock -%}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/listenbrainz/webserver/views/user.py b/listenbrainz/webserver/views/user.py
index cb9211524b..e574ae7a39 100644
--- a/listenbrainz/webserver/views/user.py
+++ b/listenbrainz/webserver/views/user.py
@@ -347,6 +347,48 @@ def year_in_music(user_name, year: int = 2023):
},
})
+# Embedable widgets, return HTML page to embed in an iframe
+
+
+@user_bp.route("//embed/playing-now", methods=['GET'])
+def embed_playing_now(user_name):
+ # Which database to use to show playing_now stream.
+ playing_now_conn = webserver.redis_connection._redis
+
+ user = _get_user(user_name)
+ if not user:
+ return jsonify({"error": "Cannot find user: %s" % user_name}), 404
+
+ # User name used to get user may not have the same case as original user name.
+ user_name = user.musicbrainz_id
+
+ playing_now = playing_now_conn.get_playing_now(user.id)
+ if playing_now:
+ playing_now = playing_now.to_api()
+
+ return render_template("widgets/playing_now.html", user_name=user_name, playing_now=playing_now)
+
+# Embedable widgets, return HTML page to embed in an iframe
+
+
+@user_bp.route("//embed/pin", methods=['GET'])
+def embed_pin(user_name):
+ # Which database to use to show playing_now stream.
+
+ user = _get_user(user_name)
+ if not user:
+ return jsonify({"error": "Cannot find user: %s" % user_name}), 404
+
+ # User name used to get user may not have the same case as original user name.
+ user_name = user.musicbrainz_id
+
+ pin = get_current_pin_for_user(db_conn, user_id=user.id)
+ if pin:
+ pin = fetch_track_metadata_for_items(
+ webserver.ts_conn, [pin])[0].to_api()
+
+ return render_template("widgets/pin.html", user_name=user_name, pinned_recording=pin)
+
@user_bp.route("//", defaults={'path': ''})
@user_bp.route('///')