Skip to content

Commit d0af7a7

Browse files
committed
Merge branch '2738-filename-tracknumber' of https://github.com/Vrihub/beets into 2738-filename-tracknumber
2 parents 4ee5f2c + 39f211e commit d0af7a7

File tree

10 files changed

+60
-11
lines changed

10 files changed

+60
-11
lines changed

beets/config_default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import:
1010
delete: no
1111
resume: ask
1212
incremental: no
13+
from_scratch: no
1314
quiet_fallback: skip
1415
none_rec_action: ask
1516
timid: no

beets/importer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ def imported_items(self):
534534
def apply_metadata(self):
535535
"""Copy metadata from match info to the items.
536536
"""
537+
if config['import']['from_scratch']:
538+
for item in self.match.mapping:
539+
item.clear()
540+
537541
autotag.apply_metadata(self.match.info, self.match.mapping)
538542

539543
def duplicate_items(self, lib):

beets/library.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ def update(self, values):
561561
if self.mtime == 0 and 'mtime' in values:
562562
self.mtime = values['mtime']
563563

564+
def clear(self):
565+
"""Set all key/value pairs to None."""
566+
for key in self._media_fields:
567+
setattr(self, key, None)
568+
564569
def get_album(self):
565570
"""Get the Album object that this item belongs to, if any, or
566571
None if the item is a singleton or is not associated with a

beets/ui/commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,10 @@ def import_func(lib, opts, args):
10041004
u'-I', u'--noincremental', dest='incremental', action='store_false',
10051005
help=u'do not skip already-imported directories'
10061006
)
1007+
import_cmd.parser.add_option(
1008+
u'--from-scratch', dest='from_scratch', action='store_true',
1009+
help=u'erase existing metadata before applying new metadata'
1010+
)
10071011
import_cmd.parser.add_option(
10081012
u'--flat', dest='flat', action='store_true',
10091013
help=u'import an entire tree as a single album'

beets/util/artresizer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ def im_resize(maxwidth, path_in, path_out=None):
8888
log.debug(u'artresizer: ImageMagick resizing {0} to {1}',
8989
util.displayable_path(path_in), util.displayable_path(path_out))
9090

91-
# "-resize widthxheight>" shrinks images with dimension(s) larger
92-
# than the corresponding width and/or height dimension(s). The >
93-
# "only shrink" flag is prefixed by ^ escape char for Windows
94-
# compatibility.
91+
# "-resize WIDTHx>" shrinks images with the width larger
92+
# than the given width while maintaining the aspect ratio
93+
# with regards to the height.
9594
try:
9695
util.command_output([
9796
'convert', util.syspath(path_in, prefix=False),
98-
'-resize', '{0}x^>'.format(maxwidth),
97+
'-resize', '{0}x>'.format(maxwidth),
9998
util.syspath(path_out, prefix=False),
10099
])
101100
except subprocess.CalledProcessError:

beetsplug/duplicates.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,19 @@ def _order(self, objs, tiebreak=None):
253253
"completeness" (objects with more non-null fields come first)
254254
and Albums are ordered by their track count.
255255
"""
256-
if tiebreak:
257-
kind = 'items' if all(isinstance(o, Item)
258-
for o in objs) else 'albums'
256+
kind = 'items' if all(isinstance(o, Item) for o in objs) else 'albums'
257+
258+
if tiebreak and kind in tiebreak.keys():
259259
key = lambda x: tuple(getattr(x, k) for k in tiebreak[kind])
260260
else:
261-
kind = Item if all(isinstance(o, Item) for o in objs) else Album
262-
if kind is Item:
261+
if kind == 'items':
263262
def truthy(v):
264263
# Avoid a Unicode warning by avoiding comparison
265264
# between a bytes object and the empty Unicode
266265
# string ''.
267266
return v is not None and \
268267
(v != '' if isinstance(v, six.text_type) else True)
269-
fields = kind.all_keys()
268+
fields = Item.all_keys()
270269
key = lambda x: sum(1 for f in fields if truthy(getattr(x, f)))
271270
else:
272271
key = lambda x: len(x.items())

docs/changelog.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ New features:
3434
* :doc:`/plugins/acousticbrainz`: The plugin can now be configured to write only
3535
a specific list of tags.
3636
Thanks to :user:`woparry`.
37+
* A new :ref:`from_scratch` configuration option makes the importer remove old
38+
metadata before applying new metadata.
39+
Thanks to :user:`tummychow`.
40+
:bug:`934` :bug:`2755`
3741

3842
Fixes:
3943

@@ -70,6 +74,10 @@ Fixes:
7074
Python 3 on Windows with non-ASCII filenames. :bug:`2671`
7175
* :doc:`/plugins/absubmit`: Fix an occasional crash on Python 3 when the AB
7276
analysis tool produced non-ASCII metadata. :bug:`2673`
77+
* :doc:`/plugins/duplicates`: Use default tiebreak for any kind (item/album) that
78+
does not have a tiebreak specified in the configuration.
79+
Thanks to :user:`cgevans`.
80+
:bug:`2758`
7381
* :doc:`/plugins/duplicates`: Fix the `--key` command line option, which was
7482
ignored.
7583
* :doc:`/plugins/replaygain`: Fix album replaygain calculation with the
@@ -82,6 +90,9 @@ Fixes:
8290
with no following numbers. Thanks to :user:`eigengrau`. :bug:`2741`
8391
* :doc:`/plugins/fromfilename`: Allow file names such as "01.mp3" to extract the track number.
8492
Also allow "_" as a separator. Refactor some regular expressions. :bug:`2738`
93+
* Fixed an issue where images would be resized according to their longest edge,
94+
instead of their width. Thanks to :user:`sekjun9878`. :bug:`2729`
95+
8596

8697
For developers:
8798

docs/reference/cli.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ Optional command flags:
111111
time, when no subdirectories will be skipped. So consider enabling the
112112
``incremental`` configuration option.
113113

114+
* When beets applies metadata to your music, it will retain the value of any
115+
existing tags that weren't overwritten, and import them into the database. You
116+
may prefer to only use existing metadata for finding matches, and to erase it
117+
completely when new metadata is applied. You can enforce this behavior with
118+
the ``--from-scratch`` option, or the ``from_scratch`` configuration option.
119+
114120
* By default, beets will proceed without asking if it finds a very close
115121
metadata match. To disable this and have the importer ask you every time,
116122
use the ``-t`` (for *timid*) option.

docs/reference/config.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ Either ``yes`` or ``no``, controlling whether imported directories are
475475
recorded and whether these recorded directories are skipped. This
476476
corresponds to the ``-i`` flag to ``beet import``.
477477

478+
.. _from_scratch:
479+
480+
from_scratch
481+
~~~~~~~~~~~~
482+
483+
Either ``yes`` or ``no`` (default), controlling whether existing metadata is
484+
discarded when a match is applied. This corresponds to the ``--from_scratch``
485+
flag to ``beet import``.
486+
478487
quiet_fallback
479488
~~~~~~~~~~~~~~
480489

test/test_importer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,17 @@ def test_apply_candidate_adds_album_path(self):
633633
self.assert_file_in_lib(
634634
b'Applied Artist', b'Applied Album', b'Applied Title 1.mp3')
635635

636+
def test_apply_from_scratch_removes_other_metadata(self):
637+
config['import']['from_scratch'] = True
638+
639+
for mediafile in self.import_media:
640+
mediafile.genre = u'Tag Genre'
641+
mediafile.save()
642+
643+
self.importer.add_choice(importer.action.APPLY)
644+
self.importer.run()
645+
self.assertEqual(self.lib.items().get().genre, u'')
646+
636647
def test_apply_with_move_deletes_import(self):
637648
config['import']['move'] = True
638649

0 commit comments

Comments
 (0)