Dl4 / app.py
Geek7's picture
Update app.py
73319d4 verified
raw
history blame
2.07 kB
import streamlit as st
import requests
import time
import urllib.request
import os
import json
# Constants
INSTAGRAM_USERNAME = "ladygaga"
# ------------------------------Do not modify under this line--------------------------------------- #
class Instagram_Downloader:
def __init__(self, username):
# ... (your existing code)
def create_download_directory(self):
# ... (your existing code)
def set_user_id(self):
# ... (your existing code)
# ... (your existing methods)
def main():
st.title("Instagram Media Downloader")
# Input field for Instagram username
username = st.text_input("Enter Instagram Username:", value=INSTAGRAM_USERNAME)
# Button to trigger the download
if st.button("Download Media"):
if username:
try:
user = Instagram_Downloader(username)
user.create_download_directory()
user.get_jsondata_instagram()
user.download_photos()
user.download_videos()
user.set_apilabel("data")
user.read_resume_end_cursor_timeline_media()
while True:
time.sleep(5) # pause to avoid ban
user.get_jsondata_instagram()
user.download_photos()
user.download_videos()
user.write_resume_end_cursor_timeline_media()
if not user.has_next_page():
user.remove_resume_file()
st.success(f"Done. All images/videos downloaded for {username} account.")
break
except Exception as e:
st.error(f"Error: {str(e)}")
st.warning("Script prematurely finished due to the daily limit of requests to Instagram API. "
"Execute the script again in a few hours to continue the resume of pending images/videos.")
else:
st.warning("Please enter a valid username.")
if __name__ == "__main__":
main()