#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on tues september 10 10:00:00 2019

@author: georges Evesque
prog to include new song files in the raspitone song list

add song to playlist ,secure process in order t avoid problems in file
new song files must be in the directory "Music" :
directory name is the artist name 
"""
import os
import unicodedata
f=open("/home/pi/Documents/list.txt","w+")
for root, dirs, files in os.walk(dir):        
    for name in files:    
        texte=root+'/'+name
        flg_mod=0
        song=texte.replace("/home/pi/Music/","")
        song=unicode(song,"utf-8")
        song=unicodedata.normalize('NFD',song).encode('ascii','ignore')
        if (song.find("_._")!= -1):
            song=song.split ("_._") [1]
            flg_mod=1
        if (song.find("_-_")!= -1):
            song=song.split ("_-_") [1]
            flg_mod=1
        if (song.find(" ")>0):           
            song=song.replace(" ","_")
            flg_mod=1
        if (song.find(",")>0):           
            song=song.replace(",","_")
            flg_mod=1
        if (song.find("'")>0):           
            song=song.replace("'","_")
            flg_mod=1
        if (song.find("-")>0):           
            song=song.replace("-","_")
            flg_mod=1
        if (flg_mod==1):
            song=song.capitalize()
            os.rename (texte,dir+"/"+song)
        f.write(song+"\r\n")
f.close()