Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,32 +17,19 @@ def parse_cookie_string(cookie_string):
|
|
| 17 |
cookies.append({'name': name, 'value': value, 'domain': 'instagram.com', 'path': '/'})
|
| 18 |
return cookies
|
| 19 |
|
| 20 |
-
def convert_cookies_to_netscape(cookies):
|
| 21 |
-
# Convert cookies into Netscape format
|
| 22 |
-
cookies_txt = []
|
| 23 |
-
for cookie in cookies:
|
| 24 |
-
cookie_str = f"{cookie['domain']}\t{(0)}\t{cookie['path']}\t{(False)}\t{(False)}\t{cookie['name']}\t{cookie['value']}\t{int(datetime.timestamp(datetime.now()))}" # Expiry as current time (for session cookies)
|
| 25 |
-
cookies_txt.append(cookie_str)
|
| 26 |
-
return "\n".join(cookies_txt)
|
| 27 |
-
|
| 28 |
def get_instagram_media_info(link):
|
| 29 |
try:
|
| 30 |
# Parse the cookie string into individual cookies
|
| 31 |
cookies = parse_cookie_string(cookie_string)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
# Save cookies to a temporary file in Netscape format
|
| 37 |
-
temp_cookiefile = '/tmp/temp_cookies.txt'
|
| 38 |
-
with open(temp_cookiefile, 'w') as f:
|
| 39 |
-
f.write(cookies_netscape)
|
| 40 |
|
| 41 |
# Set up yt-dlp options with cookies
|
| 42 |
ydl_opts = {
|
| 43 |
'quiet': True, # Suppress unnecessary output
|
| 44 |
'force_generic_extractor': True, # Force generic extractor to handle Instagram links
|
| 45 |
-
'
|
| 46 |
}
|
| 47 |
|
| 48 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
| 17 |
cookies.append({'name': name, 'value': value, 'domain': 'instagram.com', 'path': '/'})
|
| 18 |
return cookies
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def get_instagram_media_info(link):
|
| 21 |
try:
|
| 22 |
# Parse the cookie string into individual cookies
|
| 23 |
cookies = parse_cookie_string(cookie_string)
|
| 24 |
|
| 25 |
+
# Prepare cookies as a dictionary for yt-dlp
|
| 26 |
+
cookies_dict = {cookie['name']: cookie['value'] for cookie in cookies}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Set up yt-dlp options with cookies
|
| 29 |
ydl_opts = {
|
| 30 |
'quiet': True, # Suppress unnecessary output
|
| 31 |
'force_generic_extractor': True, # Force generic extractor to handle Instagram links
|
| 32 |
+
'cookie': cookies_dict # Pass cookies directly
|
| 33 |
}
|
| 34 |
|
| 35 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|