libpytunes
libpytunes copied to clipboard
Test library playlists reference tracks that don't exist
In this example (from my personal project), we use the included test library to step through all tracks in the library, then go through the playlists and create ordered PlaylistEntry objects. It is assumed that the Playlists section of the XML will only reference tracks that exist in the library.
Is it intentional that the XML Playlists reference non-existent tracks for testing purposes, or should they all be valid, as would be the typical case?
397/402 Aerosmith - Train Kept a Rollin' (Live)
398/402 Dixie Chicks - I Like It
399/402 J.J. Cale & Eric Clapton - Dead End Road
400/402 Gnarls Barkley - Storm Coming
401/402 U2 - City of Blinding Lights
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/shacker/Sites/virtualenvs/pyrex/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/shacker/Sites/virtualenvs/pyrex/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/shacker/Sites/virtualenvs/pyrex/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/shacker/Sites/virtualenvs/pyrex/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/shacker/dev/pyrex/itl/management/commands/sync.py", line 130, in handle
plists = [itl.getPlaylist(p) for p in itl.getPlaylistNames()]
File "/Users/shacker/dev/pyrex/itl/management/commands/sync.py", line 130, in <listcomp>
plists = [itl.getPlaylist(p) for p in itl.getPlaylistNames()]
File "/Users/shacker/dev/libpytunes/libpytunes/Library.py", line 118, in getPlaylist
t = self.songs[id]
KeyError: 63488
I just created a simple new library with a playlist and an ordered playlist from a blank/new account on my Mac, then ran the same command above, and it didn't have this problem. So I think it's a fair assumption that standard library files don't reference nonexistent files in the playlists section. I can post this library as a PR if you like, unless you prefer continuing to work with the current test library.
This is a bug in the library, which was manually edited down from a much larger library.
Is there a test that replicates this issue?
If there is, I can edit the test library so that it is not broken.
If you have sample code for a test, please send it.
Thanks
Nathan
On 25 May 2017, at 08:36, Scot Hacker [email protected] wrote:
I just created a simple new library with a playlist and an ordered playlist from a blan/new account on my Mac, then ran the same command above, and it didn't have this problem. So I think it's a fair assumption that standard library files don't reference nonexistent files in the playlists section. I can post this library as a PR if you like, unless you prefer continuing to work with the current test library.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
I don't have a test, but it would go something like this:
# itl = the Library object
plists = [itl.getPlaylist(p) for p in itl.getPlaylistNames()]
for pl in plists:
for track in pl.tracks
# get track by ID or persistent_id
Aside: Rather than editing a library file manually, I think it's much easier and more realistic to create a new account on your Mac, or create a new library by holding down Option while launching iTunes, then drag a few dozen files in, create playlists (including nested playlists) and let iTunes manage the library creation. Then just commit the resulting XML.