#!/usr/bin/python import os import string import tempfile import commands import sys from wxPython.wx import * #---------------------------------------------------------------------- # CONFIGURATION DEVICE="/dev/cdrom" SPEED=20 #---------------------------------------------------------------------- class MP3BurnFrame(wxFrame): def __init__(self, *args, **kwds): # begin wxGlade: MP3BurnFrame.__init__ kwds["style"] = wxDEFAULT_FRAME_STYLE wxFrame.__init__(self, *args, **kwds) self.list_box_1 = wxListBox(self, -1, choices=["Drop Files here"]) # Menu Bar self.frame_1_menubar = wxMenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wxMenu() wxglade_tmp_menu.Append(101, "&Burn", "", wxITEM_NORMAL) wxglade_tmp_menu.Append(102, "E&xit", "", wxITEM_NORMAL) self.frame_1_menubar.Append(wxglade_tmp_menu, "&File") # Menu Bar end self.__set_properties() self.__do_layout() # end wxGlade dt = MyFileDropTarget(self) self.list_box_1.SetDropTarget(dt) EVT_MENU(self, 101, self.onBurn) EVT_MENU(self, 102, self.onExit) if len(sys.argv) != 1: dt.OnDropFiles(0, 0, sys.argv[1:]) def onBurn(self, event): if self.list_box_1.GetCount() == 1 and \ self.list_box_1.GetString(0) == "Drop Files here": return dlg = wxMessageDialog(self, "Make sure there is a blank CD-R in the drive.", "Insert CD", style=wxOK|wxCANCEL|wxICON_INFORMATION) response = dlg.ShowModal() dlg.Destroy() if response == wxID_CANCEL: return fileList = [] for i in range(self.list_box_1.GetCount()): fileList.append(self.list_box_1.GetString(i)) dirname = tempfile.mkdtemp() progress = wxProgressDialog("Converting", "Converting to WAV", len(fileList) * 2) for ind, i in enumerate(fileList): commands.getoutput('mpg321 -s "%s" | sox -t raw -r 44100 -s -w -c 2 - "%s/%02d - `basename "%s" .mp3`.wav"' % (i, dirname, ind, i)) progress.Update(ind) progress.Update(ind + 1, "Burning disk") commands.getstatusoutput("cdrecord -pad -v dev=%s -dao " % DEVICE + \ "speed=%d %s/*.wav" % (SPEED, dirname)) progress.Destroy() commands.getstatusoutput("rm -rf " + dirname) commands.getstatusoutput("eject cdrom") def onExit(self, event): self.Close(True) def __set_properties(self): # begin wxGlade: MP3BurnFrame.__set_properties self.SetTitle("MP3 Burn") self.list_box_1.SetSize((600, 400)) self.list_box_1.SetMinSize((600, 400)) self.list_box_1.SetSelection(0) # end wxGlade def __do_layout(self): # begin wxGlade: MP3BurnFrame.__do_layout sizer_1 = wxBoxSizer(wxVERTICAL) sizer_1.Add(self.list_box_1, 0, 0, 0) self.SetAutoLayout(1) self.SetSizer(sizer_1) sizer_1.Fit(self) sizer_1.SetSizeHints(self) self.Layout() # end wxGlade # end of class MP3BurnFrame class MyFileDropTarget(wxFileDropTarget): def __init__(self, window): wxFileDropTarget.__init__(self) self.window = window def OnDropFiles(self, x, y, tempnames): if self.window.list_box_1.GetCount() == 1 and \ self.window.list_box_1.GetString(0) == "Drop Files here": self.window.list_box_1.Clear() filenames = [] for file in tempnames: file = file.replace("%20", " ") file = os.path.realpath(file) if os.path.isdir(file): temp = commands.getoutput("ls " + \ file.replace(" ", "\ ") + "/") tempfiles = temp.split("\n") for temp in tempfiles: temp = file + "/" + temp if os.path.isfile(temp): filenames.append(temp) else: filenames.append(file) for file in filenames: if string.lower(file[-4:]) == ".mp3": self.window.list_box_1.Append(file) if self.window.list_box_1.GetCount() == 0: self.window.list_box_1.Append("Drop Files here") class MP3Burn(wxApp): def OnInit(self): wxInitAllImageHandlers() frame = MP3BurnFrame(None, -1, "MP3Burn") self.SetTopWindow(frame) frame.Show(1) return 1 if __name__ == "__main__": if os.getuid() != 0: sys.exit("Must be run as root.") mp3Burn = MP3Burn() mp3Burn.MainLoop() del mp3Burn