# Copyright © 2024 Noah Vogt # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . from flask import Flask, render_template_string import config as const from input import get_cachefile_content from utils import get_unix_milis from .verify import ongoing_cd_recording_detected, calc_cuesheet_timestamp cd_recording_status_webserver = Flask(__name__) def get_cd_marker_count(active_recording: bool, cachefile_content: list) -> int: if not active_recording: return 0 return int(cachefile_content[1].strip()) def get_cd_count(active_recording: bool, cachefile_content: list) -> int: if not active_recording: return 0 return int(cachefile_content[5].strip()) def get_full_rec_time(active_recording: bool, cachefile_content: list) -> str: if not active_recording: return "00:00" return calc_cuesheet_timestamp( int(cachefile_content[3].strip()), get_unix_milis() )[:5] def get_track_rec_time(active_recording: bool, cachefile_content: list) -> str: if not active_recording: return "00:00" return calc_cuesheet_timestamp( int(cachefile_content[4].strip()), get_unix_milis() )[:5] @cd_recording_status_webserver.route("/") def index(): recording_active = ongoing_cd_recording_detected() cachefile_content = get_cachefile_content( const.CD_RECORD_CACHEFILE, suppress_error=True ) cd_marker_count = get_cd_marker_count(recording_active, cachefile_content) cd_count = get_cd_count(recording_active, cachefile_content) cd_rec_time = get_full_rec_time(recording_active, cachefile_content) track_rec_time = get_track_rec_time(recording_active, cachefile_content) background_color = "green" if recording_active else "grey" html = f""" CD Recording Status

CD Recording Status

Recording is currently {'active' if recording_active else 'not active'}.

{f"CD Count: {cd_count}" if recording_active else '​'}

{f"CD Marker Count: {cd_marker_count}" if recording_active else '​'}

{f"Recording Time: {cd_rec_time} (Track: {track_rec_time})" if recording_active else '​'}

""" return render_template_string(html)