initial commit

This commit is contained in:
2025-07-20 20:17:02 +02:00
commit 62166624dc
9 changed files with 2272 additions and 0 deletions

61
hipsterfy/panel_page.py Normal file
View File

@ -0,0 +1,61 @@
import panel as pn
from hipsterfy.hipsterfy import Hipsterfy, HipsterfyPlaylist, HipsterfyPlaylistItem
def create_panel_page(hipsterfy: Hipsterfy, playlist_uri: str=None) -> pn.Template:
# create widgets
playlist_uri = pn.widgets.TextInput(name='Playlist URI', value=playlist_uri or '', placeholder='Enter Spotify Playlist URI')
primary_item = pn.widgets.Select(name='Primary Item', options=HipsterfyPlaylistItem.get_available_properties(), value="release_year")
secondary_item = pn.widgets.Select(name='Secondary Item', options=HipsterfyPlaylistItem.get_available_properties(), value="title")
additional_items = pn.widgets.MultiChoice(name='Additional Items', options=HipsterfyPlaylistItem.get_available_properties(), value=["artist", "album"])
enable_album_art = pn.widgets.Checkbox(name='Enable Album Art', value=True)
create_preview_button = pn.widgets.Button(name='Create Preview', button_type='primary')
front_cards_column = pn.Column(sizing_mode='stretch_width')
back_cards_column = pn.Column(sizing_mode='stretch_width')
# add widgets to the sidebar of the template
template = pn.template.FastListTemplate(
title='Hipsterfy Playlist Manager',
sidebar=[playlist_uri, primary_item, secondary_item, additional_items, enable_album_art, create_preview_button],
main=[pn.Row(front_cards_column, back_cards_column, sizing_mode='stretch_width')],
accent_base_color='indigo',
header_background='indigo',
header_color='white'
)
def create_preview(event):
# clear previous cards
front_cards_column.clear()
back_cards_column.clear()
# get playlist URI
uri = playlist_uri.value.strip()
if not uri:
pn.state.notifications.error("Please enter a valid Spotify Playlist URI.")
return
# create HipsterfyPlaylist instance
hipsterfy_playlist = HipsterfyPlaylist(uri, hipsterfy)
# generate front and back cards for each item in the playlist
for item in hipsterfy_playlist.get_tracks_data():
front_card = item.generate_hipsterfy_front_card(include_preview=False)
back_card = item.generate_hipsterfy_back_card(
primary_property=primary_item.value,
secondary_property=secondary_item.value,
additional_properties=additional_items.value,
album_cover_gb=enable_album_art.value
)
front_cards_column.append(pn.pane.HTML(front_card, sizing_mode='stretch_width'))
back_cards_column.append(pn.pane.HTML(back_card, sizing_mode='stretch_width'))
# notify user of success
# bind the create_preview function to the button click event
create_preview_button.on_click(create_preview)
# return the template
return template