From ba0cdcb27b1a313c1714db813d4578ef8f8b4c8c Mon Sep 17 00:00:00 2001 From: Danilo Reyes Date: Tue, 11 Nov 2025 10:21:41 -0600 Subject: [PATCH] Add HTML report generation for missing albums - Introduced a new `html_report.py` file to generate an HTML report for albums to add and update. - Implemented a `generate_html_report` function that creates a styled HTML document with clickable submission links. - Integrated the new report generation function into `main.py` to streamline the process of reporting missing albums. - Enhanced user experience with filtering options for album types and artists in the generated report. --- html_report.py | 357 +++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 176 +----------------------- 2 files changed, 359 insertions(+), 174 deletions(-) create mode 100644 html_report.py diff --git a/html_report.py b/html_report.py new file mode 100644 index 0000000..ed08177 --- /dev/null +++ b/html_report.py @@ -0,0 +1,357 @@ +"""HTML report generation for missing albums""" + +from html import escape +from typing import Dict, List + + +def generate_html_report(albums_to_add: List[Dict], albums_to_update: List[Dict]): + """Generate an HTML report with clickable submission links""" + html_content = """ + + + + + MusicBrainz Albums - Add & Update + + + +

🎵 MusicBrainz Albums - Add & Update

+
+ Albums to ADD: {add_count} | Albums to UPDATE: {update_count} +
+
+
+ +
+ + + +
+
+
+ +
+ + {artist_buttons} +
+
+
+ +""" + + album_html = """ +
+
{title}
+
by {artist}
+ {mb_info} + {issues_info} + + +
+""" + + def format_album(album: Dict, is_update: bool = False) -> str: + submission_links = album.get("submission_links", {}) + mb_info = "" + issues_info = "" + + if is_update: + mb_url = album.get("mb_url", "") + if mb_url: + mb_info = f'' + issues = album.get("album_issues", []) + if issues: + issues_info = f'
Issues: {", ".join(issues)}
' + + title = album.get("title", "Unknown Title") + artist = album.get("artist_name", "Unknown Artist") + artist_escaped = escape(artist) + atisket_link = submission_links.get("atisket_link", "#") + harmony_link = submission_links.get("harmony_link", "#") + deezer_url = submission_links.get("deezer_url", "#") + + return album_html.format( + title=escape(title), + artist=artist, + artist_escaped=artist_escaped, + mb_info=mb_info, + issues_info=issues_info, + atisket_link=atisket_link, + harmony_link=harmony_link, + deezer_url=deezer_url, + ) + + all_albums = albums_to_add + albums_to_update + unique_artists = sorted( + set(album.get("artist_name", "Unknown") for album in all_albums) + ) + + artist_buttons_html = "".join( + f'' + for artist in unique_artists + ) + + albums_html = "" + if albums_to_add: + albums_html += '
' + albums_html += "

📥 Albums to ADD (Not in MusicBrainz)

" + formatted_add = map(lambda album: format_album(album, False), albums_to_add) + albums_html += "".join(formatted_add) + albums_html += "
" + + if albums_to_update: + albums_html += '
' + albums_html += "

🔄 Albums to UPDATE (Need Linking/Updates)

" + formatted_update = map( + lambda album: format_album(album, True), albums_to_update + ) + albums_html += "".join(formatted_update) + albums_html += "
" + + add_count = len(albums_to_add) + update_count = len(albums_to_update) + html_header = html_content.format( + add_count=add_count, + update_count=update_count, + artist_buttons=artist_buttons_html, + ) + html_footer = "\n\n\n" + html_content = html_header + albums_html + html_footer + + with open("missing_albums.html", "w", encoding="utf-8") as f: + f.write(html_content) + print(f"📄 HTML report saved to missing_albums.html") diff --git a/main.py b/main.py index dac37bc..6f3efb2 100755 --- a/main.py +++ b/main.py @@ -13,6 +13,8 @@ from urllib.parse import quote import requests from dotenv import load_dotenv +from html_report import generate_html_report + load_dotenv() @@ -342,179 +344,5 @@ def main(): generate_html_report(all_albums_to_add, all_albums_to_update) -def generate_html_report(albums_to_add: List[Dict], albums_to_update: List[Dict]): - """Generate an HTML report with clickable submission links""" - html_content = """ - - - - - MusicBrainz Albums - Add & Update - - - -

🎵 MusicBrainz Albums - Add & Update

-
- Albums to ADD: {add_count} | Albums to UPDATE: {update_count} -
-""" - - album_html = """ -
-
{title}
-
by {artist}
- {mb_info} - {issues_info} - - -
-""" - - def format_album(album: Dict, is_update: bool = False) -> str: - submission_links = album.get("submission_links", {}) - mb_info = "" - issues_info = "" - - if is_update: - mb_url = album.get("mb_url", "") - if mb_url: - mb_info = f'' - issues = album.get("album_issues", []) - if issues: - issues_info = f'
Issues: {", ".join(issues)}
' - - title = album.get("title", "Unknown Title") - artist = album.get("artist_name", "Unknown Artist") - atisket_link = submission_links.get("atisket_link", "#") - harmony_link = submission_links.get("harmony_link", "#") - deezer_url = submission_links.get("deezer_url", "#") - - return album_html.format( - title=title, - artist=artist, - mb_info=mb_info, - issues_info=issues_info, - atisket_link=atisket_link, - harmony_link=harmony_link, - deezer_url=deezer_url, - ) - - albums_html = "" - if albums_to_add: - albums_html += "

📥 Albums to ADD (Not in MusicBrainz)

" - formatted_add = map(lambda album: format_album(album, False), albums_to_add) - albums_html += "".join(formatted_add) - - if albums_to_update: - albums_html += "

🔄 Albums to UPDATE (Need Linking/Updates)

" - formatted_update = map( - lambda album: format_album(album, True), albums_to_update - ) - albums_html += "".join(formatted_update) - - add_count = len(albums_to_add) - update_count = len(albums_to_update) - html_header = html_content.format(add_count=add_count, update_count=update_count) - html_footer = "\n\n\n" - html_content = html_header + albums_html + html_footer - - with open("missing_albums.html", "w", encoding="utf-8") as f: - f.write(html_content) - print(f"📄 HTML report saved to missing_albums.html") - - if __name__ == "__main__": main()