Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import gdata.youtube
- import gdata.youtube.service
- import urllib2
- import os
- __author__ = 'Nicholas McKinney'
- class captchaFrame(wx.Dialog):
- def __init__(self, parent, id):
- wx.Dialog.__init__(self, parent, id, title, size = (390,350))
- self.panel = wx.Panel(self)
- self.vbox1 = wx.Sizer(wx.VERTICAL)
- self.hbox1 = wx.Sizer(wx.HORIZONTAL)
- self.hbox2 = wx.Sizer(wx.HORIZONTAL)
- self.hbox3 = wx.Sizer(wx.HORIZONTAL)
- self.hbox4 = wx.Sizer(wx.HORIZONTAL)
- self.yt_username = wx.StaticText(self.panel, label = 'YouTube Username/Email:')
- self.hbox1.Add(self.yt_username, flag = wx.EXPAND | wx.RIGHT, border = 8)
- self.yt_usrnmeTXT = wx.TextCtrl(self.panel)
- self.hbox1.Add(self.yt_usrnmeTXT, flag = wx.EXPAND, proportion = 1)
- self.yt_password = wx.StaticText(self.panel, label = 'Password:')
- self.hbox1.Add(self.yt_password, flag = wx.EXPAND | wx.ALL, border = 8)
- self.yt_passwordTXT = wx.TextCtrl(self.panel)
- self.hbox1.Add(self.yt_passwordTXT, flag = wx.EXPAND, proportion = 1)
- self.vbox.Add(self.hbox1, flag = wx.EXPAND | wx.LEFT | wx.RIGHT| wx.TOP, border = 10)
- pic = urllib2.urlopen(self.yt_service._GetCaptchaURL()).read()
- if os.path.exists(os.environ['APPDATA'] + '\\' + 'Together To The Top') == False:
- os.mkdir(os.environ['APPDATA'] + '\\' + 'Together To The Top')
- cPic = open(os.environ['APPDATA'] + '\\' + 'Together To The Top' + '\\' + 'pic.gif', 'wb').write(pic)
- self.captcha_image = wx.Bitmap(os.environ['APPDATA'] + '\\' + 'Together To The Top' + '\\' + 'pic.gif')
- self.captcha_image = wx.StaticBitmap(self.panelFront, -1, self.captcha_image)
- self.hbox2.Add(self.captcha_image, flag = wx.ALIGN_CENTRE, proportion = 1)
- self.vbox.Add(self.hbox2, flag = wx.ALIGN_CENTRE, proportion = 1)
- self.captcha_text = wx.StaticText(self.panel, label = 'Enter Code:')
- self.hbox3.Add(self.captcha_text, flag = wx.EXPAND | wx.RIGHT, border = 8)
- self.captcha_txtCTRL = wx.TextCtrl(self.panel)
- self.hbox3.Add(self.captcha_txtCTRL, flag = wx.EXPAND, proportion = 1)
- self.vbox.Add(self.hbox3, flag = wx.EXPAND, border = 8)
- self.validButt = wx.Button(self.panel, label = 'Login', size = (100,30))
- self.hbox2.Add(self.validButt, flag = wx.ALIGN_RIGHT, proportion = 1)
- self.vbox.Add(self.hbox2, flag = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
- self.panel.SetSizer(self.vbox)
- wx.Bind(wx.EVT_BUTTON, self.loginCaptcha, self.validButt)
- def loginCaptcha(self, event):
- if self.yt_usrnmeTXT.GetValue() == '' or self.yt_passwordTXT.GetValue() == '' or self.captcha_txtCTRL.GetValue() == '':
- error102 = wx.MessageDialog(None, 'Error 102: No User Info Set', 'Error', wx.OK | wx.ICON_ERROR)
- error102.ShowModal()
- else:
- TTTT.verifyUsr(captcha_t = TTTT.yt_service._GetCaptchaToken, captcha_r = self.captcha_txtCTRL.GetValue())
- class TTTT(wx.Frame):
- def __init__(self, parent, id):
- self.yt_service = gdata.youtube.service.YouTubeService()
- self.yt_service.developer_key = 'AI39si5rnPvPImFhuElDqY9EJ8MhIy8dfX7fUOzSxon-D569gbN7YBiqTPktvlJUZvk3XlCuNq5KA_D2kKwa45DX16WdbCxg_Q'
- self.yt_service.client_id = 'Together To The Top'
- wx.Frame.__init__(self,parent,id,'Together To The Top',size=(390,350))
- self.initUI()
- def initUI(self):
- menubar = wx.MenuBar()
- about = wx.Menu()
- about.Append(101, '&About')
- about.Append(102, '&How To Use')
- menubar.Append(about, '&About')
- self.SetMenuBar(menubar)
- self.panelFront = wx.Panel(self)
- #panelFront.SetBackgroundColour('#ededed')
- self.vbox = wx.BoxSizer(wx.VERTICAL)
- # vbox.Add(panelFront, 1, wx.EXPAND | wx.ALL, 20)
- self.hbox1 = wx.BoxSizer(wx.HORIZONTAL)
- self.yt_username = wx.StaticText(self.panelFront, label = 'YouTube Username/Email:')
- self.hbox1.Add(self.yt_username, flag = wx.EXPAND | wx.RIGHT, border = 8)
- self.yt_usrnmeTXT = wx.TextCtrl(self.panelFront)
- self.hbox1.Add(self.yt_usrnmeTXT, flag = wx.EXPAND, proportion = 1)
- self.yt_password = wx.StaticText(self.panelFront, label = 'Password:')
- self.hbox1.Add(self.yt_password, flag = wx.EXPAND | wx.ALL, border = 8)
- self.yt_passwordTXT = wx.TextCtrl(self.panelFront)
- self.hbox1.Add(self.yt_passwordTXT, flag = wx.EXPAND, proportion = 1)
- self.vbox.Add(self.hbox1, flag = wx.EXPAND | wx.LEFT | wx.RIGHT| wx.TOP, border = 10)
- self.hbox2 = wx.BoxSizer(wx.HORIZONTAL)
- self.validButt = wx.Button(self.panelFront, label = 'Login', size = (100,30))
- self.hbox2.Add(self.validButt, flag = wx.ALIGN_RIGHT, proportion = 1)
- self.vbox.Add(self.hbox2, flag = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
- self.vbox.Add((-1, 50))
- self.hbox3 = wx.BoxSizer(wx.HORIZONTAL)
- self.yt_name = wx.StaticText(self.panelFront, label = 'Target YouTuber:')
- self.hbox3.Add(self.yt_name, flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 8, proportion = 1)
- self.vbox.Add(self.hbox3, flag = wx.EXPAND | wx. ALIGN_CENTER | wx.ALL, border = 10)
- self.hbox4 = wx.BoxSizer(wx.HORIZONTAL)
- self.yt_nameTXT = wx.TextCtrl(self.panelFront)
- self.hbox4.Add(self.yt_nameTXT, flag = wx.EXPAND, proportion = 1)
- self.vbox.Add(self.hbox4, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
- self.hbox5 = wx.BoxSizer(wx.HORIZONTAL)
- self.yt_findVideos_Butt = wx.Button(self.panelFront, label = 'Find Videos', size = (100,30))
- self.hbox5.Add(self.yt_findVideos_Butt, flag = wx.ALIGN_RIGHT, proportion = 1)
- self.vbox.Add(self.hbox5, flag = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP, border = 10)
- self.panelFront.SetSizer(self.vbox)
- #bind buttons
- self.Bind(wx.EVT_BUTTON, self.verifyUsr, self.validButt)
- self.Bind(wx.EVT_BUTTON, self.findVids, self.yt_findVideos_Butt)
- def verifyUsr(self, event, captcha_t = None, captcha_r = None):
- if self.yt_usrnmeTXT.GetValue() == None or self.yt_passwordTXT.GetValue() == None:
- error102 = wx.MessageDialog(None, 'Error 102: No User Info Set', 'Error', wx.OK | wx.ICON_ERROR)
- error102.ShowModal()
- self.yt_service.email = self.yt_usrnmeTXT.GetValue()
- self.yt_service.password = self.yt_passwordTXT.GetValue()
- self.yt_service.source = 'Together To The Top'
- try:
- self.yt_service.ProgrammaticLogin(captcha_token = captcha_t, captcha_response = captcha_r)
- self.hbox1.DeleteWindows()
- self.hbox2.DeleteWindows()
- self.yt_authUSR = wx.StaticText(self.panelFront, label = 'Authenticated User:')
- self.hbox1.Add(self.yt_authUSR, flag = wx.EXPAND | wx.RIGHT, border = 8)
- self.yt_usr = wx.StaticText(self.panelFront, label = self.yt_service.email)
- self.hbox1.Add(self.yt_usr, flag = wx.EXPAND | wx.RIGHT, border = 8)
- self.hbox1.Layout()
- self.vbox.Layout()
- except gdata.service.CaptchaRequired:
- capLogin = captchaFrame(parent = None, id = -1, title = 'Login with Captcha')
- capLogin.ShowModal()
- capLogin.Destroy()
- except BadAuthentication:
- pass
- except:
- error103 = wx.MessageDialog(None, 'Error 103: Invalid Info', 'Error', wx.OK | wx.ICON_ERROR)
- error103.ShowModal()
- self.yt_usrnmeTXT.SetValue('')
- self.yt_passwordTXT.SetValue('')
- def findVids(self, event):
- if self.yt_nameTXT.GetValue() == '':
- error101 = wx.MessageDialog(None, 'Error 101: No User Verified', 'Error', wx.OK | wx.ICON_ERROR)
- error101.ShowModal()
- return 0
- def usrLogout(self, event):
- pass
- if __name__ == '__main__':
- app = wx.PySimpleApp()
- frame = TTTT(parent = None, id = -1)
- frame.Show()
- app.MainLoop()
Add Comment
Please, Sign In to add comment