1
0
mirror of https://github.com/bspeice/Melodia synced 2024-12-25 08:08:13 -05:00

Fix a bug where scanning would add the same file many times

This commit is contained in:
Bradlee Speice 2013-01-10 10:11:50 -05:00
parent 870efac03f
commit 944593be94

View File

@ -66,11 +66,14 @@ class Archive (models.Model):
if re.match(regex, filename):
#Make sure that `filename` is in the database
try:
self.songs.get(url = filename)
rel_url = os.path.join(dirname, filename)
full_url = os.path.abspath(rel_url)
self.songs.get(url = full_url)
except ObjectDoesNotExist, e:
#Song needs to be added to database
full_url = os.path.join(dirname, filename)
rel_url = os.path.join(dirname, filename)
full_url = os.path.abspath(rel_url)
new_song = Song(url = full_url)
new_song.save()
self.songs.add(new_song)
@ -133,7 +136,7 @@ class Archive (models.Model):
Recognized escape characters:
%a - Artist Name %A - Album Name
%d - Disc Number %e - Number of discs
%f - Current Filename (no extension) %g - Current Filename (with extension)
%f - Current Filename (with extension) %g - Current Filename (no extension)
%n - Track Number %o - Number of tracks on disc
%y - Album year
@ -153,13 +156,13 @@ class Archive (models.Model):
new_location = format_string.replace("%a", song.artist)\
.replace("%A", song.album)\
.replace("%d", song.disc_number)\
.replace("%e", song.disc_total)\
.replace("%d", str(song.disc_number))\
.replace("%e", str(song.disc_total))\
.replace("%f", _current_filename)\
.replace("%g", _current_filename_no_extension)\
.replace("%n", song.track_number)\
.replace("%o", song.track_total)\
.replace("%y", _release_year)
.replace("%n", str(song.track_number))\
.replace("%o", str(song.track_total))\
.replace("%y", str(_release_year))
new_url = os.path.join(self.root_folder, new_location)