mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-31 08:19:16 +02:00
some quality of life improvents
This commit is contained in:
+17
-2
@@ -148,10 +148,25 @@ def play_playlist(playlist_path, play_newest_first=False):
|
||||
subprocess.run(['ffplay', '-nodisp', '-stats', '-hide_banner', '-autoexit', track_path])
|
||||
|
||||
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")
|
||||
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:
|
||||
current_hour = get_current_hour()
|
||||
|
||||
+34
-10
@@ -57,7 +57,7 @@ def ensure_playlist_dir(day: str) -> str:
|
||||
os.makedirs(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}
|
||||
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())
|
||||
|
||||
# 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:
|
||||
return None
|
||||
|
||||
@@ -81,7 +87,7 @@ def calculate_category_percentages(playlists, current_day):
|
||||
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):
|
||||
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()
|
||||
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
|
||||
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)
|
||||
polskie_percent = polskie_percentages.get(category, 0)
|
||||
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:
|
||||
category_bar = category_bar[:term_width - 5] + "..."
|
||||
@@ -276,7 +283,7 @@ def main():
|
||||
|
||||
if not audio_files:
|
||||
print("No audio files found. Exiting.")
|
||||
return
|
||||
return 1
|
||||
|
||||
days_of_week = get_days_of_week()
|
||||
playlists = load_playlists(days_of_week)
|
||||
@@ -345,6 +352,12 @@ def main():
|
||||
except:
|
||||
pass
|
||||
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 == ' ':
|
||||
selected_idx = min(len(audio_files) - 1, selected_idx + visible_lines)
|
||||
elif key.lower() == 'm':
|
||||
@@ -412,10 +425,21 @@ def main():
|
||||
flash_message = f"File not in any playlist! Add it first."
|
||||
message_timer = 0
|
||||
|
||||
elif key == 'g':
|
||||
selected_idx = 0
|
||||
elif key == 'G':
|
||||
selected_idx = len(audio_files) - 1
|
||||
elif key.isupper() and len(key) == 1 and key.isalpha():
|
||||
target_letter = key.lower()
|
||||
found_idx = -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__":
|
||||
main()
|
||||
exit(main())
|
||||
|
||||
Reference in New Issue
Block a user