diff --git a/beets/autotag/match.py b/beets/autotag/match.py index c79eba2d7e..7454d71897 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -18,6 +18,7 @@ import datetime +import os import re from collections import namedtuple from typing import ( @@ -185,7 +186,8 @@ def track_distance( dist.add_ratio("track_length", diff, track_length_max) # Title. - dist.add_string("track_title", item.title, track_info.title) + cur_title = item.title or os.fsdecode(os.path.basename(item.path)) + dist.add_string("track_title", cur_title, track_info.title) # Artist. Only check if there is actually an artist in the track data. if ( diff --git a/docs/changelog.rst b/docs/changelog.rst index 0b5e195774..1287557723 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -158,6 +158,7 @@ New features: * :doc:`/plugins/convert`: Don't treat WAVE (`.wav`) files as lossy anymore when using the `never_convert_lossy_files` option. They will get transcoded like the other lossless formats. +* The autotagger matches the file name if the track has no ``title`` metadata. Bug fixes: diff --git a/test/test_autotag.py b/test/test_autotag.py index 44c68ce9a1..474f129ebe 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -356,6 +356,14 @@ def test_various_artists_tolerated(self): dist = match.track_distance(item, info, incl_artist=True) self.assertEqual(dist, 0.0) + def test_missing_metadata(self): + item = _make_item("", 0) + info = _make_trackinfo()[0] + dist1 = match.track_distance(item, info) + item.path = b"/tmp/01 One.mp3" + dist2 = match.track_distance(item, info) + self.assertLess(dist2, dist1) + class AlbumDistanceTest(_common.TestCase): def _mapping(self, items, info):