Commit d91c4f4c authored by Manuel Cortez's avatar Manuel Cortez

Multiupload attempt #1

parent f3aeb9f6
......@@ -815,7 +815,6 @@ class audioBuffer(feedBuffer):
output.speak(_("{0} errors occurred while attempting to add {1} audios to your playlist.").format(errors_detected, len(selected)))
def get_menu(self):
p = self.get_post()
if p == None:
......@@ -824,6 +823,7 @@ class audioBuffer(feedBuffer):
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_post,
widgetUtils.connect_event(m, widgetUtils.MENU, self.play_audio,
widgetUtils.connect_event(m, widgetUtils.MENU, self.move_to_album, menuitem=m.move)
widgetUtils.connect_event(m, widgetUtils.MENU,,
# if owner_id is the current user, the audio is added to the user's audios.
if p["owner_id"] == self.session.user_id:
......@@ -831,6 +831,7 @@ class audioBuffer(feedBuffer):
widgetUtils.connect_event(m, widgetUtils.MENU, self.add_to_library, menuitem=m.library)
return m
def post(self, *args, **kwargs):
""" Uploads an audio to the current user's library from the computer. """
file =
......@@ -865,6 +866,35 @@ class audioBuffer(feedBuffer):
def __del__(self):
pub.unsubscribe(self.change_label, "playback-changed")
def download(self, *args, **kwargs):
selected =
if len(selected) < 1:
audios = [self.session.db[]["items"][audio] for audio in selected]
if len(audios) == 0:
elif len(audios) == 1:
multiple = False
filename = utils.safe_filename("{0} - {1}.mp3".format(audios[0]["title"], audios[0]["artist"]))
multiple = True
filename = "" # No default filename for multiple files.
path =, multiple=multiple)
call_threaded(self.download_threaded, path, multiple, audios)
def download_threaded(self, path, multiple, audios):
if multiple == False:
url = audios[0]["url"]
pub.sendMessage("download-file", url=url, filename=filename)
downloads = []
for i in audios:
filename = utils.safe_filename("{0} - {1}.mp3".format(i["title"], i["artist"]))
filepath = os.path.join(path, filename)
downloads.append((utils.transform_audio_url(i["url"]), filepath))
pub.sendMessage("download-files", downloads)
class audioAlbum(audioBuffer):
""" this buffer was supposed to be used with audio albums
but is deprecated as VK removed its audio support for third party apps."""
......@@ -307,6 +307,7 @@ class Controller(object):
pub.subscribe(self.in_post, "posted")
pub.subscribe(self.post_failed, "postFailed")
pub.subscribe(, "download-file")
pub.subscribe(self.download_files, "download-files")
pub.subscribe(self.view_post, "open-post")
pub.subscribe(self.update_status_bar, "update-status-bar")
pub.subscribe(self.chat_from_id, "new-chat")
......@@ -403,6 +404,9 @@ class Controller(object):
log.debug("downloading %s URL to %s filename" % (url, filename,))
call_threaded(utils.download_file, url, filename, self.window)
def download_files(self, downloads):
call_threaded(utils.download_files, downloads, self.window)
def view_post(self, post_object, controller_, vars=dict()):
""" Display the passed post in the passed post presenter.
@ post_object dict: A post representation returned by the VK api. The fields present in this dict are different depending on the presenter used to render it.
......@@ -58,6 +58,10 @@ def download_file(url, local_filename, window):
return local_filename
def download_files(downloads, window):
for download in downloads:
download_file(download[0], download[1], window)
def detect_users(text):
""" Detect all users and communities mentionned in any text posted in VK."""
# This regexp gets group and users mentionned in topic comments.
......@@ -31,7 +31,7 @@ class audioMenu(wx.Menu): = self.Append(wx.NewId(), _("&Play"))
self.library = self.Append(wx.NewId(), _("&Add to library"))
self.move = self.Append(wx.NewId(), _("Move to album"))
# self.open_in_browser = self.Append(wx.NewId(), _("Open in")) = self.Append(wx.NewId(), _("Download"))
class peopleMenu(wx.Menu):
def __init__(self, is_request=False, is_subscriber=False, not_friend=False, *args, **kwargs):
......@@ -8,7 +8,7 @@ class homeTab(wx.Panel):
def create_list(self):
self.lbl = wx.StaticText(self, wx.NewId(), _("Po&sts"))
self.list = widgetUtils.list(self, *[_("User"), _("Text"), _("Date")], style=wx.LC_REPORT)
self.list = widgetUtils.list(self, *[_("User"), _("Text"), _("Date")], style=wx.LC_REPORT, name=_("Posts"))
self.list.set_windows_size(0, 200)
self.list.set_windows_size(1, 300)
self.list.set_windows_size(2, 250)
......@@ -64,7 +64,7 @@ class communityTab(feedTab):
class audioTab(homeTab):
def create_list(self):
self.lbl = wx.StaticText(self, wx.NewId(), _("Mu&sic"))
self.list = widgetUtils.multiselectionList(self, *[_("Title"), _("Artist"), _("Duration")], style=wx.LC_REPORT)
self.list = widgetUtils.multiselectionList(self, *[_("Title"), _("Artist"), _("Duration")], style=wx.LC_REPORT, name=_("Music"))
self.list.set_windows_size(0, 160)
self.list.set_windows_size(1, 380)
self.list.set_windows_size(2, 80)
......@@ -87,6 +87,15 @@ class audioTab(homeTab):
return None
return openFileDialog.GetPath()
def get_download_path(self, filename="", multiple=False):
if multiple == False:
d = wx.FileDialog(self, _("Save this file"), "", filename, _("Audio Files(*.mp3)|*.mp3"), wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
d = wx.DirDialog(None, _("Select a folder to save all files"))
if d.ShowModal() == wx.ID_OK:
return d.GetPath()
class audioAlbumTab(audioTab):
def create_post_buttons(self):
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment