def search_torrents(self,event): query=self.search_bar.GetValue() if self.search_media_for_file(query): return try: meta_data = sr.get_metadata_from_server(query) if meta_data==None: Text="No Torrent Found" dlg1 = wx.MessageDialog(None,caption="Confirm Download:", message=str(Text) ,style=wx.OK|wx.ICON_EXCLAMATION) if dlg1.ShowModal() == wx.ID_OK: dlg1.Destroy() return open_meta_data = json.loads(meta_data) except(requests.exceptions.RequestException): print "server not up" return Text = "Was this the file you were looking for?\nSong: " + open_meta_data['title'] + "\nAlbum: " + open_meta_data['album'] + "\nArtist: " + open_meta_data['artist'] dlg1 = wx.MessageDialog(None,caption="Confirm Download:", message=str(Text) ,style=wx.OK|wx.CANCEL|wx.ICON_EXCLAMATION) if dlg1.ShowModal() == wx.ID_OK: download_hash = sr.init_download_on_server(meta_data) dlg1.Destroy() download_hash = sr.init_download_on_server(meta_data) else: return data = None while data is None: data,ctype = sr.poll_server(download_hash) time.sleep(2) if ctype == 'audio/mpeg': filepath = 'music/'+open_meta_data['title']+'.mp3' fileout = open(filepath, 'wb') fileout.write(data) finalpath = ac.convert_to_wav(filepath,outputpath=os.getcwd()+'/music/'+str(hash(filepath))+'.wav') open_meta_data['path'] = finalpath open_meta_data['name'] = open_meta_data['title'] os.remove(filepath) self.playlist.addSong(open_meta_data) if ctype == 'audio/m4a': filepath = 'music/'+open_meta_data['title']+'.m4a' fileout = open(filepath, 'wb') fileout.write(data) finalpath = ac.convert_to_wav(filepath,outputpath=os.getcwd()+'/music/'+str(hash(filepath))+'.wav') open_meta_data['path'] = finalpath open_meta_data['name'] = open_meta_data['title'] os.remove(filepath) self.playlist.addSong(open_meta_data) if ctype == 'audio/x-flac': filepath='music/'+open_meta_data['title']+'.flac' fileout = open(filepath, 'wb') fileout.write(data) finalpath = ac.convert_to_wav(filepath,outputpath=os.getcwd()+'/music/'+str(hash(filepath))+'.wav') open_meta_data['path'] = finalpath open_meta_data['name'] = open_meta_data['title'] os.remove(filepath) self.playlist.addSong(open_meta_data) if ctype == 'audio/x-wav': filepath = 'music/'+open_meta_data['title']+'.wav' fileout = open(filepath, 'wb') fileout.write(data) open_meta_data['path'] = filepath open_meta_data['name'] = open_meta_data['title'] self.playlist.addSong(open_meta_data)
def search_media_for_file(self, query): """return bool of wather or not file is found, if file is found pass it to playlist""" print(self.mediaFolder) for tup in os.walk(self.mediaFolder): for mfile in tup[2]: if mfile.endswith('/'): continue song = mfile.split('.')[0] if query not in song: continue print("sucess") album = tup[0].split('/')[-2] TEXT = "Is this the song you where searching for?\nSong: " + song + "\nAlbum: " + album dlg1 = wx.MessageDialog(None, caption="Confirm Download:", message=str(TEXT), style=wx.OK | wx.CANCEL | wx.ICON_EXCLAMATION) if dlg1.ShowModal() == wx.ID_OK: directory = tup[0] if not directory.endswith('/'): directory += '/' path = directory + mfile final_path = ac.convert_to_wav( path, outputpath=os.getcwd() + '/music/' + str(hash(path)) + '.wav') self.playlist.addSong({ 'path': final_path, 'name': song, 'album': album, 'artist': 'None', 'thumb': 'None' }) dlg1.Destroy() return True return False
def add_file(self, event): """ Opens file dialog to browse for music """ wildcard = """MP3 (*.mp3)|*.mp3| WAV (*.wav)|*.wav| FLAC (*.flac)|*.flac| ALL (*)|*""" dlg = wx.FileDialog(self, message="Choose a file", defaultDir=self.mediaFolder, defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() if path.split('.')[-1] != 'wav': final_path = ac.convert_to_wav(path, outputpath=os.getcwd() + '/music/' + str(hash(path)) + '.wav') else: final_path = path name = path.split('/')[-1].split('.')[0] album = path.split('/')[-2] self.playlist.addSong({ 'path': final_path, 'name': name, 'album': album, 'artist': 'None', 'thumb': 'None' }) dlg.Destroy()
def search_media_for_file(self, query): """return bool of wather or not file is found, if file is found pass it to playlist""" print(self.mediaFolder) for tup in os.walk(self.mediaFolder): for mfile in tup[2]: if mfile.endswith('/'): continue song = mfile.split('.')[0] if query not in song: continue print("sucess") album = tup[0].split('/')[-2] TEXT = "Is this the song you where searching for?\nSong: " + song + "\nAlbum: " + album dlg1 = wx.MessageDialog(None,caption="Confirm Download:", message=str(TEXT) ,style=wx.OK|wx.CANCEL|wx.ICON_EXCLAMATION) if dlg1.ShowModal() == wx.ID_OK: directory = tup[0] if not directory.endswith('/'): directory += '/' path = directory+mfile final_path = ac.convert_to_wav(path,outputpath=os.getcwd()+'/music/'+str(hash(path))+'.wav') self.playlist.addSong({'path':final_path,'name':song,'album':album, 'artist':'None','thumb':'None'}) dlg1.Destroy() return True return False
def add_file(self, event): """ Opens file dialog to browse for music """ wildcard = """MP3 (*.mp3)|*.mp3| WAV (*.wav)|*.wav| FLAC (*.flac)|*.flac| ALL (*)|*""" dlg = wx.FileDialog( self, message="Choose a file", defaultDir=self.mediaFolder, defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR ) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() if path.split('.')[-1] != 'wav': final_path = ac.convert_to_wav(path,outputpath=os.getcwd()+'/music/'+str(hash(path))+'.wav') else: final_path = path name = path.split('/')[-1].split('.')[0] album = path.split('/')[-2] self.playlist.addSong({'path':final_path,'name':name,'album':album, 'artist':'None','thumb':'None'}) dlg.Destroy()
def search_torrents(self, event): query = self.search_bar.GetValue() if self.search_media_for_file(query): return try: meta_data = sr.get_metadata_from_server(query) if meta_data == None: Text = "No Torrent Found" dlg1 = wx.MessageDialog(None, caption="Confirm Download:", message=str(Text), style=wx.OK | wx.ICON_EXCLAMATION) if dlg1.ShowModal() == wx.ID_OK: dlg1.Destroy() return open_meta_data = json.loads(meta_data) except (requests.exceptions.RequestException): print "server not up" return Text = "Was this the file you were looking for?\nSong: " + open_meta_data[ 'title'] + "\nAlbum: " + open_meta_data[ 'album'] + "\nArtist: " + open_meta_data['artist'] dlg1 = wx.MessageDialog(None, caption="Confirm Download:", message=str(Text), style=wx.OK | wx.CANCEL | wx.ICON_EXCLAMATION) if dlg1.ShowModal() == wx.ID_OK: download_hash = sr.init_download_on_server(meta_data) dlg1.Destroy() download_hash = sr.init_download_on_server(meta_data) else: return data = None while data is None: data, ctype = sr.poll_server(download_hash) time.sleep(2) if ctype == 'audio/mpeg': filepath = 'music/' + open_meta_data['title'] + '.mp3' fileout = open(filepath, 'wb') fileout.write(data) finalpath = ac.convert_to_wav(filepath, outputpath=os.getcwd() + '/music/' + str(hash(filepath)) + '.wav') open_meta_data['path'] = finalpath open_meta_data['name'] = open_meta_data['title'] os.remove(filepath) self.playlist.addSong(open_meta_data) if ctype == 'audio/m4a': filepath = 'music/' + open_meta_data['title'] + '.m4a' fileout = open(filepath, 'wb') fileout.write(data) finalpath = ac.convert_to_wav(filepath, outputpath=os.getcwd() + '/music/' + str(hash(filepath)) + '.wav') open_meta_data['path'] = finalpath open_meta_data['name'] = open_meta_data['title'] os.remove(filepath) self.playlist.addSong(open_meta_data) if ctype == 'audio/x-flac': filepath = 'music/' + open_meta_data['title'] + '.flac' fileout = open(filepath, 'wb') fileout.write(data) finalpath = ac.convert_to_wav(filepath, outputpath=os.getcwd() + '/music/' + str(hash(filepath)) + '.wav') open_meta_data['path'] = finalpath open_meta_data['name'] = open_meta_data['title'] os.remove(filepath) self.playlist.addSong(open_meta_data) if ctype == 'audio/x-wav': filepath = 'music/' + open_meta_data['title'] + '.wav' fileout = open(filepath, 'wb') fileout.write(data) open_meta_data['path'] = filepath open_meta_data['name'] = open_meta_data['title'] self.playlist.addSong(open_meta_data)