|
import streamlit as st |
|
import requests |
|
import time |
|
import urllib.request |
|
import os |
|
import json |
|
|
|
|
|
INSTAGRAM_USERNAME = "ladygaga" |
|
|
|
|
|
|
|
class Instagram_Downloader: |
|
def __init__(self, username): |
|
|
|
|
|
def create_download_directory(self): |
|
|
|
|
|
def set_user_id(self): |
|
|
|
|
|
|
|
|
|
def main(): |
|
st.title("Instagram Media Downloader") |
|
|
|
|
|
username = st.text_input("Enter Instagram Username:", value=INSTAGRAM_USERNAME) |
|
|
|
|
|
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) |
|
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() |