Last active
September 25, 2018 14:30
-
-
Save steph-ben/c5e7e5a5817fb450643d6dacfa826432 to your computer and use it in GitHub Desktop.
Put relative path in mp3u music playlists
This file contains hidden or 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
#!/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