Multiupload attempt #1

This commit is contained in:
Manuel Cortez 2019-12-04 12:45:47 -06:00
parent f3aeb9f61b
commit d91c4f4cf2
5 changed files with 51 additions and 4 deletions

View File

@ -815,7 +815,6 @@ class audioBuffer(feedBuffer):
else:
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, menuitem=m.open)
widgetUtils.connect_event(m, widgetUtils.MENU, self.play_audio, menuitem=m.play)
widgetUtils.connect_event(m, widgetUtils.MENU, self.move_to_album, menuitem=m.move)
widgetUtils.connect_event(m, widgetUtils.MENU, self.download, menuitem=m.download)
# if owner_id is the current user, the audio is added to the user's audios.
if p["owner_id"] == self.session.user_id:
m.library.SetItemLabel(_("&Remove"))
@ -831,6 +831,7 @@ class audioBuffer(feedBuffer):
else:
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 = self.tab.get_file_to_upload()
@ -865,6 +866,35 @@ class audioBuffer(feedBuffer):
def __del__(self):
pub.unsubscribe(self.change_label, "playback-changed")
def download(self, *args, **kwargs):
selected = self.tab.list.get_multiple_selection()
if len(selected) < 1:
return
audios = [self.session.db[self.name]["items"][audio] for audio in selected]
if len(audios) == 0:
return
elif len(audios) == 1:
multiple = False
filename = utils.safe_filename("{0} - {1}.mp3".format(audios[0]["title"], audios[0]["artist"]))
else:
multiple = True
filename = "" # No default filename for multiple files.
path = self.tab.get_download_path(filename=filename, 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)
return
else:
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."""

View File

@ -307,6 +307,7 @@ class Controller(object):
pub.subscribe(self.in_post, "posted")
pub.subscribe(self.post_failed, "postFailed")
pub.subscribe(self.download, "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.

View File

@ -58,6 +58,10 @@ def download_file(url, local_filename, window):
window.change_status(_("Ready"))
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.

View File

@ -31,7 +31,7 @@ class audioMenu(wx.Menu):
self.play = 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 vk.com"))
self.download = self.Append(wx.NewId(), _("Download"))
class peopleMenu(wx.Menu):
def __init__(self, is_request=False, is_subscriber=False, not_friend=False, *args, **kwargs):

View File

@ -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)
else:
d = wx.DirDialog(None, _("Select a folder to save all files"))
if d.ShowModal() == wx.ID_OK:
return d.GetPath()
d.Destroy()
class audioAlbumTab(audioTab):
def create_post_buttons(self):