Better handle broken playlist track path

This commit is contained in:
NicoHood 2016-02-04 14:36:58 +01:00
parent f313664a97
commit 92d121330c

View file

@ -364,6 +364,8 @@ class PlaylistHeader(Record):
if playlist["number_of_songs"] > 0: if playlist["number_of_songs"] > 0:
playlistcount += 1 playlistcount += 1
chunks += [construction] chunks += [construction]
else:
print "Error: Playlist does not contain a single track. Skipping playlist."
self["number_of_playlists"] = playlistcount self["number_of_playlists"] = playlistcount
self["total_length"] = 0x14 + (self["number_of_playlists"] * 4) self["total_length"] = 0x14 + (self["number_of_playlists"] * 4)
@ -461,11 +463,15 @@ class Playlist(Record):
chunks = "" chunks = ""
for i in self.listtracks: for i in self.listtracks:
path = self.ipod_to_path(i)
position = -1
try: try:
position = tracks.index(self.ipod_to_path(i)) position = tracks.index(path)
except: except:
print tracks # Print an error if no track was found.
raise # Empty playlists are handeled in the PlaylistHeader class.
print "Error: Could not find track \"" + path + "\"."
print "Maybe its an invalid FAT filesystem name. Please fix your playlist. Skipping track."
if position > -1: if position > -1:
chunks += struct.pack("I", position) chunks += struct.pack("I", position)
self["number_of_songs"] += 1 self["number_of_songs"] += 1