Guest User

Untitled

a guest
Jan 18th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. import wx
  2. import gdata.youtube
  3. import gdata.youtube.service
  4. import urllib2
  5. import os
  6. __author__ = 'Nicholas McKinney'
  7.  
  8.  
  9. class captchaFrame(wx.Dialog):
  10. def __init__(self, parent, id):
  11. wx.Dialog.__init__(self, parent, id, title, size = (390,350))
  12.  
  13. self.panel = wx.Panel(self)
  14. self.vbox1 = wx.Sizer(wx.VERTICAL)
  15. self.hbox1 = wx.Sizer(wx.HORIZONTAL)
  16. self.hbox2 = wx.Sizer(wx.HORIZONTAL)
  17. self.hbox3 = wx.Sizer(wx.HORIZONTAL)
  18. self.hbox4 = wx.Sizer(wx.HORIZONTAL)
  19.  
  20. self.yt_username = wx.StaticText(self.panel, label = 'YouTube Username/Email:')
  21. self.hbox1.Add(self.yt_username, flag = wx.EXPAND | wx.RIGHT, border = 8)
  22. self.yt_usrnmeTXT = wx.TextCtrl(self.panel)
  23. self.hbox1.Add(self.yt_usrnmeTXT, flag = wx.EXPAND, proportion = 1)
  24. self.yt_password = wx.StaticText(self.panel, label = 'Password:')
  25. self.hbox1.Add(self.yt_password, flag = wx.EXPAND | wx.ALL, border = 8)
  26. self.yt_passwordTXT = wx.TextCtrl(self.panel)
  27. self.hbox1.Add(self.yt_passwordTXT, flag = wx.EXPAND, proportion = 1)
  28. self.vbox.Add(self.hbox1, flag = wx.EXPAND | wx.LEFT | wx.RIGHT| wx.TOP, border = 10)
  29.  
  30. pic = urllib2.urlopen(self.yt_service._GetCaptchaURL()).read()
  31. if os.path.exists(os.environ['APPDATA'] + '\\' + 'Together To The Top') == False:
  32. os.mkdir(os.environ['APPDATA'] + '\\' + 'Together To The Top')
  33. cPic = open(os.environ['APPDATA'] + '\\' + 'Together To The Top' + '\\' + 'pic.gif', 'wb').write(pic)
  34. self.captcha_image = wx.Bitmap(os.environ['APPDATA'] + '\\' + 'Together To The Top' + '\\' + 'pic.gif')
  35. self.captcha_image = wx.StaticBitmap(self.panelFront, -1, self.captcha_image)
  36. self.hbox2.Add(self.captcha_image, flag = wx.ALIGN_CENTRE, proportion = 1)
  37. self.vbox.Add(self.hbox2, flag = wx.ALIGN_CENTRE, proportion = 1)
  38.  
  39. self.captcha_text = wx.StaticText(self.panel, label = 'Enter Code:')
  40. self.hbox3.Add(self.captcha_text, flag = wx.EXPAND | wx.RIGHT, border = 8)
  41. self.captcha_txtCTRL = wx.TextCtrl(self.panel)
  42. self.hbox3.Add(self.captcha_txtCTRL, flag = wx.EXPAND, proportion = 1)
  43. self.vbox.Add(self.hbox3, flag = wx.EXPAND, border = 8)
  44.  
  45. self.validButt = wx.Button(self.panel, label = 'Login', size = (100,30))
  46. self.hbox2.Add(self.validButt, flag = wx.ALIGN_RIGHT, proportion = 1)
  47. self.vbox.Add(self.hbox2, flag = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
  48.  
  49. self.panel.SetSizer(self.vbox)
  50. wx.Bind(wx.EVT_BUTTON, self.loginCaptcha, self.validButt)
  51.  
  52. def loginCaptcha(self, event):
  53. if self.yt_usrnmeTXT.GetValue() == '' or self.yt_passwordTXT.GetValue() == '' or self.captcha_txtCTRL.GetValue() == '':
  54. error102 = wx.MessageDialog(None, 'Error 102: No User Info Set', 'Error', wx.OK | wx.ICON_ERROR)
  55. error102.ShowModal()
  56. else:
  57. TTTT.verifyUsr(captcha_t = TTTT.yt_service._GetCaptchaToken, captcha_r = self.captcha_txtCTRL.GetValue())
  58.  
  59. class TTTT(wx.Frame):
  60. def __init__(self, parent, id):
  61. self.yt_service = gdata.youtube.service.YouTubeService()
  62. self.yt_service.developer_key = 'AI39si5rnPvPImFhuElDqY9EJ8MhIy8dfX7fUOzSxon-D569gbN7YBiqTPktvlJUZvk3XlCuNq5KA_D2kKwa45DX16WdbCxg_Q'
  63. self.yt_service.client_id = 'Together To The Top'
  64. wx.Frame.__init__(self,parent,id,'Together To The Top',size=(390,350))
  65. self.initUI()
  66. def initUI(self):
  67. menubar = wx.MenuBar()
  68. about = wx.Menu()
  69. about.Append(101, '&About')
  70. about.Append(102, '&How To Use')
  71.  
  72. menubar.Append(about, '&About')
  73. self.SetMenuBar(menubar)
  74.  
  75.  
  76. self.panelFront = wx.Panel(self)
  77. #panelFront.SetBackgroundColour('#ededed')
  78.  
  79. self.vbox = wx.BoxSizer(wx.VERTICAL)
  80. # vbox.Add(panelFront, 1, wx.EXPAND | wx.ALL, 20)
  81.  
  82. self.hbox1 = wx.BoxSizer(wx.HORIZONTAL)
  83. self.yt_username = wx.StaticText(self.panelFront, label = 'YouTube Username/Email:')
  84. self.hbox1.Add(self.yt_username, flag = wx.EXPAND | wx.RIGHT, border = 8)
  85. self.yt_usrnmeTXT = wx.TextCtrl(self.panelFront)
  86. self.hbox1.Add(self.yt_usrnmeTXT, flag = wx.EXPAND, proportion = 1)
  87. self.yt_password = wx.StaticText(self.panelFront, label = 'Password:')
  88. self.hbox1.Add(self.yt_password, flag = wx.EXPAND | wx.ALL, border = 8)
  89. self.yt_passwordTXT = wx.TextCtrl(self.panelFront)
  90. self.hbox1.Add(self.yt_passwordTXT, flag = wx.EXPAND, proportion = 1)
  91. self.vbox.Add(self.hbox1, flag = wx.EXPAND | wx.LEFT | wx.RIGHT| wx.TOP, border = 10)
  92.  
  93. self.hbox2 = wx.BoxSizer(wx.HORIZONTAL)
  94. self.validButt = wx.Button(self.panelFront, label = 'Login', size = (100,30))
  95. self.hbox2.Add(self.validButt, flag = wx.ALIGN_RIGHT, proportion = 1)
  96. self.vbox.Add(self.hbox2, flag = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
  97.  
  98. self.vbox.Add((-1, 50))
  99.  
  100. self.hbox3 = wx.BoxSizer(wx.HORIZONTAL)
  101. self.yt_name = wx.StaticText(self.panelFront, label = 'Target YouTuber:')
  102. self.hbox3.Add(self.yt_name, flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 8, proportion = 1)
  103. self.vbox.Add(self.hbox3, flag = wx.EXPAND | wx. ALIGN_CENTER | wx.ALL, border = 10)
  104.  
  105. self.hbox4 = wx.BoxSizer(wx.HORIZONTAL)
  106. self.yt_nameTXT = wx.TextCtrl(self.panelFront)
  107. self.hbox4.Add(self.yt_nameTXT, flag = wx.EXPAND, proportion = 1)
  108. self.vbox.Add(self.hbox4, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
  109.  
  110. self.hbox5 = wx.BoxSizer(wx.HORIZONTAL)
  111. self.yt_findVideos_Butt = wx.Button(self.panelFront, label = 'Find Videos', size = (100,30))
  112. self.hbox5.Add(self.yt_findVideos_Butt, flag = wx.ALIGN_RIGHT, proportion = 1)
  113. self.vbox.Add(self.hbox5, flag = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
  114.  
  115. self.panelFront.SetSizer(self.vbox)
  116.  
  117.  
  118. #bind buttons
  119. self.Bind(wx.EVT_BUTTON, self.verifyUsr, self.validButt)
  120. self.Bind(wx.EVT_BUTTON, self.findVids, self.yt_findVideos_Butt)
  121.  
  122. def verifyUsr(self, event, captcha_t = None, captcha_r = None):
  123. if self.yt_usrnmeTXT.GetValue() == None or self.yt_passwordTXT.GetValue() == None:
  124. error102 = wx.MessageDialog(None, 'Error 102: No User Info Set', 'Error', wx.OK | wx.ICON_ERROR)
  125. error102.ShowModal()
  126. self.yt_service.email = self.yt_usrnmeTXT.GetValue()
  127. self.yt_service.password = self.yt_passwordTXT.GetValue()
  128. self.yt_service.source = 'Together To The Top'
  129. try:
  130. self.yt_service.ProgrammaticLogin(captcha_token = captcha_t, captcha_response = captcha_r)
  131. self.hbox1.DeleteWindows()
  132. self.hbox2.DeleteWindows()
  133. self.yt_authUSR = wx.StaticText(self.panelFront, label = 'Authenticated User:')
  134. self.hbox1.Add(self.yt_authUSR, flag = wx.EXPAND | wx.RIGHT, border = 8)
  135. self.yt_usr = wx.StaticText(self.panelFront, label = self.yt_service.email)
  136. self.hbox1.Add(self.yt_usr, flag = wx.EXPAND | wx.RIGHT, border = 8)
  137. self.hbox1.Layout()
  138. self.vbox.Layout()
  139. except gdata.service.CaptchaRequired:
  140. capLogin = captchaFrame(parent = None, id = -1, title = 'Login with Captcha')
  141. capLogin.ShowModal()
  142. capLogin.Destroy()
  143. except BadAuthentication:
  144. pass
  145. except:
  146. error103 = wx.MessageDialog(None, 'Error 103: Invalid Info', 'Error', wx.OK | wx.ICON_ERROR)
  147. error103.ShowModal()
  148. self.yt_usrnmeTXT.SetValue('')
  149. self.yt_passwordTXT.SetValue('')
  150. def findVids(self, event):
  151. if self.yt_nameTXT.GetValue() == '':
  152. error101 = wx.MessageDialog(None, 'Error 101: No User Verified', 'Error', wx.OK | wx.ICON_ERROR)
  153. error101.ShowModal()
  154. return 0
  155. def usrLogout(self, event):
  156. pass
  157.  
  158.  
  159. if __name__ == '__main__':
  160. app = wx.PySimpleApp()
  161. frame = TTTT(parent = None, id = -1)
  162. frame.Show()
  163. app.MainLoop()
Add Comment
Please, Sign In to add comment