diff --git a/websitepart.py b/websitepart.py index 27481cf..0a019e7 100644 --- a/websitepart.py +++ b/websitepart.py @@ -5,6 +5,7 @@ import os import json import requests import re +from collections import defaultdict app = Flask(__name__) @@ -39,6 +40,7 @@ def get_scrobbles(): music_data = {extract_filename(row[2]): (row[0], row[1]) for row in music_cursor.fetchall()} music_conn.close() + total_durations = defaultdict(int) enriched_data = [] for ts, duration, extra_json in scrobbles: try: @@ -47,6 +49,7 @@ def get_scrobbles(): filename = extract_filename(filepath) if filename in music_data: title, videoid = music_data[filename] + total_durations[(title, videoid)] += duration enriched_data.append({ 'title': title, 'videoid': videoid, @@ -55,11 +58,22 @@ def get_scrobbles(): }) except json.JSONDecodeError: continue - return enriched_data + + unique_tracks = {} + for track in enriched_data: + key = (track['title'], track['videoid']) + if key not in unique_tracks: + unique_tracks[key] = { + 'title': track['title'], + 'videoid': track['videoid'], + 'total_duration': total_durations[key], + 'last_played': track['timestamp'] + } + return sorted(unique_tracks.values(), key=lambda x: x['last_played'], reverse=True) @app.route('/swingmusicwrapped.html') def swing_history(): - scrobbles = get_scrobbles() + tracks = get_scrobbles() return render_template_string(''' @@ -93,6 +107,24 @@ def swing_history(): max-width: 1200px; margin: 0 auto; } + .header-buttons { + display: flex; + gap: 1rem; + margin-bottom: 2rem; + } + .play-button { + background: var(--card-bg); + border: 1px solid var(--border-color); + color: var(--text-color); + padding: 0.8rem 1.5rem; + border-radius: 5px; + text-decoration: none; + display: inline-flex; + align-items: center; + } + .play-button:hover { + background: #444; + } .history-table { width: 100%; border-collapse: collapse; @@ -126,37 +158,27 @@ def swing_history(): color: #666; font-size: 0.8rem; } - a.play-button { - background: #333; - border: 1px solid #444; - color: var(--text-color); - padding: 8px 16px; - border-radius: 5px; - text-decoration: none; - display: inline-block; - } - a.play-button:hover { - background: #444; - }
Cover | Song | -Duration(play time) | +Total Play Time | Last Play Date | Play | |
---|---|---|---|---|---|---|
{% if is_youtube(track.videoid) %} @@ -168,8 +190,8 @@ def swing_history(): {% endif %} | {{ track.title }} | -{{ (track.duration // 60)|int }}:{{ "%02d" % (track.duration % 60) }} | -{{ datetime.fromtimestamp(track.timestamp).strftime('%Y-%m-%d %H:%M') }} | +{{ (track.total_duration // 3600)|int }}h {{ ((track.total_duration % 3600) // 60)|int }}m | +{{ datetime.fromtimestamp(track.last_played).strftime('%Y-%m-%d %H:%M') }} | ▶ YT Music |