Allows uploading audio directly from the 'my audios' buffer

This commit is contained in:
Manuel Cortez 2019-02-26 13:57:37 -06:00
parent 0821565a75
commit b3f5c532dd
2 changed files with 27 additions and 4 deletions

View File

@ -16,6 +16,7 @@ from pubsub import pub
from vk_api.exceptions import VkApiError from vk_api.exceptions import VkApiError
from vk_api import upload from vk_api import upload
from requests.exceptions import ReadTimeout, ConnectionError from requests.exceptions import ReadTimeout, ConnectionError
from mutagen.id3 import ID3
from presenters import player from presenters import player
from wxUI.tabs import home from wxUI.tabs import home
from sessionmanager import session, renderers, utils from sessionmanager import session, renderers, utils
@ -577,8 +578,8 @@ class audioBuffer(feedBuffer):
self.tab = home.audioTab(parent) self.tab = home.audioTab(parent)
self.tab.name = self.name self.tab.name = self.name
self.connect_events() self.connect_events()
if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"): if self.name == "me_audio":
self.tab.post.Enable(False) self.tab.post.Enable(True)
def connect_events(self): def connect_events(self):
widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio) widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio)
@ -705,6 +706,22 @@ class audioBuffer(feedBuffer):
else: else:
widgetUtils.connect_event(m, widgetUtils.MENU, self.add_to_library, menuitem=m.library) widgetUtils.connect_event(m, widgetUtils.MENU, self.add_to_library, menuitem=m.library)
return m 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()
if file == None:
return
audio_tags = ID3(file)
if "TIT2" in audio_tags:
title = audio_tags["TIT2"].text[0]
else:
title = _("Untitled")
if "TPE1" in audio_tags:
artist = audio_tags["TPE1"].text[0]
else:
artist = _("Unknown artist")
uploader = upload.VkUpload(self.session.vk.session_object)
call_threaded(uploader.audio, file, title=title, artist=artist)
class audioAlbum(audioBuffer): class audioAlbum(audioBuffer):
""" this buffer was supposed to be used with audio albums """ this buffer was supposed to be used with audio albums

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#from __future__ import unicode_literals
from __future__ import unicode_literals from __future__ import unicode_literals
import wx import wx
import widgetUtils import widgetUtils
@ -74,13 +73,20 @@ class audioTab(homeTab):
def create_post_buttons(self): def create_post_buttons(self):
self.postBox = wx.StaticBoxSizer(parent=self, orient=wx.HORIZONTAL, label=_("Actions")) self.postBox = wx.StaticBoxSizer(parent=self, orient=wx.HORIZONTAL, label=_("Actions"))
self.post = wx.Button(self.postBox.GetStaticBox(), -1, _("&Post")) self.post = wx.Button(self.postBox.GetStaticBox(), -1, _("&Upload audio"))
self.post.Enable(False)
self.play = wx.Button(self.postBox.GetStaticBox(), -1, _("P&lay")) self.play = wx.Button(self.postBox.GetStaticBox(), -1, _("P&lay"))
self.play_all = wx.Button(self.postBox.GetStaticBox(), -1, _("Play &All")) self.play_all = wx.Button(self.postBox.GetStaticBox(), -1, _("Play &All"))
self.postBox.Add(self.post, 0, wx.ALL, 5) self.postBox.Add(self.post, 0, wx.ALL, 5)
self.postBox.Add(self.play, 0, wx.ALL, 5) self.postBox.Add(self.play, 0, wx.ALL, 5)
self.postBox.Add(self.play_all, 0, wx.ALL, 5) self.postBox.Add(self.play_all, 0, wx.ALL, 5)
def get_file_to_upload(self):
openFileDialog = wx.FileDialog(self, _("Select the audio file to be uploaded"), "", "", _("Audio files (*.mp3)|*.mp3"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return None
return openFileDialog.GetPath()
class audioAlbumTab(audioTab): class audioAlbumTab(audioTab):
def create_post_buttons(self): def create_post_buttons(self):