Skip to content

Instantly share code, notes, and snippets.

@cuevasclemente
Created February 15, 2017 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuevasclemente/7eb44e7a0ef4ec90d6fb69b7cbb24ea5 to your computer and use it in GitHub Desktop.
Save cuevasclemente/7eb44e7a0ef4ec90d6fb69b7cbb24ea5 to your computer and use it in GitHub Desktop.
Shuffle an m3u playlist`
#!/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