Added _format and bitrate parameters to the transcoder so it will be more flexible. The default for mp3 now is 320 KBPS

This commit is contained in:
Manuel Cortez 2019-06-20 17:24:56 -05:00
parent 7786a31c2c
commit edc46ee824

View File

@ -110,7 +110,7 @@ class audioPlayer(object):
#https://github.com/ZeBobo5/Vlc.DotNet/issues/4 #https://github.com/ZeBobo5/Vlc.DotNet/issues/4
call_threaded(self.next) call_threaded(self.next)
def transcode_audio(self, item, path): def transcode_audio(self, item, path, _format="mp3", bitrate=320):
""" Converts given item to mp3. This method will be available when needed automatically.""" """ Converts given item to mp3. This method will be available when needed automatically."""
if item.download_url == "": if item.download_url == "":
item.get_download_url() item.get_download_url()
@ -118,7 +118,7 @@ class audioPlayer(object):
temporary_filename = "chunk_{0}".format(random.randint(0,2000000)) temporary_filename = "chunk_{0}".format(random.randint(0,2000000))
temporary_path = os.path.join(os.path.dirname(path), temporary_filename) temporary_path = os.path.join(os.path.dirname(path), temporary_filename)
# Let's get a new VLC instance for transcoding this file. # Let's get a new VLC instance for transcoding this file.
transcoding_instance = vlc.Instance(*["--sout=#transcode{acodec=mp3,ab=192}:file{mux=raw,dst=\"%s\"}"% (temporary_path,)]) transcoding_instance = vlc.Instance(*["--sout=#transcode{acodec=%s,ab=%d}:file{mux=raw,dst=\"%s\"}"% (_format, bitrate, temporary_path,)])
transcoder = transcoding_instance.media_player_new() transcoder = transcoding_instance.media_player_new()
transcoder.set_mrl(item.download_url) transcoder.set_mrl(item.download_url)
pub.sendMessage("change_status", status=_(u"Downloading {0}.").format(item.title,)) pub.sendMessage("change_status", status=_(u"Downloading {0}.").format(item.title,))