[Pythonmac-SIG] Reading iPod files

Dinu Gherman gherman@darwin.in-berlin.de
Thu, 11 Jul 2002 14:06:57 +0200 (CEST)


This message is in MIME format.

---MOQ10263892175aad7b8e3211e9f316ac342ac38df611
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Jack Jansen <Jack.Jansen@oratrix.com>:

> Dinu,
> depending on how much work you want to put into this it might 
> make a very nice demo of the capabilities of Python. I'm 
> thinking of something like a lowlevel module that allows access 
> to the database, and a couple of programs: at least a command 
> line program and a GUI program, possibly a GUI program both with 
> Carbon and one with Cocoa, maybe even a Scripting Addition that 
> opens up the files to AppleScript, or [Help! Help! He's getting 
> carried away!!] a CGI script that makes the contents of your 
> iPod available on a webpage, that sort of things.

That would be simple enough, even accessing the files
directly on an iPod attached to a networked machine!
But that sounds *very* much like some folks will more
than not like this...

I don't know how much more time I'll put in. A Cocoa i/f
is doable, but I have no clue about Carbon and certain-
ly won't take courses to learn it... ;-) More or less 
the same with AppleScript.

> Hmm, [talk about getting carried away...], if the API to the 
> lowlevel module is reasonably clean it might also be possible to 
> write an alternative lowlevel module that would give the same 
> access to your iTunes playlists. That would really be a very 
> nice demo of the powers of Python...

The API is dead-simple. I'm attaching my test suite as
a proof! ;-)

> But: by all means makes this available, even if the rant above 
> doesn't have you jumping up and down with excitement:-)

It does! ;-)

Dinu

---MOQ10263892175aad7b8e3211e9f316ac342ac38df611
Content-Type: application/octet-stream; name="test.py"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.py"

IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgppbXBvcnQgc3RyaW5nLCBzeXMsIG9zLCB1bml0dGVzdCwg
cmFuZG9tCgpmcm9tIGlwb2RsaWIgaW1wb3J0IGxvY2F0ZWlQb2RWb2x1bWUsIGxvY2F0ZWlQb2Rp
VHVuZXNEQgpmcm9tIGlwb2RsaWIgaW1wb3J0IERCLCBTb25nCgoKCgpjbGFzcyBJUG9kQWNjZXNz
VGVzdHModW5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W5hdGlvbiBmb2xkZXIgaGllcmFyY2h5LiIKCiAgICAgICAgZGIgPSBE
QignaVR1bmVzREInKS5yZWFkKCkKICAgICAgICBkYi5jb3B5RmlsZXNUcmVlKCdzb25ncy8nLCAo
KCdhcnRpc3QnLCAnQXN0b3IuKicpLCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAoJ3RpdGxlJywgJ0EuKicpKSkKCgogICAgZGVmIHRlc3RDb3B5TW9yZU5lc3RlZFRyZWUoc2Vs
Zik6CiAgICAgICAgIlRlc3QgY29weWluZyBpUG9kIG11c2ljIGZpbGVzIHRvIGRlc3RpbmF0aW9u
IGZvbGRlciBoaWVyYXJjaHkuIgoKICAgICAgICBkYiA9IERCKCdpVHVuZXNEQicpLnJlYWQoKQog
ICAgICAgIGRiLmNvcHlGaWxlc1RyZWUoJ3NvbmdzLycsICgoJ2FsYnVtJywgJ0EuKicpLCAKICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCdhcnRpc3QnLCAnLionKSwKICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCd0aXRsZScsICdbQS1NXS4qJykpICkKCgog
ICAgZGVmIF90ZXN0V3JpdGVYbWwoc2VsZik6CiAgICAgICAgIlRlc3QgY29udmVydGluZyBzb25n
cyB0byBYTUwuIgoKICAgICAgICBkYiA9IERCKCdpVHVuZXNEQicpLnJlYWQoKQogICAgICAgIHNv
bmdzID0gZGIuZ2V0U29uZ3MoKCgnYXJ0aXN0JywgJ0FzdG9yLionKSwgCiAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgKCdhbGJ1bScsICdTdSonKSkpCiAgICAgICAgZGIud3JpdGVUb1htbCgn
c29uZ3Mvc29uZ3MueG1sJywgc29uZ3MpCgoKCgpjbGFzcyBMb2NhbERiQWNjZXNzVGVzdHModW5p
dHRlc3QuVGVzdENhc2UpOgogICAgIlRlc3RzIG9uIGEgbG9jYWwgY29weSBvZiBhbiBpUG9kJ3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