Skip to content

Instantly share code, notes, and snippets.

@steph-ben
Last active Sep 25, 2018
Embed
What would you like to do?
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