Skip to content

Commit

Permalink
Merge pull request #4504 from Tomasito665/fix_max_bitrate_default
Browse files Browse the repository at this point in the history
Fix #4472 - set 'max_bitrate' default param to none
  • Loading branch information
sampsyo authored Oct 3, 2022
2 parents 7db0209 + 1ebcbf6 commit e7290c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions beetsplug/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from beets import ui, util, plugins, config
from beets.plugins import BeetsPlugin
from confuse import ConfigTypeError
from confuse import ConfigTypeError, Optional
from beets import art
from beets.util.artresizer import ArtResizer
from beets.library import parse_query_string
Expand Down Expand Up @@ -101,7 +101,9 @@ def should_transcode(item, fmt):
if config['convert']['never_convert_lossy_files'] and \
not (item.format.lower() in LOSSLESS_FORMATS):
return False
maxbr = config['convert']['max_bitrate'].get(int)
maxbr = config['convert']['max_bitrate'].get(Optional(int))
if maxbr is None:
return False
return fmt.lower() != item.format.lower() or \
item.bitrate >= 1000 * maxbr

Expand Down Expand Up @@ -136,7 +138,7 @@ def __init__(self):
'wma':
'ffmpeg -i $source -y -vn -acodec wmav2 -vn $dest',
},
'max_bitrate': 500,
'max_bitrate': None,
'auto': False,
'auto_keep': False,
'tmpdir': None,
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ New features:

Bug fixes:

* :doc:`/plugins/convert`: Set default ``max_bitrate`` value to ``None`` to
avoid transcoding when this parameter is not set. :bug:`4472`
* :doc:`/plugins/replaygain`: Avoid a crash when errors occur in the analysis
backend.
:bug:`4506`
Expand Down
11 changes: 11 additions & 0 deletions test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def setUp(self):
)
self.config['convert'] = {
'dest': self.convert_dest,
# Enforce running convert
'max_bitrate': 1,
'paths': {'default': 'converted'},
'format': 'mp3',
'formats': {
Expand Down Expand Up @@ -249,6 +251,13 @@ def test_empty_query(self):
self.run_convert('An impossible query')
self.assertEqual(logs[0], 'convert: Empty query result.')

def test_no_transcode_when_max_bitrate_set_to_none(self):
self.config['convert']['max_bitrate'] = None
with control_stdin('y'):
self.run_convert()
converted = os.path.join(self.convert_dest, b'converted.ogg')
self.assertNoFileTag(converted, 'mp3')


@_common.slow_test()
class NeverConvertLossyFilesTest(unittest.TestCase, TestHelper,
Expand All @@ -263,6 +272,8 @@ def setUp(self):
self.convert_dest = os.path.join(self.temp_dir, b'convert_dest')
self.config['convert'] = {
'dest': self.convert_dest,
# Enforce running convert
'max_bitrate': 1,
'paths': {'default': 'converted'},
'never_convert_lossy_files': True,
'format': 'mp3',
Expand Down

0 comments on commit e7290c3

Please sign in to comment.