143 lines
4.2 KiB
GDScript
143 lines
4.2 KiB
GDScript
extends HTMLParser
|
|
class_name FAParser
|
|
|
|
|
|
enum {ERR_ADLT,ERR_ASHL}
|
|
|
|
|
|
func get_sub_ids():
|
|
#get submission ids
|
|
var ids = []
|
|
print("srtar")
|
|
seek(0)
|
|
while read() == 0:
|
|
if get_node_name() == "figure" and get_named_attribute_value_safe("id").begins_with("sid"):
|
|
ids.append(get_named_attribute_value_safe("id").substr(4).to_int())
|
|
#print(get_node_offset())
|
|
return ids
|
|
|
|
|
|
|
|
func get_sub_urls() -> Dictionary:
|
|
#get submission ids
|
|
var ids = {}
|
|
print("getting submission urls")
|
|
seek(0)
|
|
while read() == 0:
|
|
if get_node_name() == "figure" and get_named_attribute_value_safe("id").begins_with("sid"):
|
|
var id = get_named_attribute_value_safe("id").substr(4).to_int()
|
|
get_html_element("img")
|
|
var url = get_named_attribute_value("src").replace("//","https://")
|
|
ids[id] = url
|
|
#print(get_node_offset())
|
|
return ids
|
|
|
|
|
|
func get_sub_desc() -> String:
|
|
# get the description of the loaded submission page
|
|
seek(0)
|
|
get_cssclass("submission-description")
|
|
return read_inner_text_bbcode().strip_edges()
|
|
|
|
|
|
func get_sub_img_url() -> String:
|
|
#get the fullsize url of the loaded submission page
|
|
seek(0)
|
|
get_cssid("submissionImg")
|
|
return add_proto(get_named_attribute_value("src"))
|
|
|
|
|
|
func get_user_watchlist() -> PoolStringArray:
|
|
# gets the watchlist from /watchlist/by/[user] or /watchlist/to/[user]
|
|
# but only the first 1000 (200?). i cant be bothered to make it grab the next page
|
|
# who in their right mind would follow more than 1000 people anyway?
|
|
var users = PoolStringArray()
|
|
print("getting watchlist")
|
|
seek(0)
|
|
#breakpoint
|
|
var loop = true
|
|
while read() == 0:
|
|
if get_named_attribute_value_safe("class").match("*watch-list-items*"):
|
|
print(get_html_element("a"))
|
|
users.append(get_named_attribute_value_safe("href").split("/",false)[1])
|
|
#users.append(read_inner_text())
|
|
prints("found",users.size(),"users")
|
|
return users
|
|
|
|
|
|
func get_sublist_data() -> Dictionary:
|
|
#get submission ids
|
|
var ids = {}
|
|
print("getting submission data")
|
|
seek(0)
|
|
var loop = true
|
|
while read() == 0:
|
|
if get_node_type() != NODE_TEXT and get_node_name() == "figure" and get_named_attribute_value_safe("id").begins_with("sid"):
|
|
var id = get_named_attribute_value_safe("id").substr(4).to_int()
|
|
get_html_element("img")
|
|
var thumb = add_proto(get_named_attribute_value("src"))
|
|
get_html_element("a")
|
|
var url = "https://www.furaffinity.net" + get_named_attribute_value_safe("href")
|
|
var title = get_named_attribute_value_safe("title")
|
|
get_html_element("a")
|
|
var user = get_named_attribute_value_safe("title")
|
|
ids[id] = {"thumb":thumb,"url":url,"title":title,"user":user}
|
|
#print(get_node_offset())
|
|
return ids
|
|
|
|
|
|
func get_sub_download_url() -> String:
|
|
# gets the link that the download button goes to.
|
|
seek(0)
|
|
get_cssclass("download")
|
|
get_html_element("a")
|
|
return add_proto(get_named_attribute_value_safe("href"))
|
|
|
|
|
|
func get_sub_title() -> String:
|
|
seek(0)
|
|
get_cssclass("submission-title")
|
|
get_html_element("p")
|
|
return read_inner_text()
|
|
|
|
|
|
func get_sub_user() -> String:
|
|
seek(0)
|
|
get_cssclass("submission-title")
|
|
get_html_element("strong")
|
|
return read_inner_text()
|
|
|
|
|
|
func get_sub_err() -> String:
|
|
seek(0)
|
|
get_cssclass("notice-message")
|
|
var err_text = read_inner_text()
|
|
if "registered users only" in err_text:
|
|
# hello. if anyone is reading this source code, yes ASHL does in fact
|
|
# stand for "asshole" because i think people who do that bullshit are assholes
|
|
return "[color=red]Error code: ERR_ASHL[/color]" + err_text
|
|
elif "contains Mature" in err_text:
|
|
# this error code is self explanitory. just means its adult content
|
|
# which it cant view without account because FA is a shitty website.
|
|
return "[color=red]Error code: ERR_ADLT[/color]" + err_text
|
|
return err_text
|
|
|
|
|
|
static func add_proto(i:String) -> String:
|
|
#return i.replace("//","https://")
|
|
if not i.empty():
|
|
return "https://"+i.lstrip("/")
|
|
else:
|
|
return ""
|
|
|
|
|
|
static func url(input:String) -> String:
|
|
# makes the FA urls consistant and makes sure all links are https
|
|
var out:String = input.trim_prefix("https://www.furaffinity.net")
|
|
out = input.trim_prefix("http://www.furaffinity.net")
|
|
out = input.trim_prefix("https://furaffinity.net")
|
|
out = input.trim_prefix("http://furaffinity.net")
|
|
if out.begins_with("/"):
|
|
return "https://www.furaffinity.net"+out
|
|
else:
|
|
return input
|