Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,45 @@
|
|
| 1 |
-
# streamlit_instaloader_cookie.py
|
| 2 |
import streamlit as st
|
| 3 |
import instaloader
|
| 4 |
import os
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
import base64
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
L.context.load_cookiejar(cookiefile)
|
| 16 |
-
|
| 17 |
-
# Extract shortcode from the link
|
| 18 |
-
shortcode = link.split('/')[-2]
|
| 19 |
-
|
| 20 |
-
# Download the reel
|
| 21 |
-
post = instaloader.Post.from_shortcode(L.context, shortcode)
|
| 22 |
-
L.download_post(post, target=download_dir)
|
| 23 |
-
reel_path = os.path.join(download_dir, f"{post.date_utc.strftime('%Y-%m-%d_%H-%M-%S')}_{shortcode}.mp4")
|
| 24 |
-
|
| 25 |
-
# Return the path to the downloaded reel
|
| 26 |
-
return reel_path
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
b64 = base64.b64encode(file_bytes).decode()
|
| 36 |
-
href = f'<a href="data:file/mp4;base64,{b64}" download="{Path(file_path).name}">Download Reel</a>'
|
| 37 |
-
return href
|
| 38 |
|
| 39 |
def main():
|
| 40 |
-
st.title(
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
if st.button(
|
| 47 |
-
if
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# Clean up the saved cookie file
|
| 60 |
-
os.remove(cookie_path)
|
| 61 |
else:
|
| 62 |
-
st.warning(
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
main()
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import instaloader
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def download_reel(url, username, password):
|
| 6 |
+
# Set up Instaloader with login credentials
|
| 7 |
+
loader = instaloader.Instaloader()
|
| 8 |
+
loader.login(username, password)
|
| 9 |
|
| 10 |
+
# Extract shortcode from URL
|
| 11 |
+
shortcode = url.split('/')[-2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Download the reel
|
| 14 |
+
try:
|
| 15 |
+
post = instaloader.Post.from_shortcode(loader.context, shortcode)
|
| 16 |
+
loader.download_post(post, target=f"reels/{shortcode}")
|
| 17 |
+
return f"Reel downloaded successfully to reels/{shortcode}"
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"An error occurred: {str(e)}"
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
def main():
|
| 22 |
+
st.title('Instagram Reel Downloader')
|
| 23 |
+
|
| 24 |
+
# Input for Reel URL
|
| 25 |
+
url = st.text_input('Enter the Instagram Reel URL')
|
| 26 |
+
|
| 27 |
+
# Handle form submission
|
| 28 |
+
if st.button('Download Reel'):
|
| 29 |
+
if url:
|
| 30 |
+
# Instagram login credentials (remember to handle this securely)
|
| 31 |
+
username = 'balance.and.blisss'
|
| 32 |
+
password = '1e9!5a=e1^BvRBYjz%aB'
|
| 33 |
+
|
| 34 |
+
# Create the directory if it doesn't exist
|
| 35 |
+
if not os.path.exists("reels"):
|
| 36 |
+
os.makedirs("reels")
|
| 37 |
+
|
| 38 |
+
# Download the reel
|
| 39 |
+
result = download_reel(url, username, password)
|
| 40 |
+
st.write(result)
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
+
st.warning('Please enter a URL.')
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
main()
|