Skip to content

Instantly share code, notes, and snippets.

@steph-ben
Last active September 25, 2018 14:30
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 steph-ben/c5e7e5a5817fb450643d6dacfa826432 to your computer and use it in GitHub Desktop.
Save steph-ben/c5e7e5a5817fb450643d6dacfa826432 to your computer and use it in GitHub Desktop.
Put relative path in mp3u music playlists
#!/usr/bin/env python
"""
Put relative path in mp3u music playlists
"""
import os
import shutil
PLAYLIST_BASE_DIR = '/home/cloud/steph/files/Musique/'
SOURCE_BASEPATH = 'C:\\Bench\\cloud\\Musique\\'
DEST_BASEPATH = ''
def mp3_unifier(fp, source_basepath, dest_basepath):
print("Unifying %s ..." % fp)
with open(fp) as fd:
with open(fp+".tmp", "w") as outd:
for line in fd:
if line[0] != '#':
line = line.replace(source_basepath, dest_basepath).replace('\\', '/')
outd.write(line)
#shutil.move(fp+".tmp", fp)
if __name__ == "__main__":
for f in os.listdir(PLAYLIST_BASE_DIR):
fp = os.path.join(PLAYLIST_BASE_DIR, f)
if os.path.isfile(fp) and '.m3u' in fp:
mp3_unifier(fp, SOURCE_BASEPATH, DEST_BASEPATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment