summaryrefslogtreecommitdiff
path: root/sortashuffle.py
blob: bcd93739d831171c87736324bdc9872021319798 (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
#!/usr/bin/env python3

# sortashuffle.py
# Shuffles shows but keeps episodes in order.

# USAGE
# 0. Copy this script to the playlist folder
# 1. Modify the TARGET variable below
# 2. Modify the SOURCES variable below
# 3. Run the script as administrator
#
# To add/remove shows or regenerate playlist,
# delete everything in TARGET (except this script)
# and re-run the script.

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>"]

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()