Discuss Scratch

kashifau
New to Scratch
15 posts

Scratch API

Is there a way to get the list of IDs of all Scratch projects via Scratch API?
Jonathan50
Scratcher
1000+ posts

Scratch API

No, that would be way to long… Anyway, the project IDs just go sequentially up from 104 to ~198 million, not counting all the deleted projects in between.

Last edited by Jonathan50 (Jan. 19, 2018 04:41:47)

_nix
Scratcher
1000+ posts

Scratch API

Jonathan50 wrote:

No, that would be way to long… Anyway, the project IDs just go sequentially up from 104 to ~198 million, not counting all the deleted projects in between.
Of course, unshared projects are also stored by those IDs, which will just be 404s (if you aren't the creator of that unshared project).

By the way, you can get the total number of projects by using /projects/count/all. (This isn't quite live, but updates fairly frequently.)

art blog – My pronouns are they/them, btw. sparrows one word to the paragraph
kashifau
New to Scratch
15 posts

Scratch API

Thanks. That was helpful. I need to perform analysis on large number of projects so maybe I can generate numbers between 104 to 198 million and then check individual projects.
jokebookservice1
Scratcher
1000+ posts

Scratch API

Slightly relevant thing of mine. It tries random project IDs until it gets a match.
kashifau
New to Scratch
15 posts

Scratch API

jokebookservice1 wrote:

Slightly relevant thing of mine. It tries random project IDs until it gets a match.
Is the code available online?
_nix
Scratcher
1000+ posts

Scratch API

kashifau wrote:

jokebookservice1 wrote:

Slightly relevant thing of mine. It tries random project IDs until it gets a match.
Is the code available online?
Yes, see here: https://github.com/joker314/joker314.github.io/blob/master/RandomProject.html

art blog – My pronouns are they/them, btw. sparrows one word to the paragraph
jokebookservice1
Scratcher
1000+ posts

Scratch API

The bit at the start of the URL looks like "https://cors-anywhere.herokuapp.com/" in the code. This basically just fetches the content under the URL that follows; but it bypasses Same Origin policy, something browsers enforce for security, if that helps. Same origin policy stops my code from taking control over your Scratch account.

I'm going to make some modifications to the code since it's a little outdated

(EDIT: done)

To improve, you could try and hook it up to the statistics api so that the maximum random number is the latest one, and not something which turns inaccurate very quickly.

(EDIT: added more words)

Last edited by jokebookservice1 (Jan. 21, 2018 23:04:19)

kashifau
New to Scratch
15 posts

Scratch API

Great. Thanks!
kashifau
New to Scratch
15 posts

Scratch API

Is there a way to get the project code in Json or any other format ?
Sheep_maker
Scratcher
1000+ posts

Scratch API

kashifau wrote:

Is there a way to get the project code in Json or any other format ?
https://projects.scratch.mit.edu/internalapi/project/<project ID>/get/
gets the project.json of the given project ID.

In it there are md5 hashes of assets such as “8fb3962cfe256cc600587ed3f76f0d59.svg” which you can use to get the assets from
https://cdn.assets.scratch.mit.edu/internalapi/asset/<md5 hash thing>/get/

- Sheep_maker This is a kumquat-free signature. :P
Please don't feel the obligation to post on every single topic you see; eventually you will resort to spam.
Another suggestion has been implemented!
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
kashifau
New to Scratch
15 posts

Scratch API

Sheep_maker wrote:

kashifau wrote:

Is there a way to get the project code in Json or any other format ?
https://projects.scratch.mit.edu/internalapi/project/<project ID>/get/
gets the project.json of the given project ID.

In it there are md5 hashes of assets such as “8fb3962cfe256cc600587ed3f76f0d59.svg” which you can use to get the assets from
https://cdn.assets.scratch.mit.edu/internalapi/asset/<md5 hash thing>/get/
Brilliant. Works for 2.0 projects. Any way around for 1.4 projects?
_nix
Scratcher
1000+ posts

Scratch API

kashifau wrote:

Any way around for 1.4 projects?
1.4 projects are stored as SB files, which are a particular format which isn't particularly easy to work with (it's not a zip or any similar common format). You can get the SB file just by opening the same URL (cdn.assets.scratch.mit.edu/internalapi/asset/MD5/get/); you can use a library like kurt to extract assets/scripts (but not in the SB2 json format, of course).

art blog – My pronouns are they/them, btw. sparrows one word to the paragraph
kashifau
New to Scratch
15 posts

Scratch API

Thanks for the valuable feedback everyone. Cheers.

Last edited by kashifau (Jan. 22, 2018 00:03:04)

kashifau
New to Scratch
15 posts

Scratch API

Is it possible to tell the version of Scratch project (1.4 or 2.0) or can I fetch the extension of the project via API or any other method.
Jonathan50
Scratcher
1000+ posts

Scratch API

kashifau wrote:

Is it possible to tell the version of Scratch project (1.4 or 2.0) or can I fetch the extension of the project via API or any other method.
Fetch the project, if the first byte is “S” it's a Scratch 1.x project, if the first byte is “{” or whitespace then it's a Scratch 2.0 project.

(Btw, if you're planning to make something that makes lots and lots of requests to the Scratch API to gather lots of statistics, you probably shouldn't go ahead with it, without asking a Scratch Team member first.)

Last edited by Jonathan50 (Jan. 23, 2018 04:19:38)

kashifau
New to Scratch
15 posts

Scratch API

Jonathan50 wrote:

kashifau wrote:

Is it possible to tell the version of Scratch project (1.4 or 2.0) or can I fetch the extension of the project via API or any other method.
Fetch the project, if the first byte is “S” it's a Scratch 1.x project, if the first byte is “{” or whitespace then it's a Scratch 2.0 project.

(Btw, if you're planning to make something that makes lots and lots of requests to the Scratch API to gather lots of statistics, you probably shouldn't go ahead with it, without asking a Scratch Team member first.)
Thanks for the tip.

I do intend to make a lots of request. At the moment, I am making only few requests just to analyze few projects but soon will be increasing the number of requests. Is that a problem?
kashifau
New to Scratch
15 posts

Scratch API

_nix wrote:

kashifau wrote:

Any way around for 1.4 projects?
1.4 projects are stored as SB files, which are a particular format which isn't particularly easy to work with (it's not a zip or any similar common format). You can get the SB file just by opening the same URL (cdn.assets.scratch.mit.edu/internalapi/asset/MD5/get/); you can use a library like kurt to extract assets/scripts (but not in the SB2 json format, of course).

Hi. When I download the project file for 1.4 Scratch projects using https://projects.scratch.mit.edu/internalapi/project/<project ID>/get/ the file I get is in some coded format and there is no md5 in it. I have tried using kurt to read that file but it gives an error. Any idea how to do this?
Jonathan50
Scratcher
1000+ posts

Scratch API

kashifau wrote:

Hi. When I download the project file for 1.4 Scratch projects using https://projects.scratch.mit.edu/internalapi/project/<project ID>/get/ the file I get is in some coded format and there is no md5 in it. I have tried using kurt to read that file but it gives an error. Any idea how to do this?
You might need to give it a .sb extension or pass the format “scratch14” to Kurt: http://kurt.readthedocs.io/en/latest/api.html#kurt.Project.load

Edit: It seems like Kurt won't read any projects from Scratch 1.2 or older because of the ScratchV01 header Maybe ask @blob8108.

Last edited by Jonathan50 (Feb. 12, 2018 04:57:37)

kashifau
New to Scratch
15 posts

Scratch API

Is there a way to get the age of the user of the project? (via API or any other way?)

Powered by DjangoBB

Standard | Mobile