Spaces:
Paused
Paused
| import streamlit as st | |
| import instaloader | |
| import os | |
| def download_reel(url, username, password): | |
| # Set up Instaloader with login credentials | |
| loader = instaloader.Instaloader() | |
| loader.login(username, password) | |
| # Extract shortcode from URL | |
| shortcode = url.split('/')[-2] | |
| # Download the reel | |
| try: | |
| post = instaloader.Post.from_shortcode(loader.context, shortcode) | |
| loader.download_post(post, target=f"reels/{shortcode}") | |
| return f"Reel downloaded successfully to reels/{shortcode}" | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| def main(): | |
| st.title('Instagram Reel Downloader') | |
| # Input for Reel URL | |
| url = st.text_input('Enter the Instagram Reel URL') | |
| # Handle form submission | |
| if st.button('Download Reel'): | |
| if url: | |
| # Instagram login credentials (remember to handle this securely) | |
| username = 's' | |
| password = 'S' | |
| # Create the directory if it doesn't exist | |
| if not os.path.exists("reels"): | |
| os.makedirs("reels") | |
| # Download the reel | |
| result = download_reel(url, username, password) | |
| st.write(result) | |
| else: | |
| st.warning('Please enter a URL.') | |
| if __name__ == "__main__": | |
| main() | |