This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
generated from othneildrew/Best-README-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MidiaSaverBR.py
288 lines (249 loc) · 10.6 KB
/
MidiaSaverBR.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
import wx, re, time, os
from decoding import getMedia, killFirefox
from threading import *
formato='.jpg'
button = 0
EVT_RESULT_ID = wx.NewId()
ID_START = wx.NewId()
url=''
def getTipo():
global formato
return formato
def setTipo(tipo):
global formato
formato=tipo
######################################################Thread Class##########################################################################################
def EVT_RESULT(win, func):
win.Connect(-1, -1, EVT_RESULT_ID, func)
class ResultEvent(wx.PyEvent):
def __init__(self, data):
wx.PyEvent.__init__(self)
self.SetEventType(EVT_RESULT_ID)
self.data = data
class WorkerThread(Thread):
"""Worker Thread Class."""
def __init__(self, notify_window):
"""Init Worker Thread Class."""
Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = 0
self.start()
#Open URL Message
def MessageBrowser(self):
wx.MessageBox('O link foi aberto no seu navegador!', '',
wx.OK | wx.ICON_INFORMATION)
#Wait MessageBox
def Aguarde(self):
wx.MessageBox('Isso pode demorar até 1 minuto.', 'Aguarde um instante',
wx.OK | wx.ICON_INFORMATION)
def MessageErro(self):
wx.MessageBox('Erro, tente novamente.', '',
wx.OK | wx.ICON_INFORMATION)
def MessageM4s(self):
wx.MessageBox('Formato de video inválido tente outro.', 'Erro',
wx.OK | wx.ICON_INFORMATION)
def run(self):
global button
global url
self.tipo = getTipo()
self.url = url
self.stories = re.search('https://www.instagram.com/stories', self.url)
self.posts = re.search('https://www.instagram.com/p', self.url)
self.twt = re.search('https://twitter.com/', self.url)
########################################################## Instagram Posts ##################################################################################
if (self.posts != None):
dlg = wx.MessageDialog(None, 'Deseja salvar no seu computador?', '',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dlg.ShowModal()
if resp == wx.ID_YES:
self.Aguarde()
self.response='Computador'
time.sleep(1)
if(getMedia(self.url, self.tipo, self.response, self.posts, button) == True):
button += 1
else:
dlg2 = wx.MessageDialog(None, 'Deseja abrir no seu navegador?', 'Salvar ou Abrir No Navegador',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dlg2.ShowModal()
if resp == wx.ID_YES:
self.Aguarde()
self.response='Navegador'
time.sleep(1)
if(getMedia(self.url, self.tipo, self.response, self.posts, button) == True):
button += 1
else:
event.Skip()
########################################################## Instagram Stories ##################################################################################
elif (self.stories != None):
dlg = wx.MessageDialog(None, 'Deseja salvar no seu computador?', 'Salvar ou Abrir No Navegador',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dlg.ShowModal()
if resp == wx.ID_YES:
self.Aguarde()
self.response='Computador'
time.sleep(1)
if(getMedia(self.url, self.tipo, self.response, self.stories, button) == True):
button += 1
else:
dlg2 = wx.MessageDialog(None, 'Deseja abrir no seu navegador?', '',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dlg2.ShowModal()
if resp == wx.ID_YES:
self.Aguarde()
self.response='Navegador'
time.sleep(1)
if(getMedia(self.url, self.tipo, self.response, self.stories, button) == True):
button += 1
else:
event.Skip()
########################################################## Twitter Media ##################################################################################
elif (self.twt != None):
dlg = wx.MessageDialog(None, 'Deseja salvar no seu computador?', 'Salvar ou Abrir No Navegador',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dlg.ShowModal()
if resp == wx.ID_YES:
self.Aguarde()
self.response='Computador'
time.sleep(1)
getMedia(self.url, self.tipo, self.response, self.twt, button)
else:
dlg2 = wx.MessageDialog(None, 'Deseja abrir no seu navegador?', '',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dlg2.ShowModal()
if resp == wx.ID_YES:
self.Aguarde()
self.response='Navegador'
time.sleep(1)
getMedia(self.url, self.tipo, self.response, self.twt, button)
if self._want_abort:
wx.PostEvent(self._notify_window, ResultEvent(None))
return
wx.PostEvent(self._notify_window, ResultEvent(True))
def abort(self):
"""abort worker thread."""
self._want_abort = 1
########################################################################################################################
#Frame class constructor
class Frame(wx.Frame):
def __init__(self, parent, title):
super(Frame, self).__init__(parent, title=title)
self.Panel()
self.Centre()
self.SetSize(500,250)
###########################################################################################################################
#Panel
def Panel(self):
panel = wx.Panel(self)
#Setting FONT
font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)#font type
font.SetPointSize(11) #font size
#Box Sizers
vbox = wx.BoxSizer(wx.VERTICAL) #Box sizer VERTICAL
hbox1 = wx.BoxSizer(wx.HORIZONTAL) #Box sizer Horizontal
#Static Text 1
st1 = wx.StaticText(panel, label='Insira Um Link: ') #Static Text Above Field Camp
st1.SetFont(font) #st1 Font
hbox1.Add(st1, flag=wx.RIGHT | wx.TOP, border=8)#Inserting ST1 into the FRAME
#Field 1
self.field1 = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER) #Field for Input
hbox1.Add(self.field1, proportion=1)#Inserting FIELD1 into the FRAME
vbox.Add(hbox1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)#Adjusting FRAME
vbox.Add((-1, 32))# Adjust Vertical Position
############################################################################################################################
#CheckBoxes Static Text
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
st2 = wx.StaticText(panel, label='Escolha o Tipo do Arquivo:')
st2.SetFont(font)
hbox2.Add(st2,flag=wx.LEFT, border=8)
vbox.Add(hbox2, flag=wx.RIGHT, border=10)
vbox.Add((-1, 10))
#RadioButtons
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
self.rb1 = wx.RadioButton(panel, label='Imagem')
self.rb1.SetFont(font)
hbox4.Add(self.rb1)
self.rb2 = wx.RadioButton(panel, label='Video')
self.rb2.SetFont(font)
hbox4.Add(self.rb2)
self.rb3 = wx.RadioButton (panel, label='GIF')
self.rb3.SetFont(font)
hbox4.Add(self.rb3, flag=wx.LEFT, border=2)
vbox.Add(hbox4, flag=wx.LEFT, border=2)
vbox.Add((-1, 25))
#Buttons
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
btn1 = wx.Button(panel, ID_START, label='Salvar', size=(120, 50))
hbox5.Add(btn1)
btn2 = wx.Button(panel, label='Fechar', size=(120, 50))
hbox5.Add(btn2)
vbox.Add(hbox5, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=10)
#########################################################################################################################################
#Adjustments
panel.SetSizer(vbox)
self.CreateStatusBar()
self.worker = None
self.Bind(wx.EVT_BUTTON, self.OnSave, id=ID_START)
EVT_RESULT(self,self.OnResult)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, id=btn2.GetId())
self.Bind(wx.EVT_BUTTON, self.OnSave, id=ID_START)
self.Bind(wx.EVT_RADIOBUTTON, self.FileType)
self.Bind(wx.EVT_TEXT_ENTER, self.OnSave)
###################################################################################################
#Events
#CloseButton Event
def OnCloseWindow(self, event):
dial = wx.MessageDialog(None, 'Deseja sair?', 'Sair',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
resp = dial.ShowModal()
if resp == wx.ID_YES:
self.Destroy()
killFirefox()
else:
event.Skip()
#RadioButton Event
def FileType(self, event):
state1 = self.rb1.GetValue()
state2 = self.rb2.GetValue()
state3 = self.rb3.GetValue()
if (state2 == True):
self.tipo='.mp4'
elif (state3 == True):
self.tipo= 'gif'
else:
self.tipo='.jpg'
setTipo(self.tipo)
#Save Button
def OnSave(self, event):
global url
url = self.field1.GetValue()
if (url == ''):
dlg3 = wx.MessageBox('Voce não inseriu um link', '',
wx.OK | wx.ICON_INFORMATION)
event.Skip()
else:
if not self.worker:
self.worker = WorkerThread(self)
self.SetStatusText('Salvando seu link...')
#On getMedia() result
def OnResult(self, event):
"""Show Result status."""
if event.data is None:
self.SetStatusText('Operação cancelada.')
elif event.data is False:
self.MessageM4s()
else:
self.SetStatusText('Arquivo salvo com sucesso.')
self.MessageSave()
self.worker = None
#Save to PC Message
def MessageSave(self):
wx.MessageBox('Arquivo salvo com sucesso!', 'Finalizado',
wx.OK | wx.ICON_INFORMATION)
def main():
app = wx.App()
dlg = Frame(None, title='Midia Save')
dlg.Show()
app.MainLoop()
if __name__ == '__main__':
main()