Allow us to parse Pixelfed URLs

fixes #30
This commit is contained in:
nanos 2023-03-31 07:51:18 +01:00
parent 44f15de367
commit 0c87cd6727

View file

@ -478,6 +478,10 @@ def parse_user_url(url):
if match is not None:
return match
match = parse_pixelfed_profile_url(url)
if match is not None:
return match
log(f"Error parsing Profile URL {url}")
return None
@ -493,6 +497,11 @@ def parse_url(url, parsed_urls):
if match is not None:
parsed_urls[url] = match
if url not in parsed_urls:
match = parse_pixelfed_url(url)
if match is not None:
parsed_urls[url] = match
if url not in parsed_urls:
log(f"Error parsing toot URL {url}")
parsed_urls[url] = None
@ -540,6 +549,22 @@ def parse_pleroma_profile_url(url):
return (match.group("server"), match.group("username"))
return None
def parse_pixelfed_url(url):
"""parse a Pixelfed URL and return the server and ID"""
match = re.match(
r"https://(?P<server>.*)/p/(?P<username>.*)/(?P<toot_id>.*)", url
)
if match is not None:
return (match.group("server"), match.group("toot_id"))
return None
def parse_pixelfed_profile_url(url):
"""parse a Pixelfed Profile URL and return the server and username"""
match = re.match(r"https://(?P<server>.*)/(?P<username>.*)", url)
if match is not None:
return (match.group("server"), match.group("username"))
return None
def get_redirect_url(url):
"""get the URL given URL redirects to"""