Skip to content

Commit

Permalink
🐛 fix(yt_tracking_rm): fix t and time
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeris1One committed Oct 31, 2023
1 parent 820c8af commit 87fc9f9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plugins/youtubeTrackingRemover/youtubeTrackingRemover.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ async def on_message(self, message: discord.Message):
for match in matches:
parsed_url = urlparse(match)
query_params = parse_qs(parsed_url.query)
new_match = match

# replace the link with a link with only the video id
if 'v' in query_params:
video_id = query_params['v'][0]
content = content.replace(match, f'https://www.youtube.com/watch?v={video_id}')
new_match = f'https://www.youtube.com/watch?v={video_id}'

# re-add `time` and `t` parameters
if 't' in query_params:
time = query_params['t'][0]
content = content.replace(match, f'{match}&t={time}')
new_match = new_match + f'&t={time}'
elif 'time' in query_params:
time = query_params['time'][0]
content = content.replace(match, f'{match}&time={time}')
new_match = new_match + f'&time={time}'

content = content.replace(match, f'{new_match}')

# check for youtu.be links
regex = r'(https?://(?:www\.)?youtu\.be/[^\s]+)'
Expand All @@ -82,15 +85,17 @@ async def on_message(self, message: discord.Message):
query_params = parse_qs(parsed_url.query)

# remove every parameters
match = match.split('?')[0]
new_match = match.split('?')[0]

# re-add `time` and `t` parameters
if 't' in query_params:
time = query_params['t'][0]
content = content.replace(match, f'{match}?t={time}')
new_match = new_match + f'?t={time}'
elif 'time' in query_params:
time = query_params['time'][0]
content = content.replace(match, f'{match}?time={time}')
new_match = new_match + f'?time={time}'

content = content.replace(match, f'{new_match}')

if content == message.content:
# no need to send a message if it will be the same
Expand Down

0 comments on commit 87fc9f9

Please sign in to comment.