CMUS Playlist Exporter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.7 KiB

#usage python3 [filepath]/ --playlistsPath [.../.config/cmus/playlists]
import os;
from shutil import copyfile
import urllib.parse;
import argparse
# 1. Parse arguments
parser = argparse.ArgumentParser(description='CMUS Playlist Exporter')
parser.add_argument('--playlistsPath', dest='playlistsPath', help='The cmus playlists path (usually located in .config/cmus/playlists).', default='', action='store');
args = parser.parse_args();
def CheckIfItemIsDuplicate(index,pl_item,pl_array):
result = False;
for i in range(0,len(pl_array)):
if pl_item == pl_array[i] and index > i:
result = True;
return result;
def ExportPlaylist(playlistname,playlistURL):
print('Exporting playlist ('+playlistname+')');
m3uString = '#EXTM3U\n';
file = open(playlistURL,'r');
playlist_array = [];
for line in file:
for i in range(0,len(playlist_array)):
is_duplicate = CheckIfItemIsDuplicate(i,playlist_array[i],playlist_array);
filepatharray = playlist_array[i].split('/');
filename = filepatharray[len(filepatharray)-1];
if is_duplicate == False:
dur_seconds = '';
artist = '';
song = '';
print('Exporting item ('+filename+')');
m3uString = m3uString+'#EXTINF:'+dur_seconds+','+artist+' - '+song+'\n'+urllib.parse.quote(filename)+'\n';
print('Skipping because it is duplicate ('+filename+')');
with open(localDirectory+'/exported/'+playlistname+'.m3u','w') as pl_file:
print('Running CMUS Playlist Exporter...');
if args.playlistsPath == '':
playlistsPath = input('PlaylistPath not set. Please drag the local cmus playlist directory to your terminal and press enter.').replace(' ','');
print('Thank you!');
playlistsPath = args.playlistsPath;
print('PlaylistsPath: ',playlistsPath);
localDirectory = os.path.dirname(os.path.abspath(__file__));
print('Loading playlists...');
playlists = [n for n in os.listdir(playlistsPath) if not n.startswith(".")]
include_all = input('Du you want to export all ('+str(len(playlists))+') playlists? (y/n) ');
for i in range(0,len(playlists)):
if include_all == 'y':
print('Exporting '+str(playlists[i])+'...');
include_this = input('Do you want to export the playlist: '+str(playlists[i])+'? (y/n) ');
if include_this == 'y':
print('Skipping list...');
print('END OF LINE.');