-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstaPicVid.py
347 lines (242 loc) · 13.3 KB
/
InstaPicVid.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# from ssl import Purpose
import instaloader
from instaloader import Post
from tkinter import *
import subprocess
from tkinter import ttk
import tkinter.messagebox
import urllib.request
import webbrowser
# Testing Purpose links
# https://www.instagram.com/gal_gadot/
# https://www.instagram.com/bollywoodbinge/
# https://www.instagram.com/reel/CWQQoTaJnhS/?utm_source=ig_web_copy_link
# https://www.instagram.com/tv/CWVlkM9tGvi/?utm_source=ig_web_copy_link
# https://www.instagram.com/p/CWVAGDuphAJ/?utm_source=ig_web_copy_link
# https://www.instagram.com/p/CWPy0FyqKir/?utm_source=ig_web_copy_link
root = Tk()
#Windows Title
root.title("InstaPicVid Downloader")
#windows width=800 and height=500 fixed
root.geometry('800x500')
#windows resizable disable
root.resizable(width=False, height=False)
#windows icon set
p1 = PhotoImage(file = 'instagram_icon.png')
# Setting icon of master window
root.iconphoto(False, p1)
#variables
insta_Url= 'https://www.instagram.com/p/'
insta_Url1='https://www.instagram.com/tv/'
insta_Url_reel='https://www.instagram.com/reel/'
insta_ig='/?utm_source=ig_web_copy_link'
insta_Id=insta_Url[0:len(insta_Url)-2]
btColor= 'black'
borderWidth='0'
fontStyle=('', 11, 'bold')
fontStyle1=('', 15, 'bold')
fontSmall= ('', 8)
cursor="hand2"
#Checking internet connection status
def connect(host='http://google.com'):
try:
urllib.request.urlopen(host)
return True
except:
return False
#for webbrowser
def callback(event):
webbrowser.open_new_tab(event)
#Function to download videos, photos ,reels and IGTV
def insta_pic_vid():
def short(u1):
char_to_replace = {str(insta_Url_reel): '',str(insta_Url): '',str(insta_Url1): '', str(insta_ig): ''}
for key, value in char_to_replace.items():
u1 = u1.replace(key, value)
return u1
def show1():
#folder name
target= 'Instagram'
if connect() == True:
try:
url = inUrl.get()
if url == '':
raise Exception
elif url.find(insta_ig) != -1:
shorted_url = short(url)
my_listbox.insert(END,"<< "+str(shorted_url))
elif url.find(insta_Url) != -1:
shorted_url = url[28:len(url)-1]
my_listbox.insert(END,"<< "+str(shorted_url))
elif url.find(insta_Url_reel) != -1:
shorted_url = url[31:len(url)-1]
my_listbox.insert(END,"<< "+str(shorted_url))
elif insta_Url1==url[0:len(url) - 12]:
shorted_url = url[29:len(url) - 1]
my_listbox.insert(END,"<< "+str(shorted_url))
elif url.find(insta_ig) != -1:
shorted_url = short(url)
my_listbox.insert(END,"<< "+str(shorted_url))
else:
shorted_url=url
my_listbox.insert(END,"<< "+str(shorted_url))
#save_metadata=true, then Instaloader function also download post description()
i = instaloader.Instaloader(save_metadata=False, post_metadata_txt_pattern='')
post = Post.from_shortcode(i.context, shorted_url)
i.download_post(post, target=target)
#open downloaded path
subprocess.Popen('explorer "{0}"'.format(target))
tkinter.messagebox.showinfo("Downloading", "Downloading Successful")
except Exception:
tkinter.messagebox.showerror("Invalid Url","Input cannot be blank and Inavid Url")
else:
tkinter.messagebox.showerror("Connection Status", "No Internet!\nPlease Connect to Internet")
f2=Frame(bg="#ECE5F0")
f2.place(x=0, y=0, width=800, height=500)
input_url_label = ttk.Label(f2, text="Enter Post Link: ", background="#ECE5F0" , font=fontStyle)
input_url_label.pack(fill='x', padx=200, pady=(20,5))
inUrl = ttk.Entry(f2, font=(20), width=70)
inUrl.pack(padx=200, ipady=5)
b3 = Button(f2, text='Download', cursor=cursor, pady=5, borderwidth=borderWidth, relief="groove" , activebackground="blue", activeforeground="white",bg=btColor, fg='white', font=fontStyle1, command=show1)
b3.pack(pady=10,padx=200, fill=X)
input_url_history = ttk.Label(f2, text="Post Link History:", background="#ECE5F0" , font=fontStyle)
input_url_history.pack(fill='x', padx=200, pady=(20,0))
my_listbox = Listbox(f2, height=10, width=66)
my_listbox.pack()
label2 = Label(f2, text="Instruction: ", font=fontStyle, bd=5, fg="black", bg="#ECE5F0")
label2.place(x=200, y=370)
TEXT = "1. Copy Instagram Post Link and paste in the input field\n2. Download Photos, Video, Reels and IGTV"
label2 = Label(f2, text=TEXT, font=('', 10), bd=5, fg="#cd486b", justify=LEFT, bg="#ECE5F0")
label2.place(x=200, y=400)
b4=Button(f2, text="Back", cursor=cursor, borderwidth=borderWidth, bg=btColor, activebackground="blue", activeforeground="white", fg='white', font=fontStyle1, command=home)
b4.pack(anchor = "s", side = "right", padx=(0,20), pady=(0,15))
#Function to download unsta user's profile picture
def insta_profile_image():
def show2():
if connect() == True:
url1 = inUrl1.get()
try:
if url1=="":
raise Exception
elif len(url1) > 26 and url1.find(insta_Id, 0, 26) == 0:
temp=url1.replace(insta_Id,"")
shorted_url=temp[0:-1]
my_listbox1.insert(END,"<< "+str(shorted_url))
else:
shorted_url=url1
my_listbox1.insert(END,"<< "+str(shorted_url))
#save_metadata=true, then Instaloader function also download post description()
j = instaloader.Instaloader(save_metadata=False)
j.download_profile(shorted_url, profile_pic_only=True)
#open downloaded path
subprocess.Popen('explorer "{0}"'.format(shorted_url))
# tru()
tkinter.messagebox.showinfo("Downloading", "Downloading Successful")
except Exception:
tkinter.messagebox.showerror("Blanked","Input cannot be blanked and Inavid Url")
else:
tkinter.messagebox.showerror("Connection Status", "No Internet!\nPlease Connect to Internet")
f3=Frame(bg="#ECE5F0")
f3.place(x=0, y=0, width=800, height=500)
input_url_label1 = ttk.Label(f3, text="Enter Username:", background="#ECE5F0" , font=fontStyle)
input_url_label1.pack(fill='x', padx=200, pady=(20,5))
inUrl1 = ttk.Entry(f3, font=(20), width=70)
inUrl1.pack(padx=200, ipady=5)
b5 = Button(f3, text='Download', cursor=cursor, pady=5, borderwidth=borderWidth, relief="groove" , activebackground="blue", activeforeground="white",bg=btColor, fg='white', font=fontStyle1, command=show2)
b5.pack(pady=10,padx=200, fill=X)
input_url_history1 = ttk.Label(f3, text="Username History:", background="#ECE5F0" , font=fontStyle)
input_url_history1.pack(fill='x', padx=200, pady=(20,0))
my_listbox1 = Listbox(f3, height=10, width=66)
my_listbox1.pack()
instruction = Label(f3, text="Instruction: ", font=fontStyle, bd=5, fg="black", bg="#ECE5F0")
instruction.place(x=200, y=370)
TEXT = "1. You just any Public Instagram account profile URL\n or Link Address in the input field\n2. Download Profile Picture or DP"
instruction_Con = Label(f3, text=TEXT, font=('', 10), bd=5, fg="#cd486b", justify=LEFT, bg="#ECE5F0")
instruction_Con.place(x=200, y=400)
b6=Button(f3, text="Back", cursor=cursor, borderwidth=borderWidth, bg=btColor, activebackground="blue", activeforeground="white", fg='white', font=fontStyle1, command=home)
b6.pack(anchor = "s", side = "right", padx=(0,20), pady=(0,15))
def insta_stories():
def show3():
USERNAME=username_inUrl2.get()
PASSWORD=password_inUrl2.get()
if connect() == True:
url2 = inUrl2.get()
try:
if USERNAME=="" and PASSWORD=="" and url2=="" :
raise Exception
elif len(url2) > 26 and url2.find(insta_Id, 0, 26) == 0:
temp=url2.replace(insta_Id,"")
shorted_url=temp[0:-1]
my_listbox2.insert(END,"<< "+str(shorted_url))
else:
shorted_url=url2
my_listbox2.insert(END,"<< "+str(shorted_url))
s = instaloader.Instaloader(save_metadata=False)
s.login(USERNAME, PASSWORD)
profile = s.check_profile_id(shorted_url)
#save_metadata=true, then Instaloader function also download post description()
for story in s.get_stories(userids=str(profile.userid)):
for item in story.get_items():
s.download_storyitem(item, shorted_url)
#open downloaded path
subprocess.Popen('explorer "{0}"'.format(shorted_url))
# tru()
tkinter.messagebox.showinfo("Downloading", "Downloading Successful")
except Exception:
tkinter.messagebox.showerror("Blanked","Input cannot be blanked and Inavid Url")
else:
tkinter.messagebox.showerror("Connection Status", "No Internet!\nPlease Connect to Internet")
f4=Frame(bg="#ECE5F0")
f4.place(x=0, y=0, width=800, height=500)
username = ttk.Label(f4, text="Username:", background="#ECE5F0" , font=fontStyle)
username.pack(fill='x', padx=200, pady=(10,5))
username_inUrl2 = ttk.Entry(f4, font=(20), width=70)
username_inUrl2.pack(padx=200, ipady=5)
password = ttk.Label(f4, text="Password:", background="#ECE5F0" , font=fontStyle)
password.pack(fill='x', padx=200, pady=(5,5))
password_inUrl2 = ttk.Entry(f4, font=(20), width=70)
password_inUrl2.pack(padx=200, ipady=5)
input_url_label4 = ttk.Label(f4, text="Profile Username:", background="#ECE5F0" , font=fontStyle)
input_url_label4.pack(fill='x', padx=200, pady=(5,5))
inUrl2 = ttk.Entry(f4, font=(20), width=70)
inUrl2.pack(padx=200, ipady=5)
b6 = Button(f4, text='Download', cursor=cursor, pady=5, borderwidth=borderWidth, relief="groove" , activebackground="blue", activeforeground="white",bg=btColor, fg='white', font=fontStyle1, command=show3)
b6.pack(pady=10,padx=200, fill=X)
input_url_history2 = ttk.Label(f4, text="Stories History:", background="#ECE5F0" , font=fontStyle)
input_url_history2.pack(fill='x', padx=200)
my_listbox2 = Listbox(f4, height=5, width=66)
my_listbox2.pack()
instruction = Label(f4, text="Instruction: ", font=fontStyle, bd=5, fg="black", bg="#ECE5F0")
instruction.place(x=200, y=380)
TEXT = "1. Enter USERNAME, PASSWORD and Public Instagram\n account profile URL or Link Address\n2. Download any public profile Stories"
instruction_Con = Label(f4, text=TEXT, font=('', 10), bd=5, fg="#cd486b", justify=LEFT, bg="#ECE5F0")
instruction_Con.place(x=200, y=420)
b7=Button(f4, text="Back", cursor=cursor, borderwidth=borderWidth, bg=btColor, activebackground="blue", activeforeground="white", fg='white', font=fontStyle1, command=home)
b7.pack(anchor = "s", side = "right", padx=(0,20), pady=(0,15))
#Home Page Function
def home():
f1=Frame(bg="#ECE5F0")
des=ttk.Label(f1, background="#ECE5F0" , text="Download Instagram Video, Photos, DP, Stories, IGTV & Reels", anchor=CENTER, font=('Arial Bold', 18))
fB3=('', 15, 'bold')
b1=Button(f1, text="Photos", cursor=cursor, width=20, pady=10, bg=btColor, activebackground="blue", activeforeground="white", borderwidth=borderWidth, fg='white', font=fB3, command=insta_pic_vid)
b2=Button(f1, text="Profile Picture", cursor=cursor, width=20, pady=10, bg=btColor, activebackground="blue", activeforeground="white", borderwidth=borderWidth, fg='white', font=fB3, command=insta_profile_image)
b3=Button(f1, text="Videos", cursor=cursor, width=20, pady=10, bg=btColor, activebackground="blue", activeforeground="white", borderwidth=borderWidth, fg='white', font=fB3, command=insta_pic_vid)
b4=Button(f1, text="Stories", cursor=cursor, width=20, pady=10, bg=btColor, activebackground="blue", activeforeground="white", borderwidth=borderWidth, fg='white', font=fB3, command=insta_stories)
lbl = Label(f1, text="Github",background="#ECE5F0", fg='red', highlightthickness=2,highlightbackground = "red", font=('', 20, 'bold'), cursor=cursor)
lbl.bind("<Button>", lambda e: callback("https://github.com/sauravhathi"))
version=ttk.Label(f1, text="Version: 1.0.0", background="#ECE5F0" , font=fontSmall)
qut=ttk.Label(f1, text="Download Instagram Video, Photos, DP, Stories, IGTV & Reels", background="#ECE5F0" , anchor=CENTER, font=fontSmall)
#home page widget method
des.pack(fill='x', pady=(80,0))
b1.place(x=125, y=160)
b2.place(x=410, y=160)
b3.place(x=125, y=260)
b4.place(x=410, y=260)
lbl.place(x=340, y=380)
version.pack(anchor = "s", side = "left")
qut.pack(anchor = "s", side = "right")
f1.place(width=800, height=500)
#home function call
home()
#root. mainloop() is a method on the main window which we execute when we want to run our application
root.mainloop()