Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions radioactive/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ def handle_shazam(target_url: str):

# Also send a notification if possible
handle_notification("Song Identified", f"{title} - {artist}")

# Show the popup with all details
from radioactive.ui import handle_shazam_popup

handle_shazam_popup(result)
else:
log.warning("No match found for this song.")
else:
Expand Down
2 changes: 1 addition & 1 deletion radioactive/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self):
try:
self.__VERSION__ = metadata.version("radio-active")
except metadata.PackageNotFoundError:
self.__VERSION__ = "4.0.1" # change this on every update #
self.__VERSION__ = "4.0.2" # change this on every update #
self.pypi_api = "https://pypi.org/pypi/radio-active/json"
self.remote_version = ""

Expand Down
4 changes: 3 additions & 1 deletion radioactive/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def record_audio_from_url(input_url, output_file, force_mp3, loglevel, duration=
return process

except FileNotFoundError:
log.error("FFmpeg not found! Please install FFmpeg to use the recording feature.")
log.error(
"FFmpeg not found! Please install FFmpeg to use the recording feature."
)
except Exception as ex:
log.error(f"Error while starting recording: {ex}")
return None
Expand Down
72 changes: 72 additions & 0 deletions radioactive/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,78 @@ def handle_recording_popup(process, outfile_path) -> None:
log.error(f"Error in recording popup: {e}")


def handle_shazam_popup(result: dict) -> None:
"""Show identified song information in an alternate screen (Modal)."""
if not result or not result.get("track"):
log.error("No track information available to display.")
return

try:
from rich.align import Align
from rich.console import Console
from rich.panel import Panel
from rich.table import Table

track = result.get("track")
title = track.get("title", "N/A")
artist = track.get("subtitle", "N/A")
genre = track.get("genres", {}).get("primary", "N/A")
shazam_url = track.get("url", "N/A")

# Extract album and release year from sections if available
album = "N/A"
released = "N/A"
label = "N/A"

sections = track.get("sections", [])
for section in sections:
if section.get("type") == "SONG":
metadata = section.get("metadata", [])
for item in metadata:
if item.get("title") == "Album":
album = item.get("text", "N/A")
elif item.get("title") == "Released":
released = item.get("text", "N/A")
elif item.get("title") == "Label":
label = item.get("text", "N/A")

console = Console()
with console.screen():
table = Table(box=None, padding=(0, 2), show_header=False)
table.add_column("Property", style="cyan", justify="right")
table.add_column("Value", style="white")

table.add_row("Title:", f"[bold]{title}[/bold]")
table.add_row("Artist:", artist)
table.add_row("Album:", album)
table.add_row("Genre:", genre)
table.add_row("Released:", released)
table.add_row("Label:", label)
table.add_row("Shazam URL:", f"[link={shazam_url}]{shazam_url}[/link]")

info_panel = Panel(
table,
title="[bold white]🎵 Song Identified[/bold white]",
subtitle="Press Enter to return",
border_style="white",
padding=(1, 4),
width=100,
expand=False,
)

# Center the panel visually
console.print("\n" * 6)
console.print(Align.center(info_panel))

try:
console.input()
except (EOFError, KeyboardInterrupt):
pass

except Exception as e:
log.error(f"Error in shazam popup: {e}")


def handle_current_play_panel(curr_station_name: str = "") -> None:
"""
Print the currently playing station panel and sync station name state.
Expand Down
4 changes: 3 additions & 1 deletion radioactive/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def handle_runtime_help_menu():
Show a colorful popup-style help menu using 'rich'.
Uses the alternate screen buffer to avoid cluttering the console history.
"""
from rich.align import Align
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
Expand Down Expand Up @@ -342,7 +343,8 @@ def add(cmd, desc):
)

# Print the panel centered on the alternate screen
console.print(help_panel, justify="center")
console.print("\n" * 4)
console.print(Align.center(help_panel))

# Use console.input() to wait for Enter and avoid prompt capture
try:
Expand Down
Loading