0

Hi guys i have made a simple gui to to run a single line of code, until now i run via cmd the command is

youtube-dl.py http://www.youtube.com/ --extract-audio --audio-format mp3

now i want to run this command with my gui.

My gui is this:

#!/usr/bin/python


import wx


APP_SIZE_X = 300
APP_SIZE_Y = 200

class MyButtons(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y))

        wx.Button(self, 1, 'Close', (50, 130))
        wx.Button(self, 2, 'Run', (150, 130), (110, -1))

        self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
        self.Bind(wx.EVT_BUTTON, self.OnRun, id=2)

        self.Centre()
        self.ShowModal()
        self.Destroy()

    def OnClose(self, event):
        self.Close(True)

    def OnRun(self,event):
        print "ok for now"


app = wx.App(0)
MyButtons(None, -1, 'buttons.py')
app.MainLoop()

I need some help please, and thanks for your help...

TLSK
  • 265
  • 1
  • 6
  • 23
  • Since youtube-dl is also a Python program, is there anything stopping you from just doing an `import youtube-dl` and then using the code therein directly? – a p Sep 17 '13 at 20:53
  • Good idea but if i import youtube-dl then how i run the follow command i am a little confused, http://www.youtube.com/ --extract-audio --audio-format mp3 is the less command but how to run it? – TLSK Sep 17 '13 at 20:58
  • 1
    Well, you'd have to look at the code in youtube-dl... if you really just want to call it as an external program (not recommended), use `subprocess.call()` or maybe `from sh import python` (ridiculous). See http://stackoverflow.com/questions/89228/calling-an-external-command-in-python for more on this. – a p Sep 17 '13 at 21:03
  • Thanks i already have see this it's not so good!! – TLSK Sep 17 '13 at 21:06

1 Answers1

1

You could just import subprocess and call your script that way. Something like this:

def OnRun(self,event):
    path = "/path/to/youtube-dl.py"
    url = "http://www.youtube.com/"
    subprocess.Popen(path, url, "--extract-audio", "--audio-format", "mp3")

See the docs for more information: http://docs.python.org/2/library/subprocess.html

Mike Driscoll
  • 31,394
  • 6
  • 39
  • 83
  • p = subprocess.Popen(['youtube-dl.py http://www.youtube.com/watch?v=RuARtirENtw --extract-audio --audio-format mp3'],shell=True) works fine – TLSK Sep 17 '13 at 22:08
  • Yeah, that would work too. I've had some odd issues calling it with just a string, which is why I showed the list way of passing arguments. – Mike Driscoll Sep 18 '13 at 13:29