Verified Commit 44a56cd5 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Flattr support

parent acfe8f98
......@@ -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"
......
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment