This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-21 16:14:13

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

kurt — Scratch file format Python library

kurt

Scratch project files  <--->  Python  <--->  Scratchblocks code & images

Kurt is a de/compiler for converting to/from a folder structure of scripts and images. You can decompile a project into its parts, edit the scripts as scratchblocks code (the same syntax as forum blocks) in a text editor, and images in an image editor, then recompile!

It's also a Python library for reading/writing Scratch project (.sb) and sprite (.sprite) files. You can load the files, look at their internal structure — including sprites, scripts, variables, images, etc — make changes, and save them again! You can generate Scratch projects from Python code.

Check it out on Github.

---

a post about working with Kurt

I've reached my long-term goal: to be able to decompile my roads game to text/images, compile it again, and have it (mostly) working. Now I can edit projects as text!  big_smile

Screenshot:

http://i.imgur.com/18Pvc.png

---

~Many thanks to nXIII for advice on the format.
Thanks to Bobbybee for inspiration.
smile

Last edited by blob8108 (2012-10-24 13:19:36)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#2 2012-03-21 16:18:24

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

(high-pitched pleas) Could you (greedily) mention that I'm inspiration?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#3 2012-03-21 16:23:27

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

bobbybee wrote:

(high-pitched pleas) Could you (greedily) mention that I'm inspiration?

Happy?  tongue


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#4 2012-03-21 16:24:47

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

bobbybee wrote:

(high-pitched pleas) Could you (greedily) mention that I'm inspiration?

Happy?  tongue

Yeah.  tongue  Now can we do the mailinator team elite process?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#5 2012-03-21 16:40:18

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: kurt — Scratch file format Python library

Yesss! I've been waiting forever for this! Thank you!

Offline

 

#6 2012-03-21 16:42:17

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

Magnie wrote:

Yesss! I've been waiting forever for this! Thank you!

Pleasure  smile  Let me know how you get on!


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7 2012-03-21 16:47:29

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

Magnie wrote:

Yesss! I've been waiting forever for this! Thank you!

Pleasure  smile  Let me know how you get on!

How...is...Magnie...only...on...when...I'm....not...on....?....


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#8 2012-03-21 16:49:52

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Also, you might want to change the file test_files.py: the path has your name in it.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#9 2012-03-21 17:05:41

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

bobbybee wrote:

Also, you might want to change the file test_files.py: the path has your name in it.

That's fine  smile  Thanks, though!

Last edited by blob8108 (2012-03-21 17:05:49)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#10 2012-03-21 17:06:09

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Also, I can't run the tests. Which test should I run?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#11 2012-03-21 17:11:06

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

bobbybee wrote:

Also, I can't run the tests. Which test should I run?

The tests are from when I was making inline & fixed objects parse correctly. It all works now, so they're no longer really necessary; though they might be in future, to check I haven't broken anything.  tongue

You can run them from the root directory by

Code:

from tests import test_objtable

...but as I said, they don't currently work.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#12 2012-03-21 17:12:18

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

What is the helloworld of kurt, then?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#13 2012-03-21 17:13:29

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

bobbybee wrote:

What is the helloworld of kurt, then?

See "Usage" in the readme.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#14 2012-03-21 17:13:47

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Thank you.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#15 2012-03-21 17:20:00

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Annoying Python Interpreter wrote:

macpro-8:blob8108-kurt-51156df *$ python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    project = ScratchProjectFile('tests/game.sb')
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/files.py", line 19, in __init__
    self.load()
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/files.py", line 25, in load
    self._load(bytes)
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/files.py", line 81, in _load
    project = self._construct.parse(bytes)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 126, in parse
    return self.parse_stream(StringIO(data))
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 129, in parse_stream
    return self._parse(stream, AttrDict())
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 522, in _parse
    subobj = sc._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 166, in _parse
    return self.subcon._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/objtable.py", line 280, in _parse
    objtable = self.subcon._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 181, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 181, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 522, in _parse
    subobj = sc._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 166, in _parse
    return self.subcon._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 332, in _parse
    obj.append(self.subcon._parse(stream, context))
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 181, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 181, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 522, in _parse
    subobj = sc._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 700, in _parse
    obj = self.cases.get(key, self.default)._parse(stream, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/core.py", line 181, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/objtable.py", line 48, in _decode
    return cls.from_construct(obj, context)
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/fixed_objects.py", line 20, in from_construct
    return cls.from_value(obj.value)
  File "/Users/*/Downloads/blob8108-kurt-51156df/kurt/fixed_objects.py", line 235, in from_value
    return cls(**dict(value))
  File "/Users/*/Downloads/blob8108-kurt-51156df/construct/lib/container.py", line 41, in __getitem__
    return self.__dict__[name]
KeyError: 0
macpro-8:blob8108-kurt-51156df *$


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#16 2012-03-21 17:37:50

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

That's... interesting.

Turns out you're using Construct version 2.00; it appears I sent you an outdated download link. My apologies. Try thissmile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#17 2012-03-21 17:49:39

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

kay


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#18 2012-03-21 17:51:20

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

It works great now.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#19 2012-03-22 02:56:52

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: kurt — Scratch file format Python library

blob8108 wrote:

I made a Python library for parsing Scratch format project (.sb) and sprite (.sprite) files.

I didn't test it yet if it works but... this is an incredible job! Thanks a lot for investing your time in doing this!

Offline

 

#20 2012-03-22 14:49:55

roijac_test
Scratcher
Registered: 2011-08-31
Posts: 49

Re: kurt — Scratch file format Python library

awesome, just awesome  smile

and you're releasing it under... GPL3? please?
tongue

just want to know if we can use it on M30W  smile

Last edited by roijac_test (2012-03-22 14:50:32)


http://gigabyte.50webs.com/funnyerrormessages/work013.jpg

Offline

 

#21 2012-03-22 17:19:15

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

roijac_test wrote:

awesome, just awesome  smile

and you're releasing it under... GPL3? please?
tongue

just want to know if we can use it on M30W  smile

I haven't actually decided yet  tongue  as permissive as possible, I think -- probably LGPL, or maybe Apache License... what licence would allow you to use it?  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#22 2012-03-22 17:47:53

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

I'd like a GPL...although LGPL might be more appropiate for this particular project. Also, can we talk? (wikispaces...something that might be too ambitious to work)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#23 2012-03-23 11:22:49

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: kurt — Scratch file format Python library

As I'm definitely not a Python guy... after having:
- installed python
- installed costruct

what will I do in order to run the commands that I found in the readme?!?!? Do I have to:

- change to a specific dir? how?
- load kurt? how?
- run... what?

Thanks for your help :-)

Offline

 

#24 2012-03-23 12:17:29

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

s_federici wrote:

As I'm definitely not a Python guy... after having:
- installed python
- installed costruct

what will I do in order to run the commands that I found in the readme?!?!? Do I have to:

- change to a specific dir? how?
- load kurt? how?
- run... what?

Thanks for your help :-)

What platform are you using? You could try copying just the "kurt" folder to Python's "site-packages" directory:
    C:\Python26\Lib\site-packages on Windows;
    On Mac OS X, either /Library/Python/2.6/site-packages
    or /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages;
    /usr/local/lib/python2.6/lib/site-packages or similar on Linux
-- replace 2.6 with the version of Python you're using. (Should be about 2.6 or newer, don't think it works on 3.0)

Then you should be able to run Python/IDLE, and type in the commands from the readme after the interpreter's triple > prompt.  smile

Make sure you supply absolute paths to files (ie. starting with "/" or "C:\"), and it should all work nicely!

Gratuitous screenshot of working example.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#25 2012-03-23 12:38:40

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: kurt — Scratch file format Python library

Thanks a lot. Now I can run it. I got the following error when loading the provided game.sb:

Code:

>>> project = ScratchProjectFile('tests/game.sb')

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    project = ScratchProjectFile('tests/game.sb')
  File "C:\Python27\lib\site-packages\kurt\files.py", line 19, in __init__
    self.load()
  File "C:\Python27\lib\site-packages\kurt\files.py", line 25, in load
    self._load(bytes)
  File "C:\Python27\lib\site-packages\kurt\files.py", line 81, in _load
    project = self._construct.parse(bytes)
  File "C:\Python27\lib\site-packages\construct\core.py", line 181, in parse
    return self.parse_stream(StringIO(data))
  File "C:\Python27\lib\site-packages\construct\core.py", line 191, in parse_stream
    return self._parse(stream, Container())
  File "C:\Python27\lib\site-packages\construct\core.py", line 645, in _parse
    subobj = sc._parse(stream, context)
  File "C:\Python27\lib\site-packages\construct\core.py", line 264, in _parse
    return self.subcon._parse(stream, context)
  File "C:\Python27\lib\site-packages\kurt\objtable.py", line 280, in _parse
    objtable = self.subcon._parse(stream, context)
  File "C:\Python27\lib\site-packages\construct\core.py", line 279, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "C:\Python27\lib\site-packages\construct\core.py", line 279, in _parse
    return self._decode(self.subcon._parse(stream, context), context)
  File "C:\Python27\lib\site-packages\construct\core.py", line 645, in _parse
    subobj = sc._parse(stream, context)
  File "C:\Python27\lib\site-packages\construct\core.py", line 264, in _parse
    return self.subcon._parse(stream, context)
  File "C:\Python27\lib\site-packages\construct\core.py", line 432, in _parse
    raise ArrayError("expected %d, found %d" % (count, c), ex)
ArrayError: ('expected 96, found 18', ArrayError('expected 256, found 5', FieldError(FieldError('expected 2, found 1',),)))

Last edited by s_federici (2012-03-24 02:48:45)

Offline

 

Board footer