libsaria: Remove old ids from library
If the song was deleted it should be removed. This patch also addse in the Track() class that should have been in the last patch.
This commit is contained in:
parent
a4988a0b28
commit
b1d8ba7653
|
@ -0,0 +1,28 @@
|
|||
# Bryan Schumaker (5 / 21 / 2011)
|
||||
|
||||
import tagpy
|
||||
import datetime
|
||||
|
||||
FileRef = tagpy.FileRef
|
||||
timedelta = datetime.timedelta
|
||||
|
||||
class Track:
|
||||
def __init__(self, filepath):
|
||||
ref = FileRef(filepath)
|
||||
tags = ref.tag()
|
||||
audio = ref.audioProperties()
|
||||
|
||||
self.artist = tags.artist or u"Unknown Artist"
|
||||
self.album = tags.album or u"Unknown Album"
|
||||
self.title = tags.title or u"Unknown Title"
|
||||
self.track = tags.track
|
||||
self.genre = tags.genre
|
||||
self.year = tags.year
|
||||
self.seconds = audio.length
|
||||
self.filepath = filepath
|
||||
|
||||
lenstr = "%s" % timedelta(seconds=self.seconds)
|
||||
if lenstr[:2] == "0:":
|
||||
self.lenstr = lenstr[2:]
|
||||
else:
|
||||
self.lenstr = lenstr
|
|
@ -23,6 +23,11 @@ def scan_path(path):
|
|||
file_map[song_id(file)] = file
|
||||
return file_map
|
||||
|
||||
def rm_old_ids(old_ids, new_ids, tracks):
|
||||
to_remove = old_ids - new_ids
|
||||
for id in to_remove:
|
||||
del tracks[id]
|
||||
|
||||
def add_new_ids(old_ids, new_ids, tracks, file_map):
|
||||
to_add = new_ids - old_ids
|
||||
for id in to_add:
|
||||
|
@ -37,6 +42,7 @@ def update_path(path, tracks):
|
|||
old_ids = set(tracks.keys())
|
||||
new_ids = set(file_map.keys())
|
||||
|
||||
rm_old_ids(old_ids, new_ids, tracks)
|
||||
add_new_ids(old_ids, new_ids, tracks, file_map)
|
||||
|
||||
def update():
|
||||
|
|
Loading…
Reference in New Issue