Verified Commit b64e9210 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

More providers

parent 75975ceb
......@@ -20,7 +20,7 @@ registry = Registry()
class Provider(object):
id = None
domains = []
domain_regex = None
username_regex = None
......@@ -28,14 +28,12 @@ class BasicUsernameProvider(Provider):
username_regex = r"^\/([\w\.]+)/?$"
def match_from_url(self, parsed_url):
if not self.domains and not self.username_regex:
if not self.domain_regex and not self.username_regex:
return
if parsed_url.hostname not in self.domains:
if not re.match(self.domain_regex, parsed_url.hostname):
return
compiled = re.compile(self.username_regex)
result = compiled.match(parsed_url.path)
result = re.match(self.username_regex, parsed_url.path)
if not result:
return
username = result.groups()[0]
......@@ -45,16 +43,28 @@ class BasicUsernameProvider(Provider):
@registry.register
class Patreon(BasicUsernameProvider):
id = "patreon"
domains = ["patreon.com"]
domain_regex = r"^(\w+\.)*patreon\.com"
@registry.register
class Paypal(BasicUsernameProvider):
id = "paypal"
domain_regex = r"^(\w+\.)*paypal\.me"
@registry.register
class Tipeee(BasicUsernameProvider):
id = "tipeee"
domain_regex = r"^(\w+\.)*tipeee\.com"
@registry.register
class Liberapay(BasicUsernameProvider):
id = "liberapay"
domains = ["liberapay.com"]
domain_regex = r"^(\w+\.)*liberapay\.com"
@registry.register
class KoFi(BasicUsernameProvider):
id = "ko-fi"
domains = ["ko-fi.com"]
domain_regex = r"^(\w+\.)*ko-fi\.com"
......@@ -6,8 +6,14 @@ from retribute_api.search import means
"input, expected",
[
("https://patreon.com/username", {"provider": "patreon", "id": "username"}),
("https://www.patreon.com/username", {"provider": "patreon", "id": "username"}),
("https://notpatreon.com/username", None),
("https://liberapay.com/username", {"provider": "liberapay", "id": "username"}),
("https://ko-fi.com/username", {"provider": "ko-fi", "id": "username"}),
("https://paypal.me/username", {"provider": "paypal", "id": "username"}),
("https://www.paypal.me/username", {"provider": "paypal", "id": "username"}),
("https://fr.tipeee.com/username", {"provider": "tipeee", "id": "username"}),
("https://tipeee.com/username", {"provider": "tipeee", "id": "username"}),
("https://patreon.com/username/nope", None),
],
)
......
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