diff --git a/retribute_api/providers.py b/retribute_api/providers.py index e604501b8d4387fddf0cb97127d0debce69daf33..0df4df9e648fbcb0e852c47308b9cf6f18e124b3 100644 --- a/retribute_api/providers.py +++ b/retribute_api/providers.py @@ -41,7 +41,17 @@ class BasicUsernameInPathProvider(Provider): if not re.match(self.domain_regex, parsed_url.hostname): return - result = re.match(self.username_regex, parsed_url.path) + regexes = ( + self.username_regex + if isinstance(self.username_regex, list) + else [self.username_regex] + ) + result = None + for r in regexes: + + result = re.match(r, parsed_url.path) + if result: + break if not result: return username = result.groups()[0] @@ -121,6 +131,15 @@ class Etsy(BasicUsernameInPathProvider): username_regex = r"^\/(?:[a-zA-Z-_]+/)?shop/([\w\.]+)/?$" +@registry.register +class FLattr(BasicUsernameInPathProvider): + id = "flattr" + label = "Flattr" + url = "https://flattr.com" + domain_regex = r"^(\w+\.)*flattr\.com" + username_regex = [r"^\/profile/([\w\.]+)/?$", r"^\/@([\w\.]+)/?$"] + + @registry.register class BandCamp(BasicUsernameInDomainProvider): id = "bandcamp" diff --git a/tests/search/test_means.py b/tests/search/test_means.py index 75abd946d9c6b90c6318dd690cc6f31a11faa85c..e9537c6ba9ccee61fcbb11eeb02eea17724effa6 100644 --- a/tests/search/test_means.py +++ b/tests/search/test_means.py @@ -31,12 +31,16 @@ from retribute_api.search import means {"provider": "opencollective", "id": "username"}, ), ("https://username.bandcamp.com", {"provider": "bandcamp", "id": "username"}), - ("https://username.bandcamp.com", {"provider": "bandcamp", "id": "username"}), ( "https://username.bandcamp.com/noop", {"provider": "bandcamp", "id": "username"}, ), ("https://patreon.com/username/nope", None), + ("https://flattr.com/@username", {"provider": "flattr", "id": "username"}), + ( + "https://flattr.com/profile/username", + {"provider": "flattr", "id": "username"}, + ), ], ) def test_extract_from_url(input, expected):