diff --git a/src/mastodon_toot_follower/mastodon_util.py b/src/mastodon_toot_follower/mastodon_util.py index 6fbc466..d1f5ee6 100644 --- a/src/mastodon_toot_follower/mastodon_util.py +++ b/src/mastodon_toot_follower/mastodon_util.py @@ -2,13 +2,31 @@ import re def parse_toot_url(url: str) -> tuple[str, str, str]: + if '/users/' in url and '/statuses' in url: + return parse2(url) + else: + return parse1(url) + + +def parse1(url: str) -> tuple[str, str, str]: """ - :param url: E.g. https://mastodon.instance/@user@another.instance/123456 + :param url: E.g. https://mastodon.instance/@username@another.instance/123456 :return: instance, username, toot_id """ - pattern = re.compile(r'(^https://[^/]+)/([^/]+)/([0-9]+)$') match = pattern.match(url) if match is None: raise ValueError(f'Could not parse toot url: {url}') return match.group(1), match.group(2), match.group(3) + + +def parse2(url: str) -> tuple[str, str, str]: + """ + :param url: E.g. https://mastodon.instance/users/username/statuses/123456 + :return: instance, username, toot_id + """ + pattern = re.compile(r'(^https://[^/]+)/users/([^/]+)/statuses/([0-9]+)$') + match = pattern.match(url) + if match is None: + raise ValueError(f'Could not parse toot url: {url}') + return match.group(1), f'@{match.group(2)}', match.group(3)