Fix audio copy, set bitrate based on account type if not in config

This commit is contained in:
shirt 2021-10-26 16:14:31 -04:00
parent b279125a9c
commit 27d6c791ce
No known key found for this signature in database
GPG Key ID: 89EC2E5F699F79E6
2 changed files with 12 additions and 3 deletions

View File

@ -122,8 +122,7 @@ CONFIG_DEFAULT_SETTINGS = {
'ROOT_PATH': '../ZSpotify Music/',
'ROOT_PODCAST_PATH': '../ZSpotify Podcasts/',
'SKIP_EXISTING_FILES': True,
'DOWNLOAD_FORMAT': 'mp3',
'BITRATE': '160k',
'DOWNLOAD_FORMAT': 'ogg',
'FORCE_PREMIUM': False,
'ANTI_BAN_WAIT_TIME': 1,
'OVERRIDE_AUTO_WAIT': False,

View File

@ -2,6 +2,7 @@ import os
import time
from typing import Any, Tuple, List
from librespot.audio.decoders import AudioQuality
from librespot.metadata import TrackId
from ffmpy import FFmpeg
from tqdm import tqdm
@ -129,13 +130,22 @@ def convert_audio_format(filename) -> None:
file_codec = CODEC_MAP.get(download_format, "copy")
if file_codec != 'copy':
bitrate = ZSpotify.get_config(BITRATE)
if not bitrate:
if ZSpotify.DOWNLOAD_QUALITY == AudioQuality.VERY_HIGH:
bitrate = '320k'
else:
bitrate = '160k'
else:
bitrate = None
output_params = ['-c:a', file_codec]
if bitrate:
output_params += ['-b:a', bitrate]
ff_m = FFmpeg(
global_options=['-y', '-hide_banner', '-loglevel error'],
inputs={temp_filename: None},
outputs={filename: ['-c:a', file_codec] + ['-b:a', bitrate] if bitrate else []}
outputs={filename: output_params}
)
ff_m.run()
if os.path.exists(temp_filename):