From 38af77ef4dd82ac5ee2ad3473fb77335e1273308 Mon Sep 17 00:00:00 2001 From: Tristan Williams Date: Wed, 19 Mar 2025 14:38:17 -0400 Subject: I should test things before I commit --- sortashuffle.py | 56 ++++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/sortashuffle.py b/sortashuffle.py index 14cd082..aac1e51 100644 --- a/sortashuffle.py +++ b/sortashuffle.py @@ -19,41 +19,21 @@ TARGET = "" SOURCES = ["", ""] -def get_episode_list(): - """Get list of episodes for each show in SOURCES.""" - SHOWLIST = [[f for f in os.listdir(source)] for source in SOURCES] - -def get_weight_list(): - """Determine weights (# of episodes) so shows get spread evenly.""" - WEIGHTLIST = [len(show) for show in SHOWLIST] - -def shuffle(): - """Shuffle shows, randomly selected according to weight.""" - SHUFFLED = [] - while any(SHOWLIST): - selection = random.choices(range(len(SHOWLIST)), weights=WEIGHTLIST, k=1)[0] - SHUFFLED.append(SOURCES[selection] + "//" + SHOWLIST[selection].pop(0)) - WEIGHTLIST[selection] = len(SHOWLIST[selection]) - -def deploy_symlinks(): - """Deploy a symlink for each episode in the playlist.""" - count = 0 - for episode in SHUFFLED: - os.symlink(episode, TARGET + str(count)) - count += 1 - -def deploy_index(): - """Deploy playlist index file.""" - INDEX = open(TARGET + "//" + "_PLAYLIST_INDEX.txt", 'w') - INDEX.write("\n".join(SHUFFLED)) - INDEX.close() - -def main(): - get_episode_list() - get_weight_list() - shuffle() - deploy_symlinks() - deploy_index() - -if __name__=="__main__": - main() +SHOWLIST = [[f for f in os.listdir(source)] for source in SOURCES] + +WEIGHTLIST = [len(show) for show in SHOWLIST] + +SHUFFLED = [] +while any(SHOWLIST): + selection = random.choices(range(len(SHOWLIST)), weights=WEIGHTLIST, k=1)[0] + SHUFFLED.append(SOURCES[selection] + "//" + SHOWLIST[selection].pop(0)) + WEIGHTLIST[selection] = len(SHOWLIST[selection]) + +count = 0 +for episode in SHUFFLED: + os.symlink(episode, TARGET + "//" + str(count)) + count += 1 + +INDEX = open(TARGET + "//" + "_PLAYLIST_INDEX.txt", 'w') +INDEX.write("\n".join(SHUFFLED)) +INDEX.close() -- cgit v1.2.3