Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,52 @@
|
|
| 1 |
-
#
|
| 2 |
import streamlit as st
|
| 3 |
import instaloader
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
L = instaloader.Instaloader()
|
|
|
|
|
|
|
| 7 |
|
| 8 |
try:
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
st.success(f"Downloaded reel: {post.shortcode}")
|
| 20 |
|
| 21 |
except instaloader.exceptions.InstaloaderException as e:
|
| 22 |
st.error(f"Error: {e}")
|
|
|
|
| 23 |
|
| 24 |
-
def
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
else:
|
| 35 |
-
st.warning("Please enter a
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
| 38 |
main()
|
|
|
|
| 1 |
+
# streamlit_instaloader_link.py
|
| 2 |
import streamlit as st
|
| 3 |
import instaloader
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import base64
|
| 7 |
|
| 8 |
+
def download_reel_from_link(link):
|
| 9 |
L = instaloader.Instaloader()
|
| 10 |
+
download_dir = "downloaded_reels"
|
| 11 |
+
Path(download_dir).mkdir(exist_ok=True)
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
# Extract shortcode from the link
|
| 15 |
+
shortcode = link.split('/')[-2]
|
| 16 |
|
| 17 |
+
# Download the reel
|
| 18 |
+
post = instaloader.Post.from_shortcode(L.context, shortcode)
|
| 19 |
+
L.download_post(post, target=download_dir)
|
| 20 |
+
reel_path = os.path.join(download_dir, f"{post.date_utc.strftime('%Y-%m-%d_%H-%M-%S')}_{shortcode}.mp4")
|
| 21 |
+
|
| 22 |
+
# Return the path to the downloaded reel
|
| 23 |
+
return reel_path
|
|
|
|
| 24 |
|
| 25 |
except instaloader.exceptions.InstaloaderException as e:
|
| 26 |
st.error(f"Error: {e}")
|
| 27 |
+
return None
|
| 28 |
|
| 29 |
+
def get_download_link(file_path):
|
| 30 |
+
with open(file_path, "rb") as f:
|
| 31 |
+
file_bytes = f.read()
|
| 32 |
+
b64 = base64.b64encode(file_bytes).decode()
|
| 33 |
+
href = f'<a href="data:file/mp4;base64,{b64}" download="{Path(file_path).name}">Download Reel</a>'
|
| 34 |
+
return href
|
| 35 |
|
| 36 |
+
def main():
|
| 37 |
+
st.title("Instagram Reel Downloader")
|
| 38 |
+
st.write("Enter the Instagram reel link to download:")
|
| 39 |
+
|
| 40 |
+
link = st.text_input("Instagram Reel Link", "")
|
| 41 |
+
if st.button("Download Reel"):
|
| 42 |
+
if link:
|
| 43 |
+
st.info(f"Downloading reel from {link}...")
|
| 44 |
+
reel_path = download_reel_from_link(link)
|
| 45 |
+
if reel_path:
|
| 46 |
+
st.success(f"Downloaded reel: {Path(reel_path).name}")
|
| 47 |
+
st.markdown(get_download_link(reel_path), unsafe_allow_html=True)
|
| 48 |
else:
|
| 49 |
+
st.warning("Please enter a valid Instagram reel link.")
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
main()
|