Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve extract_code_from_instagram_url function #458

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
git+https://github.com/KurimuzonAkuma/pyrogram
tgcrypto==1.2.5
yt-dlp[default]==2024.11.04
yt-dlp[default]==2024.11.18
APScheduler==3.10.4
beautifultable==1.1.0
ffmpeg-python==0.2.0
Expand Down
20 changes: 18 additions & 2 deletions ytdlbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,28 @@ def parse_cookie_file(cookiefile):

def extract_code_from_instagram_url(url):
# Regular expression patterns
patterns = [r"/p/([a-zA-Z0-9_-]+)/", r"/reel/([a-zA-Z0-9_-]+)/"] # Posts # Reels
patterns = [
# Instagram stories highlights
r'/stories/highlights/([a-zA-Z0-9_-]+)/',
# Posts
r"/p/([a-zA-Z0-9_-]+)/",
# Reels
r"/reel/([a-zA-Z0-9_-]+)/",
# TV
r"/tv/([a-zA-Z0-9_-]+)/",
# Threads post (both with @username and without)
r'(?:https?://)?(?:www\.)?(?:threads\.net)(?:/[@\w.]+)?(?:/post)?/([\w-]+)(?:/?\?.*)?$'
]

for pattern in patterns:
match = re.search(pattern, url)
if match:
return match.group(1)
if pattern == patterns[0]: # Check if it's the stories highlights pattern
# Return the URL as it is
return url
else:
# Return the code part (first group)
return match.group(1)

return None

Expand Down
Loading