mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-29 15:29:14 +02:00
some updates
This commit is contained in:
+6
-17
@@ -4,32 +4,22 @@ _log_out: log95.TextIO
|
||||
assert _log_out # pyright: ignore[reportUnboundVariable]
|
||||
|
||||
def load_play_counts(file_path: Path) -> dict[str, int]:
|
||||
"""
|
||||
Loads the play counts from the file generated by the play_counter module.
|
||||
"""
|
||||
counts = {}
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
for line in file:
|
||||
if line.strip() == "" or line.startswith(";"):
|
||||
continue
|
||||
if line.strip() == "" or line.startswith(";"): continue
|
||||
try:
|
||||
key, value = line.split(':', 1)
|
||||
counts[key.strip()] = int(value.strip())
|
||||
except ValueError:
|
||||
continue
|
||||
except ValueError: continue
|
||||
return counts
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
except FileNotFoundError: return {}
|
||||
|
||||
class PopularitySorterModule(PlaylistModifierModule):
|
||||
"""
|
||||
A playlist modifier that reorders tracks based on their play history.
|
||||
For every pair of tracks, it gives a 60% probability to schedule the less-played track first.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
self.logger = log95.log95("PopSort", output=_log_out)
|
||||
self.play_counts_file = Path("/home/user/mixes/.playlist/count.txt").resolve()
|
||||
self.play_counts_file = Path("/home/user/mixes/.playlist/count.txt")
|
||||
|
||||
def modify(self, global_args: dict, playlist: list[Track]) -> list[Track]:
|
||||
self.logger.info("Applying popularity-based sorting to the playlist...")
|
||||
@@ -69,12 +59,11 @@ class PopularitySorterModule(PlaylistModifierModule):
|
||||
count1 = play_counts.get(track1.path.as_posix(), 0)
|
||||
count2 = play_counts.get(track2.path.as_posix(), 0)
|
||||
|
||||
if count1 > count2:
|
||||
if count1 > count2:
|
||||
playlist[i], playlist[i+1] = track2, track1
|
||||
|
||||
i += 2
|
||||
|
||||
self.logger.info("Popularity sorting complete.")
|
||||
return playlist
|
||||
|
||||
playlistmod = (PopularitySorterModule(), 2)
|
||||
playlistmod = PopularitySorterModule(), 2
|
||||
Reference in New Issue
Block a user