Repository: beetbox/beets

Issue:
convert: `max_bitrate` config option should default to none
<!--
Describe your problem, feature request, or discussion topic here.

Please fill out this and the "Setup" section below and remember to include
enough detail so that other people can reproduce the problem.
-->

### Problem

Convert plugin's parameter ```max_bitrate``` has default value of ```500``` (see line 139 in ```beetsplug/convert.py```), but in docs it's ```none```.
This results in unexpected copying instead of transcoding.
I'd expect ```none``` to be a reasonable default.

### Setup

Irrelevant
convert: `max_bitrate` config option should default to none
<!--
Describe your problem, feature request, or discussion topic here.

Please fill out this and the "Setup" section below and remember to include
enough detail so that other people can reproduce the problem.
-->

### Problem

Convert plugin's parameter ```max_bitrate``` has default value of ```500``` (see line 139 in ```beetsplug/convert.py```), but in docs it's ```none```.
This results in unexpected copying instead of transcoding.
I'd expect ```none``` to be a reasonable default.

### Setup

Irrelevant


Discussion:
Huh, you're absolutely right! Not sure how that default slipped in there:
https://github.com/beetbox/beets/blob/50bd693057de472470ab5175fae0cdb5b75811c6/beetsplug/convert.py#L139
Huh, you're absolutely right! Not sure how that default slipped in there:
https://github.com/beetbox/beets/blob/50bd693057de472470ab5175fae0cdb5b75811c6/beetsplug/convert.py#L139

Resolving patch:
diff --git a/beetsplug/convert.py b/beetsplug/convert.py
--- a/beetsplug/convert.py
+++ b/beetsplug/convert.py
@@ -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
@@ -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
 
@@ -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,


Test patch:
diff --git a/test/test_convert.py b/test/test_convert.py
--- a/test/test_convert.py
+++ b/test/test_convert.py
@@ -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': {
@@ -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,
@@ -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',