Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,29 +4,16 @@ import re
|
|
| 4 |
|
| 5 |
def extract_shortcode(url):
|
| 6 |
"""Extract Instagram shortcode from various URL formats"""
|
| 7 |
-
# Remove any trailing parameters and clean URL
|
| 8 |
-
clean_url = url.split('?')[0].strip()
|
| 9 |
-
|
| 10 |
patterns = [
|
| 11 |
-
|
| 12 |
-
r'instagram\.com/
|
| 13 |
-
r'instagram\.com/
|
| 14 |
-
r'instagram\.com/tv/([A-Za-z0-9_-]+)',
|
| 15 |
-
# With username in path
|
| 16 |
-
r'instagram\.com/[^/]+/p/([A-Za-z0-9_-]+)',
|
| 17 |
-
r'instagram\.com/[^/]+/reel/([A-Za-z0-9_-]+)',
|
| 18 |
-
r'instagram\.com/[^/]+/tv/([A-Za-z0-9_-]+)',
|
| 19 |
-
# Stories format (though less common for audio)
|
| 20 |
-
r'instagram\.com/stories/[^/]+/([A-Za-z0-9_-]+)',
|
| 21 |
]
|
| 22 |
|
| 23 |
for pattern in patterns:
|
| 24 |
-
match = re.search(pattern,
|
| 25 |
if match:
|
| 26 |
return match.group(1)
|
| 27 |
-
|
| 28 |
-
# Debug: print the URL structure if no match found
|
| 29 |
-
print(f"No shortcode found in URL: {clean_url}")
|
| 30 |
return None
|
| 31 |
|
| 32 |
def download_reel_audio(url, output_folder="downloads"):
|
|
|
|
| 4 |
|
| 5 |
def extract_shortcode(url):
|
| 6 |
"""Extract Instagram shortcode from various URL formats"""
|
|
|
|
|
|
|
|
|
|
| 7 |
patterns = [
|
| 8 |
+
r'instagram\.com/p/([^/?]+)',
|
| 9 |
+
r'instagram\.com/reel/([^/?]+)',
|
| 10 |
+
r'instagram\.com/tv/([^/?]+)',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
]
|
| 12 |
|
| 13 |
for pattern in patterns:
|
| 14 |
+
match = re.search(pattern, url)
|
| 15 |
if match:
|
| 16 |
return match.group(1)
|
|
|
|
|
|
|
|
|
|
| 17 |
return None
|
| 18 |
|
| 19 |
def download_reel_audio(url, output_folder="downloads"):
|