1
0

Support Github
All checks were successful
Python Package / Package (push) Has been skipped

This commit is contained in:
Jon Michael Aanes 2024-01-02 16:27:24 +01:00
parent a5a6f5180a
commit ec00b0a656

View File

@ -59,6 +59,8 @@ class SocialSiteId(aenum.Enum):
SOUNDCLOUD_ARTIST = 3040 SOUNDCLOUD_ARTIST = 3040
IGDB_GAME_ID = 5794 IGDB_GAME_ID = 5794
GITHUB_REPOSITORY = 364
def wikidata_property(self, client): def wikidata_property(self, client):
return client.get(WIKIDATA_PROPERTIES[self]) return client.get(WIKIDATA_PROPERTIES[self])
@ -130,6 +132,7 @@ WIKIDATA_PROPERTIES = {
SocialSiteId.COHOST_PROFILE: WikidataInfo(None, 117203288), SocialSiteId.COHOST_PROFILE: WikidataInfo(None, 117203288),
SocialSiteId.SOUNDCLOUD_ARTIST: WikidataInfo(3040, None), SocialSiteId.SOUNDCLOUD_ARTIST: WikidataInfo(3040, None),
SocialSiteId.IGDB_GAME_ID: WikidataInfo(5794, None), SocialSiteId.IGDB_GAME_ID: WikidataInfo(5794, None),
SocialSiteId.GITHUB_REPOSITORY: WikidataInfo(None, 364),
} }
def re_social_subdomain(main_domain): def re_social_subdomain(main_domain):
@ -137,6 +140,7 @@ def re_social_subdomain(main_domain):
return r'^(?:https?:\/\/)?([\w_-]+)\.'+re.escape(main_domain)+r'(\/.*)?$' return r'^(?:https?:\/\/)?([\w_-]+)\.'+re.escape(main_domain)+r'(\/.*)?$'
RE_ID = r'@?([^/]+)' RE_ID = r'@?([^/]+)'
RE_DUAL_ID = r'@?([^/]+/[^/]+)'
RE_ANY_SUBPATH = r'(|\/|\/.*)$' RE_ANY_SUBPATH = r'(|\/|\/.*)$'
def re_social_path(main_domain): def re_social_path(main_domain):
@ -150,7 +154,7 @@ def re_social_path_adv(main_domain, *path):
for p in path: for p in path:
if p != RE_ANY_SUBPATH: if p != RE_ANY_SUBPATH:
l.append(r'\/') l.append(r'\/')
l.append(p if p in {RE_ID, RE_ANY_SUBPATH} else re.escape(p)) l.append(p if p in {RE_ID, RE_DUAL_ID, RE_ANY_SUBPATH} else re.escape(p))
if path[-1] != RE_ANY_SUBPATH: if path[-1] != RE_ANY_SUBPATH:
l.append(r'\/?$') l.append(r'\/?$')
regex = ''.join(l) regex = ''.join(l)
@ -196,7 +200,6 @@ URL_PARSE_DEVIANT_ART_ACCOUNT_2 = re_social_subdomain('deviantart.com')
URL_PARSE_DANBOORU_ARTIST = re_social_path_adv('danbooru.donmai.us', 'artists', RE_ID) URL_PARSE_DANBOORU_ARTIST = re_social_path_adv('danbooru.donmai.us', 'artists', RE_ID)
URL_PARSE_BANDCAMP = re_social_subdomain('bandcamp.com') URL_PARSE_BANDCAMP = re_social_subdomain('bandcamp.com')
URL_PARSE_BLUESKY = re_social_path_adv('bsky.app', 'profile', RE_ID) URL_PARSE_BLUESKY = re_social_path_adv('bsky.app', 'profile', RE_ID)
URL_PARSE_ITCH_IO_DEVELOPER = re_social_subdomain('itch.io')
REGEXES = [ REGEXES = [
# Reddit # Reddit
@ -296,7 +299,7 @@ REGEXES = [
(URL_PARSE_BLUESKY, SocialSiteId.BLUESKY_PROFILE), (URL_PARSE_BLUESKY, SocialSiteId.BLUESKY_PROFILE),
# Itch.io # Itch.io
(URL_PARSE_ITCH_IO_DEVELOPER, SocialSiteId.ITCH_IO_DEVELOPER), (re_social_subdomain('itch.io'), SocialSiteId.ITCH_IO_DEVELOPER),
# Cohost # Cohost
(re_social_path_adv('cohost.org', RE_ID), SocialSiteId.COHOST_PROFILE), (re_social_path_adv('cohost.org', RE_ID), SocialSiteId.COHOST_PROFILE),
@ -306,6 +309,9 @@ REGEXES = [
# IGDB # IGDB
(re_social_path_adv('igdb.com', 'games', RE_ID), SocialSiteId.IGDB_GAME_ID), (re_social_path_adv('igdb.com', 'games', RE_ID), SocialSiteId.IGDB_GAME_ID),
# Github
(re_social_path_adv('github.com', RE_DUAL_ID), SocialSiteId.GITHUB_REPOSITORY),
] ]
WELL_KNOWN_MASTODON_INSTANCES = frozenset({ WELL_KNOWN_MASTODON_INSTANCES = frozenset({