Last active
October 26, 2021 01:15
-
-
Save CRImier/9777606 to your computer and use it in GitHub Desktop.
This script is for exporting your playlist items to a single folder. Save, change two variables to suit your needs and run =) One use case is: you have a music collection and a playlist containing the best songs of this collection, and you want to load only the best songs to your MP3 player with limited space. This also doesn't overwrite files, …
This file contains 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
import os | |
import shutil | |
directory_name = "playlist/" | |
playlist_name = "playlist.m3u" | |
f = open(playlist_name, "r") | |
files = [] | |
for line in f: | |
line = line.strip().strip("\n").strip("\r") | |
if line and not line.startswith("#"): | |
files.append(line) | |
dir_contents = os.listdir(directory_name) | |
for file in files: | |
try: | |
filename = os.path.basename(file) | |
if filename not in dir_contents: | |
shutil.copy(file, directory_name) | |
print filename | |
else: | |
print ".", #File already there | |
except Exception as e: | |
print str(e) |
Hey @mibodhi ! This wasn't needed for me, but you can certainly do this if you change line 14 to for i, file in enumerate(files):
and line 16 to filename = str(i).zfill(3)+"_"+os.path.basename(file)
. Hope this helps! -Arsenijs
Cool! I'll give it a try.
-bodhi
I think line 18 still uses the original name. So we also need to somehow to rename the current file to filename:
shutil.copy(file, directory_name)
-bodhi
Indeed! Add file = os.path.join(os.path.dirname(file), filename)
after line 16.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice script :)
Suggestion: Even better if you can assign a numerical prefix to the mp3 file names (e.g 001, 002,...) to preserve the oder of the song in the playlist.
-bodhi