blob: 14cd0825876e69c5e3600c23159c29d6ea42f940 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/env python3
# sortashuffle.py
# Shuffles shows but keeps episodes in order.
# USAGE
# 1. Modify the TARGET variable below
# 2. Modify the SOURCES variable below
# 3. Run the script as administrator
import os
import random
# Playlist destination folder
TARGET = "<ENTER TARGET DIR>"
# Shows to include
# MUST be in format "C://Dir1//Dir2"
SOURCES = ["<SOURCE DIR>",
"<SOURCE DIR>"]
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()
|