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.
This commit is contained in:
176
main.py
176
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 = """<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>MusicBrainz Albums - Add & Update</title>
|
||||
<style>
|
||||
body {{
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}}
|
||||
h1 {{
|
||||
color: #333;
|
||||
border-bottom: 3px solid #4CAF50;
|
||||
padding-bottom: 10px;
|
||||
}}
|
||||
h2 {{
|
||||
color: #2196F3;
|
||||
margin-top: 30px;
|
||||
border-bottom: 2px solid #2196F3;
|
||||
padding-bottom: 5px;
|
||||
}}
|
||||
.album {{
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}}
|
||||
.album-title {{
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
color: #2196F3;
|
||||
margin-bottom: 10px;
|
||||
}}
|
||||
.artist-name {{
|
||||
color: #666;
|
||||
margin-bottom: 15px;
|
||||
}}
|
||||
.links {{
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}}
|
||||
.link-button {{
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s;
|
||||
}}
|
||||
.link-button:hover {{
|
||||
background-color: #45a049;
|
||||
}}
|
||||
.link-button.atisket {{
|
||||
background-color: #2196F3;
|
||||
}}
|
||||
.link-button.atisket:hover {{
|
||||
background-color: #0b7dda;
|
||||
}}
|
||||
.link-button.harmony {{
|
||||
background-color: #FF9800;
|
||||
}}
|
||||
.link-button.harmony:hover {{
|
||||
background-color: #e68900;
|
||||
}}
|
||||
.deezer-link {{
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
margin-top: 10px;
|
||||
}}
|
||||
.mb-link {{
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
margin-top: 5px;
|
||||
}}
|
||||
.issues {{
|
||||
color: #FF9800;
|
||||
font-size: 0.9em;
|
||||
margin-top: 5px;
|
||||
font-style: italic;
|
||||
}}
|
||||
.summary {{
|
||||
background: white;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🎵 MusicBrainz Albums - Add & Update</h1>
|
||||
<div class="summary">
|
||||
<strong>Albums to ADD: {add_count}</strong> | <strong>Albums to UPDATE: {update_count}</strong>
|
||||
</div>
|
||||
"""
|
||||
|
||||
album_html = """
|
||||
<div class="album">
|
||||
<div class="album-title">{title}</div>
|
||||
<div class="artist-name">by {artist}</div>
|
||||
{mb_info}
|
||||
{issues_info}
|
||||
<div class="links">
|
||||
<a href="{atisket_link}" target="_blank" class="link-button atisket">Submit via a-tisket</a>
|
||||
<a href="{harmony_link}" target="_blank" class="link-button harmony">Submit via Harmony</a>
|
||||
</div>
|
||||
<div class="deezer-link">
|
||||
<a href="{deezer_url}" target="_blank">View on Deezer</a>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
|
||||
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'<div class="mb-link"><a href="{mb_url}" target="_blank">View on MusicBrainz</a></div>'
|
||||
issues = album.get("album_issues", [])
|
||||
if issues:
|
||||
issues_info = f'<div class="issues">Issues: {", ".join(issues)}</div>'
|
||||
|
||||
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 += "<h2>📥 Albums to ADD (Not in MusicBrainz)</h2>"
|
||||
formatted_add = map(lambda album: format_album(album, False), albums_to_add)
|
||||
albums_html += "".join(formatted_add)
|
||||
|
||||
if albums_to_update:
|
||||
albums_html += "<h2>🔄 Albums to UPDATE (Need Linking/Updates)</h2>"
|
||||
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</body>\n</html>\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()
|
||||
|
||||
Reference in New Issue
Block a user