some quality of life improvents

This commit is contained in:
2025-05-10 20:49:01 +02:00
parent 618f2f75a0
commit d85af196b2
2 changed files with 350 additions and 311 deletions
+17 -2
View File
@@ -148,10 +148,25 @@ def play_playlist(playlist_path, play_newest_first=False):
subprocess.run(['ffplay', '-nodisp', '-stats', '-hide_banner', '-autoexit', track_path]) subprocess.run(['ffplay', '-nodisp', '-stats', '-hide_banner', '-autoexit', track_path])
def main(): def main():
play_newest_first = len(sys.argv) > 1 and sys.argv[1].lower() == "n" arg = sys.argv[1] if len(sys.argv) > 1 else None
play_newest_first = False
pre_track_path = None
if play_newest_first: if arg:
if arg.lower() == "n":
play_newest_first = True
print("Newest song will be played first") print("Newest song will be played first")
elif os.path.isfile(os.path.join(playlist_dir, arg)):
pre_track_path = os.path.join(playlist_dir, arg)
print(f"Will play requested song first: {os.path.basename(pre_track_path)}")
else:
print(f"Invalid argument or file not found: {arg}")
if pre_track_path:
track_name = os.path.basename(pre_track_path)
print(f"Now playing: {track_name}")
update_rds(track_name)
subprocess.run(['ffplay', '-nodisp', '-stats', '-hide_banner', '-autoexit', pre_track_path])
while True: while True:
current_hour = get_current_hour() current_hour = get_current_hour()
+34 -10
View File
@@ -57,7 +57,7 @@ def ensure_playlist_dir(day: str) -> str:
os.makedirs(playlist_dir) os.makedirs(playlist_dir)
return playlist_dir return playlist_dir
def calculate_category_percentages(playlists, current_day): def calculate_category_percentages(audio_files, playlists, current_day):
category_counts = {'late_night': 0, 'morning': 0, 'day': 0, 'night': 0} category_counts = {'late_night': 0, 'morning': 0, 'day': 0, 'night': 0}
polskie_counts = {'late_night': 0, 'morning': 0, 'day': 0, 'night': 0} polskie_counts = {'late_night': 0, 'morning': 0, 'day': 0, 'night': 0}
@@ -69,6 +69,12 @@ def calculate_category_percentages(playlists, current_day):
total_count = sum(category_counts.values()) total_count = sum(category_counts.values())
# Calculate unassigned percentage
total_files = len(set().union(*playlists[current_day].values()))
unassigned_count = len(set(audio_files) - set().union(*playlists[current_day].values()))
unassigned_percentage = (unassigned_count / len(audio_files)) * 100 if audio_files else 0
if total_count == 0: if total_count == 0:
return None return None
@@ -81,7 +87,7 @@ def calculate_category_percentages(playlists, current_day):
for category in category_counts for category in category_counts
} }
return percentages, polskie_percentages, (sum(polskie_counts.values())/sum(category_counts.values()))*100 return percentages, polskie_percentages, (sum(polskie_counts.values())/sum(category_counts.values()))*100, unassigned_percentage
def update_playlist_file(day: str, period: str, filepath: str, add: bool): def update_playlist_file(day: str, period: str, filepath: str, add: bool):
playlist_dir = ensure_playlist_dir(day) playlist_dir = ensure_playlist_dir(day)
@@ -200,7 +206,7 @@ def draw_interface(audio_files: list, playlists: dict, selected_idx: int, curren
days = get_days_of_week() days = get_days_of_week()
current_day = days[current_day_idx] current_day = days[current_day_idx]
percentages, polskie_percentages, total_pl = calculate_category_percentages(playlists, current_day) or ({}, {}, 0) percentages, polskie_percentages, total_pl, unassigned = calculate_category_percentages(audio_files, playlists, current_day) or ({}, {}, 0, 0)
available_lines = term_height - 6 available_lines = term_height - 6
start_idx = max(0, min(scroll_offset, len(audio_files) - available_lines)) start_idx = max(0, min(scroll_offset, len(audio_files) - available_lines))
@@ -212,7 +218,8 @@ def draw_interface(audio_files: list, playlists: dict, selected_idx: int, curren
percent = percentages.get(category, 0) percent = percentages.get(category, 0)
polskie_percent = polskie_percentages.get(category, 0) polskie_percent = polskie_percentages.get(category, 0)
category_bar += f"{category[:4].capitalize()}: {percent:.1f}% (P:{polskie_percent:.1f}%) | " category_bar += f"{category[:4].capitalize()}: {percent:.1f}% (P:{polskie_percent:.1f}%) | "
category_bar += f"TP:{total_pl:0.1f}%" category_bar += f"TP:{total_pl:0.1f}% | "
category_bar += f"UA:{unassigned:0.1}%"
if len(category_bar) > term_width - 2: if len(category_bar) > term_width - 2:
category_bar = category_bar[:term_width - 5] + "..." category_bar = category_bar[:term_width - 5] + "..."
@@ -276,7 +283,7 @@ def main():
if not audio_files: if not audio_files:
print("No audio files found. Exiting.") print("No audio files found. Exiting.")
return return 1
days_of_week = get_days_of_week() days_of_week = get_days_of_week()
playlists = load_playlists(days_of_week) playlists = load_playlists(days_of_week)
@@ -345,6 +352,12 @@ def main():
except: except:
pass pass
selected_idx = min(len(audio_files) - 1, selected_idx + visible_lines) selected_idx = min(len(audio_files) - 1, selected_idx + visible_lines)
elif arrow_key == '1':
if get_char() == '~':
selected_idx = 0
elif arrow_key == '4':
if get_char() == '~':
selected_idx = len(audio_files) - 1
elif key == ' ': elif key == ' ':
selected_idx = min(len(audio_files) - 1, selected_idx + visible_lines) selected_idx = min(len(audio_files) - 1, selected_idx + visible_lines)
elif key.lower() == 'm': elif key.lower() == 'm':
@@ -412,10 +425,21 @@ def main():
flash_message = f"File not in any playlist! Add it first." flash_message = f"File not in any playlist! Add it first."
message_timer = 0 message_timer = 0
elif key == 'g': elif key.isupper() and len(key) == 1 and key.isalpha():
selected_idx = 0 target_letter = key.lower()
elif key == 'G': found_idx = -1
selected_idx = len(audio_files) - 1 for i in range(selected_idx + 1, len(audio_files)):
if audio_files[i].lower().startswith(target_letter):
found_idx = i
break
if found_idx == -1:
for i in range(0, selected_idx):
if audio_files[i].lower().startswith(target_letter):
found_idx = i
break
if found_idx != -1:
selected_idx = found_idx
return 0
if __name__ == "__main__": if __name__ == "__main__":
main() exit(main())