Fixed all audio methods due to latest VK changes
This commit is contained in:
parent
5f224a077c
commit
4f3bb6ac93
@ -18,6 +18,7 @@
|
||||
|
||||
### Changes
|
||||
|
||||
* Updated method for accessing audio files due to the latest changes on VK apps.
|
||||
* When changing volume of the playing audio, it will decrease or increase the volume by 2% instead of 5%.
|
||||
* Read confirmations will be sent to VK as soon as you read the message. Before, read confirmations were being sent every 3 minutes to the social network.
|
||||
|
||||
|
@ -324,6 +324,7 @@ class Controller(object):
|
||||
@ filename: the current path to where the file will be saved.
|
||||
The dowwload progress will be displayed in the status bar on the window.
|
||||
"""
|
||||
url = utils.transform_audio_url(url)
|
||||
log.debug("downloading %s URL to %s filename" % (url, filename,))
|
||||
call_threaded(utils.download_file, url, filename, self.window)
|
||||
|
||||
|
@ -14,6 +14,7 @@ from sound_lib.main import BassError
|
||||
from pubsub import pub
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
from mysc.thread_utils import call_threaded
|
||||
from sessionmanager import utils
|
||||
|
||||
player = None
|
||||
log = logging.getLogger("player")
|
||||
@ -76,10 +77,11 @@ class audioPlayer(object):
|
||||
if self.is_working == False:
|
||||
self.is_working = True
|
||||
# Let's encode the URL as bytes if on Python 3
|
||||
url_ = bytes(object["url"], "utf-8")
|
||||
url_ = utils.transform_audio_url(object["url"])
|
||||
url_ = bytes(url_, "utf-8")
|
||||
try:
|
||||
self.stream = URLStream(url=url_)
|
||||
except IndexError:
|
||||
except:
|
||||
log.error("Unable to play URL %s" % (url_))
|
||||
return
|
||||
# Translators: {0} will be replaced with a song's title and {1} with the artist.
|
||||
@ -187,4 +189,3 @@ class audioPlayer(object):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
@ -73,3 +73,15 @@ def clean_text(text):
|
||||
text = detect_users(text)
|
||||
text = html.unescape(text)
|
||||
return text
|
||||
|
||||
def transform_audio_url(url):
|
||||
""" Transforms the URL offered by VK to the unencrypted stream so we can still play it. """
|
||||
if "vkuseraudio.net" not in url and "index.m3u8" not in url:
|
||||
return url
|
||||
url = url.replace("/index.m3u8", ".mp3")
|
||||
parts = url.split("/")
|
||||
if "/audio" not in url:
|
||||
url = url.replace("/"+parts[-2], "")
|
||||
else:
|
||||
url = url.replace("/"+parts[-3], "")
|
||||
return url
|
Loading…
Reference in New Issue
Block a user