Geek7 commited on
Commit
73319d4
·
verified ·
1 Parent(s): cef203f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -14
app.py CHANGED
@@ -1,30 +1,58 @@
1
  import streamlit as st
2
- import instaloader
 
 
 
 
3
 
4
- def download_instagram_media(username):
5
- loader = instaloader.Instaloader()
6
 
7
- try:
8
- profile = instaloader.Profile.from_username(loader.context, username)
9
 
10
- for post in profile.get_posts():
11
- loader.download_post(post, target=profile.username)
 
12
 
13
- st.success(f"Download complete for '{username}'!")
 
14
 
15
- except instaloader.exceptions.ProfileNotExistsException:
16
- st.error(f"Profile '{username}' not found.")
 
 
17
 
18
  def main():
19
  st.title("Instagram Media Downloader")
20
 
21
- # Input field for the Instagram username
22
- username = st.text_input("Enter Instagram Username:")
23
-
24
  # Button to trigger the download
25
  if st.button("Download Media"):
26
  if username:
27
- download_instagram_media(username)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  else:
29
  st.warning("Please enter a valid username.")
30
 
 
1
  import streamlit as st
2
+ import requests
3
+ import time
4
+ import urllib.request
5
+ import os
6
+ import json
7
 
8
+ # Constants
9
+ INSTAGRAM_USERNAME = "ladygaga"
10
 
11
+ # ------------------------------Do not modify under this line--------------------------------------- #
 
12
 
13
+ class Instagram_Downloader:
14
+ def __init__(self, username):
15
+ # ... (your existing code)
16
 
17
+ def create_download_directory(self):
18
+ # ... (your existing code)
19
 
20
+ def set_user_id(self):
21
+ # ... (your existing code)
22
+
23
+ # ... (your existing methods)
24
 
25
  def main():
26
  st.title("Instagram Media Downloader")
27
 
28
+ # Input field for Instagram username
29
+ username = st.text_input("Enter Instagram Username:", value=INSTAGRAM_USERNAME)
30
+
31
  # Button to trigger the download
32
  if st.button("Download Media"):
33
  if username:
34
+ try:
35
+ user = Instagram_Downloader(username)
36
+ user.create_download_directory()
37
+ user.get_jsondata_instagram()
38
+ user.download_photos()
39
+ user.download_videos()
40
+ user.set_apilabel("data")
41
+ user.read_resume_end_cursor_timeline_media()
42
+ while True:
43
+ time.sleep(5) # pause to avoid ban
44
+ user.get_jsondata_instagram()
45
+ user.download_photos()
46
+ user.download_videos()
47
+ user.write_resume_end_cursor_timeline_media()
48
+ if not user.has_next_page():
49
+ user.remove_resume_file()
50
+ st.success(f"Done. All images/videos downloaded for {username} account.")
51
+ break
52
+ except Exception as e:
53
+ st.error(f"Error: {str(e)}")
54
+ st.warning("Script prematurely finished due to the daily limit of requests to Instagram API. "
55
+ "Execute the script again in a few hours to continue the resume of pending images/videos.")
56
  else:
57
  st.warning("Please enter a valid username.")
58