Skip to content

Instantly share code, notes, and snippets.

@QueenOfSquiggles
Created February 20, 2023 18:36
Show Gist options
  • Save QueenOfSquiggles/1a2066a2aa3c09aa834f5d4167cbcc19 to your computer and use it in GitHub Desktop.
Save QueenOfSquiggles/1a2066a2aa3c09aa834f5d4167cbcc19 to your computer and use it in GitHub Desktop.
A short GDScript (2.0) script to pull all currently available versions of the Godot editor, automatically
extends Control # arbitrary. This could extend literally anything
@onready var http := $HTTPRequest # this could be replaced with a code generated node, but I like having a scene tree in-editor
const DOWNLOAD_REPO := "https://downloads.tuxfamily.org/godotengine/"
var known_versions := []
func _ready() -> void:
http.request_completed.connect(_handle_request)
var err = http.request(DOWNLOAD_REPO)
if err != OK:
push_error("HTTP Request Failed: " + str(err))
func _handle_request(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
if result == OK:
parse_body(body)
func parse_body(body : PackedByteArray) -> void:
var xml := XMLParser.new()
xml.open_buffer(body) # body is the HTML information of the web page. Because the page is simple and HTML is basically XML, this works to pull meaningful information from the website
var err = OK
while err == OK:
err = xml.read()
if xml.get_node_type() != XMLParser.NODE_ELEMENT: # we only care about hyperlink nodes: <a>
continue
var n := xml.get_node_name()
if n == 'a' and xml.get_named_attribute_value_safe("href").contains('.'): # strip non-version links
var link := xml.get_named_attribute_value_safe("href")
if link.begins_with(".."): # skip the parent directory link
continue
known_versions.append(link)
# at this point all known versions are available. Do with that as you will. The links can load the specific version page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment