1

I'm using Python appscript to write artwork to my iTunes Songs. I have a file stored in .pict format and when I use the normal open and read routines, it reads the content as a string (encoded in utf-8).

imFile = open('/Users/kartikaiyer/temp.pict','r')
data = imFile.read()
it = app('iTunes')
sel = it.current_track.get()
sel.artworks[1].data_.set(data[513:])

Is the code I'm using. it fails with a objct not recognized and I'm guessing its because the set parameter is a utf-8 encoded string, Any ideas as to how I can coerce data to a bytestream and use that as a set parameter. BinAscii module doesn't have the functions I need. Any help would be much appreciated.

  • 1
    Can you post the actual error message / stack and also the line at which it happens ? – mjv Nov 03 '09 at 17:58
  • Is this Python 2 or 3? In 2.anything, data certainly would be a string of bytes (in 3, you'd need `rb`, as somebody's already suggested and you say doesn't work). – Alex Martelli Nov 04 '09 at 00:39
  • I'm using python 2.5.1. Here is a snippet of the error. >>> sel[0].artworks[0].data_.set(test[513:]) Traceback (most recent call last): File "", line 1, in File "build/bdist.macosx-10.5-i386/egg/appscript/reference.py", line 504, in __call__ appscript.reference.CommandError: Command failed: OSERROR: -1731 MESSAGE: Unknown object type. COMMAND: app(u'/Applications/iTunes.app').sources.ID(42).user_playlists.ID(81245).file_tracks.ID(95566).artworks[0].data_.set('\x00\x00\x00\x00\x00\x00@\x00@\x00\x11\x02\xff\x0c\x00\xff\xfe\x00\x00\x00H\x00\x00\x00H\x00\x – Kartik Aiyer Nov 11 '09 at 18:34

1 Answers1

7

Try setting the read mode to binary:

imFile = open('/Users/kartikaiyer/temp.pict','rb')
DeckerDK
  • 81
  • 2