import os from flask import Flask, render_template_string, send_from_directory, abort from mastodon import Mastodon # === Configuration === ROOT_DIR = r"/mnt/convert/archives" # Update this path to where your shows live ALLOWED_EXTENSIONS = {".mp3", ".wav", ".flac", ".m4a"} BANNER_FILENAMES = ["banner.jpg", "banner.png", "banner.jpeg"] # Friendly display names DISPLAY_NAMES = { "80sdimension": "The 80s Dimension", "90slunch": "The 90s Lunch", "au": "Alternate Universe", "welch": "Bob Welch Retrospective", "bootycalls": "Booty Calls", "chaos": "The Chaos Bus", "mac": "Fleetwood Mac Retrospective", "gog": "The Good Ol Genesis", "housecalls": "House Calls", "pisces": "Pisces Playhouse", "retro": "The Retro Breakfast", "rockvault": "Rock Vault", "mayhem": "Rock and Roll Mayhem", "wakeman": "Rick Wakeman Retrospective", "sonicrevolt": "Sonic Revolt", "tunefuse": "TuneFuse", "wwo80s": "We Want Our 80s", "yacht": "Yacht Vibes Only", "yes": "Yes Retrospective", } # === URLs for File Hosting === BASE_URL = "http://server.genesis-radio.net:5020" # This is the base URL where your files live (e.g., http://localhost:5000) SERVER_URL = "http://genesis-radio.net" # This is the general server URL if you need it for anything else # === Flask App === app = Flask(__name__) HOME_TEMPLATE = """ Genesis Radio Archives

Genesis Radio: Show Archives

""" SHOW_TEMPLATE = """ {{ show_name }} - Genesis Radio ← Back to shows

{{ display_names.get(show_name, show_name) }}

{% if banner %} {% endif %} {% for file in files %}

{{ file }}

{% else %}

No audio files found for this show.

{% endfor %} """ # === Utility Functions === def list_shows(base_dir): return sorted([d for d in os.listdir(base_dir) if os.path.isdir(os.path.join(base_dir, d))]) def list_audio_files(show_dir): return sorted([ f for f in os.listdir(show_dir) if os.path.splitext(f)[1].lower() in ALLOWED_EXTENSIONS ]) def find_banner(show_dir): for name in BANNER_FILENAMES: if os.path.isfile(os.path.join(show_dir, name)): return name return None # === Flask Routes === @app.route("/") def index(): shows = list_shows(ROOT_DIR) return render_template_string(HOME_TEMPLATE, shows=shows, display_names=DISPLAY_NAMES) @app.route("/show/") def show_page(show_name): show_path = os.path.join(ROOT_DIR, show_name) if not os.path.isdir(show_path): abort(404) files = list_audio_files(show_path) banner = find_banner(show_path) return render_template_string(SHOW_TEMPLATE, show_name=show_name, files=files, banner=banner, display_names=DISPLAY_NAMES) @app.route("/stream//") def stream_file(show, filename): safe_path = os.path.join(ROOT_DIR, show) if os.path.isfile(os.path.join(safe_path, filename)): return send_from_directory(safe_path, filename, as_attachment=False) else: abort(404) @app.route("/banner//") def show_banner(show_name, banner_name): show_path = os.path.join(ROOT_DIR, show_name) if os.path.isfile(os.path.join(show_path, banner_name)): return send_from_directory(show_path, banner_name) else: abort(404) # === Start Everything === if __name__ == "__main__": app.run(host="0.0.0.0", port=5020, debug=True)