Created
February 15, 2017 06:55
-
-
Save cuevasclemente/7eb44e7a0ef4ec90d6fb69b7cbb24ea5 to your computer and use it in GitHub Desktop.
Shuffle an m3u playlist`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import sys | |
import random | |
if __name__ == '__main__': | |
old_indices = [] | |
new_indices = [] | |
with open(sys.argv[1]) as f: | |
pl = f.read().split("\n") | |
desired = [] | |
for i in range(1, len(pl[1:]), 2) | |
desired.append("{}\n{}".format(pl[i], pl[i+1])) | |
random.shuffle(desired) | |
split_desired = [] | |
for foo in desired: | |
split_desired.extend(foo.split("\n")) | |
new_list = "\n".join([pl[0]] + split_desired) | |
with open(sys.argv[2], "w") as f: | |
f.write(new_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment