def get_filename(new_tags): filename = new_tags['path'] + '\\' + \ new_tags['artist'] + '\\' + \ new_tags['year'] + '\\' + \ new_tags['album'] + '\\' + \ new_tags['album'] + '_' + \ new_tags['year'] + '_' +\ new_tags['month'] + '_' +\ new_tags['day'] + '.mp3' index = 1 while os.path.exists(filename): tags = Mp3Tag.getTags(filename) if new_tags['artist'] != tags['artist'][0] \ or new_tags['album'] != tags['album'][0] \ or new_tags['title'] != tags['title'][0]: # if file with this name already exists but it's not this file than # create new file name filename = os.path.splitext( filename)[0] + '_' + str(index) + os.path.splitext(filename)[1] index += 1 else: # if file with this name exists and it's this file than return # current file name break return filename