Skip to content

Instantly share code, notes, and snippets.

@alanedwardes
Created April 20, 2024 23:10
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 alanedwardes/465e9d8cb9f295bb2bdbcfdf35084031 to your computer and use it in GitHub Desktop.
Save alanedwardes/465e9d8cb9f295bb2bdbcfdf35084031 to your computer and use it in GitHub Desktop.
Create a simple .m3u file from a folder heirarchy
import os
import sys
import pathlib
if len(sys.argv) < 2:
print("Error - pass the folder(s) you want to index as argument(s)")
exit(1)
directories = sys.argv[1:]
for directory in directories:
playlist = os.path.join(directory, 'playlist.m3u')
print("Using directory", directory)
with open(playlist, "w") as f:
for path in pathlib.Path(directory).rglob('*.*'):
relative_path = os.path.relpath(path, directory)
if not path.suffix in ['.mkv', '.mp4']:
print("Skipping", relative_path)
continue
f.write(relative_path.replace('\\', '/') + '\n')
print("Playlist written", playlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment