Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import subprocess
|
|
3 |
import pkg_resources
|
4 |
import os
|
5 |
import tempfile
|
|
|
6 |
|
7 |
required_packages = {
|
8 |
'torch': 'torch',
|
@@ -44,27 +45,23 @@ L = instaloader.Instaloader()
|
|
44 |
|
45 |
def download_instagram_video(url):
|
46 |
try:
|
47 |
-
#
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
else:
|
|
|
53 |
return None
|
54 |
-
|
55 |
-
# Download the post/reel
|
56 |
-
post = instaloader.Post.from_shortcode(L.context, shortcode)
|
57 |
-
|
58 |
-
# Create a temporary directory
|
59 |
-
with tempfile.TemporaryDirectory() as tmpdirname:
|
60 |
-
# Download the video
|
61 |
-
L.download_post(post, target=tmpdirname)
|
62 |
-
|
63 |
-
# Find the downloaded video file
|
64 |
-
video_file = next(file for file in os.listdir(tmpdirname) if file.endswith('.mp4'))
|
65 |
-
video_path = os.path.join(tmpdirname, video_file)
|
66 |
-
|
67 |
-
return video_path
|
68 |
except Exception as e:
|
69 |
print(f"Error downloading video: {e}")
|
70 |
return None
|
|
|
3 |
import pkg_resources
|
4 |
import os
|
5 |
import tempfile
|
6 |
+
import requests
|
7 |
|
8 |
required_packages = {
|
9 |
'torch': 'torch',
|
|
|
45 |
|
46 |
def download_instagram_video(url):
|
47 |
try:
|
48 |
+
# Use a third-party API service like savefrom.net
|
49 |
+
api_url = f"https://api.savefrom.net/1/info?url={url}"
|
50 |
+
response = requests.get(api_url)
|
51 |
+
data = response.json()
|
52 |
+
|
53 |
+
if 'url' in data:
|
54 |
+
video_url = data['url']
|
55 |
+
video_data = requests.get(video_url)
|
56 |
+
|
57 |
+
# Save the video file locally
|
58 |
+
with open('downloaded_reel.mp4', 'wb') as f:
|
59 |
+
f.write(video_data.content)
|
60 |
+
|
61 |
+
return 'downloaded_reel.mp4'
|
62 |
else:
|
63 |
+
print(f"Error: {data.get('error', 'Unknown error')}")
|
64 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
except Exception as e:
|
66 |
print(f"Error downloading video: {e}")
|
67 |
return None
|