Skip to content

Commit c6c890f

Browse files
committed
➕ twitter: shorten generated urls while still preserving domain
1 parent 7588d87 commit c6c890f

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/websites.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def get_patched_url(self, domain, subdomain='', post_path_segments='') -> str:
260260
:param post_path_segments: The additional path segments to append to the URL
261261
:return: The patched URL as a string
262262
"""
263-
patched_url = self.match.expand(self.repl.format(
263+
repl = self.repl.replace(r'\g<author>', 'i')
264+
patched_url = self.match.expand(repl.format(
264265
domain=subdomain + domain,
265266
post_path_segments=post_path_segments
266267
))
@@ -387,6 +388,23 @@ class TwitterLink(GenericWebsiteLink):
387388
"/:username/status/:id/:media_type(photo|video)/:media_id": None,
388389
})
389390

391+
@call_if_valid
392+
def get_patched_url(self, domain, subdomain='', post_path_segments='', replace_author: bool = True) -> str:
393+
repl = self.repl.replace(r'\g<username>', 'i') if replace_author else self.repl
394+
patched_url = self.match.expand(repl.format(
395+
domain=subdomain + domain,
396+
post_path_segments=post_path_segments
397+
))
398+
return patched_url
399+
400+
@call_if_valid
401+
async def get_author_url(self) -> tuple[str | None, str | None]:
402+
if not ('username' in self.match.groupdict() and self.match['username']):
403+
return None, None
404+
username = self.match["username"]
405+
user_link = "https://" + self.match['domain'] + '/' + username
406+
return user_link, username
407+
390408

391409
class InstagramLink(GenericWebsiteLink):
392410
"""Instagram website."""

0 commit comments

Comments
 (0)