File size: 2,073 Bytes
1d549e9
73319d4
 
 
 
 
1d549e9
73319d4
 
1d549e9
73319d4
1d549e9
73319d4
 
 
1d549e9
73319d4
 
1d549e9
73319d4
 
 
 
1d549e9
 
 
 
73319d4
 
 
1d549e9
 
 
73319d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d549e9
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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()