Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » Where does Scratch get a project's SB3 file from?
- lolecksdeehaha
-
Scratcher
1000+ posts
Where does Scratch get a project's SB3 file from?
I'm wondering, because I don't know. Simple enough.
- Strajox
-
Scratcher
100+ posts
Where does Scratch get a project's SB3 file from?
What do you mean? When saving, it already has the file, you just download it.
- lolecksdeehaha
-
Scratcher
1000+ posts
Where does Scratch get a project's SB3 file from?
What do you mean? When saving, it already has the file, you just download it.For API reasons. Like api.scratch.mit.edu/projects/1, it doesn't show the SB3 file. Where does Scratch get it from?
- Flowermanvista
-
Scratcher
1000+ posts
Where does Scratch get a project's SB3 file from?
Scratch doesn't actually store SB3 files on the servers.
Before I can go any further with this explanation, I need to go over the structure of a Scratch project: a project consists of a project.json file, which stores all of the code and information about everything else in the project, such as all of the assets. The assets are stored separately as individual costume or sound files.
When you load a project, Scratch first downloads the project.json from projects.scratch.mit.edu. It then reads through the JSON file and enumerates every asset in the project. It will then individually download each one of those assets from assets.scratch.mit.edu.
An SB3 file is only created when you save a project to your computer - when you do that, the client (not the server) bundles the JSON file and all of the assets into a ZIP file, which it then saves as an SB3 file.
The process for downloading Scratch 2 projects is virtually identical to the one for Scratch 3 projects*, but Scratch 1.x projects are instead loaded by sending a request to projects.scratch.mit.edu, which will return the entire project in the native Scratch 1.x format (which is not a ZIP file).
*Edit: It seems that when a project is uploaded directly from the Scratch 2.0 offline editor, it is stored directly on the server in the .sb2 format (which is just a ZIP file) and you will get it in its entirety when you download it from projects.scratch.mit.edu. This is actually pretty rare, however - or, at least it's pretty rare nowadays (I ran a quick test, and out of 10,000 pseudo-randomly chosen projects, only 15 were like this).
Before I can go any further with this explanation, I need to go over the structure of a Scratch project: a project consists of a project.json file, which stores all of the code and information about everything else in the project, such as all of the assets. The assets are stored separately as individual costume or sound files.
When you load a project, Scratch first downloads the project.json from projects.scratch.mit.edu. It then reads through the JSON file and enumerates every asset in the project. It will then individually download each one of those assets from assets.scratch.mit.edu.
An SB3 file is only created when you save a project to your computer - when you do that, the client (not the server) bundles the JSON file and all of the assets into a ZIP file, which it then saves as an SB3 file.
The process for downloading Scratch 2 projects is virtually identical to the one for Scratch 3 projects*, but Scratch 1.x projects are instead loaded by sending a request to projects.scratch.mit.edu, which will return the entire project in the native Scratch 1.x format (which is not a ZIP file).
*Edit: It seems that when a project is uploaded directly from the Scratch 2.0 offline editor, it is stored directly on the server in the .sb2 format (which is just a ZIP file) and you will get it in its entirety when you download it from projects.scratch.mit.edu. This is actually pretty rare, however - or, at least it's pretty rare nowadays (I ran a quick test, and out of 10,000 pseudo-randomly chosen projects, only 15 were like this).
Last edited by Flowermanvista (Jan. 13, 2022 20:38:58)
- Beasted1010
-
New Scratcher
4 posts
Where does Scratch get a project's SB3 file from?
Scratch doesn't actually store SB3 files on the servers.
Before I can go any further with this explanation, I need to go over the structure of a Scratch project: a project consists of a project.json file, which stores all of the code and information about everything else in the project, such as all of the assets. The assets are stored separately as individual costume or sound files.
When you load a project, Scratch first downloads the project.json from projects.scratch.mit.edu. It then reads through the JSON file and enumerates every asset in the project. It will then individually download each one of those assets from assets.scratch.mit.edu.
An SB3 file is only created when you save a project to your computer - when you do that, the client (not the server) bundles the JSON file and all of the assets into a ZIP file, which it then saves as an SB3 file.
The process for downloading Scratch 2 projects is virtually identical to the one for Scratch 3 projects*, but Scratch 1.x projects are instead loaded by sending a request to projects.scratch.mit.edu, which will return the entire project in the native Scratch 1.x format (which is not a ZIP file).
*Edit: It seems that when a project is uploaded directly from the Scratch 2.0 offline editor, it is stored directly on the server in the .sb2 format (which is just a ZIP file) and you will get it in its entirety when you download it from projects.scratch.mit.edu. This is actually pretty rare, however - or, at least it's pretty rare nowadays (I ran a quick test, and out of 10,000 pseudo-randomly chosen projects, only 15 were like this).
Great explanation, thank you!
I am still confused how I can get the Scratch Project JSON (representing all the Blocks used, Sprites and their positioning, Backgrounds, Audio, etc). I believe a lot of those will be through the associated Assets.
But, when I try `https://projects.scratch.mit.edu/<project_id>` I get a `403 missing` error.
Project ID being used was both a public Project (from the Scratch home page), and also tried my own Project.
I'm using Postman to make the Request.
2nd.
Is this approach fool-proof? In other words, will it work despite how the Scratch Project was created and when? You mentioned Versions, making me wonder if newer Projects won't work the same via this Endpoint?
I'm mostly interested in Projects created TODAY (as in, in real-time, now, which is the Projects I want to retrieve the JSON for).
Please share any official documentation going over things like Authentication and proper URL formatting (Query Params, Headers, etc.)
Thoughts?
Thank you!
Last edited by Beasted1010 (July 9, 2023 01:40:49)
- mrsrec
-
Scratcher
500+ posts
Where does Scratch get a project's SB3 file from?
That post is outdated. To get the project, there are now two steps.
Firstly, go to https://api.scratch.mit.edu/projects/<id> and get the “project_token” value.
Then go to https://projects.scratch.mit.edu/<id>?token=<token> with <token> being the project token from before.
If the project was made via an offline editor, it will download the entire project. If it was made online, it will return only the project's json, and assets must be retrieveed seperately
Firstly, go to https://api.scratch.mit.edu/projects/<id> and get the “project_token” value.
Then go to https://projects.scratch.mit.edu/<id>?token=<token> with <token> being the project token from before.
If the project was made via an offline editor, it will download the entire project. If it was made online, it will return only the project's json, and assets must be retrieveed seperately
Last edited by mrsrec (Aug. 9, 2024 12:54:06)
- ilikecereal1
-
Scratcher
100+ posts
Where does Scratch get a project's SB3 file from?
That Post Is Outdated. To Get The Project Now There Are Two Steps.Please Don’t Talk Like This. It’s annoying and someone necroposted.
Firstly, Go To https://api.scratch.mit.edu/projects/<id> And Get The “project_token” Value.
Then Go To https://projects.scratch.mit.edu/<id>?token=<token> with <token> Being The Project Token From Before.
If The Project Was Made Via An Offline Editor, It Will Download The Entire Project. If It Was Made Online, It Will Return Only The Project's JSON, And Assets Must Be Retrieveed Seperately
- mrsrec
-
Scratcher
500+ posts
Where does Scratch get a project's SB3 file from?
Please Don’t Talk Like This. It’s annoying and someone necroposted.Yes, that's why I said it was outdated. I wanted to answer their question and provide new, more up-to-date info
Last edited by mrsrec (Aug. 9, 2024 12:53:02)
- Discussion Forums
- » Questions about Scratch
-
» Where does Scratch get a project's SB3 file from?