import wx ,io ,sys ,re
from pytube import YouTube
import YouTube_ui
class MyFrame( YouTube_ui.MyFrame1 ):
def __init__( self, parent ):
YouTube_ui.MyFrame1.__init__( self, parent )
# self.m_textCtrl1.SetValue(<< url >>)
# self.m_textCtrl2.SetValue(<< pass >>)
def btn_go( self, event ):
url=self.m_textCtrl1.GetValue()
yt=YouTube(url)
for list in yt.streams.all():
with io.StringIO() as f:
sys.stdout = f
print(list)
text = f.getvalue()
self.m_listBox1.Append(text)
sys.stdout = sys.__stdout__
def listbox_select(self,e):
str=e.GetEventObject().GetStringSelection() # get text
num=re.search('[0-9]+' , str)
self.m_textCtrl3.SetValue(num.group(0))
def btn_bye( self, event ):
quit()
def btn_download( self, event ):
YouTube( self.m_textCtrl1.GetValue() ).streams.get_by_itag( \
self.m_textCtrl3.GetValue() ).download( self.m_textCtrl2.GetValue() )
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show(True)
app.MainLoop()
pytube は pipで落とした。すぐだった、軽そう。wxFormBuilderで作る。簡単で良いですyt.streams.all() をforで回せば落とせるタイプのリストが一行ずつ取得できるんだけど、これはStreamになっていて、GUIでは表示できないprintするのは簡単なんだけど、GUIで表示するにはtextにしなければならず、その方法がわからないprintの出力をtextに変換して表示したのがこのコードですprintは指定しなければ標準出力に出力される、コンソールね。あらかじめ出力先をテキストストリームにしておいて、そこからgetvalueすればテキストで取得できるって事ですprintだけど、ものすごい実力を持ってるんだなあといつも思いますListBoxのアイテムをクリックしたら文字列からIDを取得して下のtextctrlに表示する。downloadで指定したフォルダにダウンロードしますprog