libpytunes
libpytunes copied to clipboard
Feature request: option to create Library from file stream, instead of XML filename
Hello! I have a few use cases where I'm loading iTunes libraries from sources other than an XML file on disk (for example, from a compressed archive or over a network). Previously, this was trivially possible, since Library.__init__()
took an open file-like object as input to read XML from With the recent change to replace the obsolete readPlist
function (26b3fdf69fa6c6570acf39aec9b07d953e448f0a), Library.__init__()
now expects itunesxml
to be a filename, since it calls open(itunesxml, 'rb') as f
internally.
Would it be possible to restore the original behavior, perhaps intelligently detecting whether itunesxml
is a filename or a file-like object? Something like:
if os.path.isfile(itunesxml):
# itunesxml is a filename, and must be opened
with open(itunesxml, 'rb') as f:
self.il = plistlib.load(f)
else:
# itunesxml is a file-like object and can be loaded directly
self.il = plistlib.load(f)