Merge pull request #148 from shirt-dev/bitrate-selection

Fix audio copy, set bitrate based on account type if not in config
This commit is contained in:
Footsiefat 2021-10-27 09:37:10 +13:00 committed by GitHub
commit 16ade2d5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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):