Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autotagger: match file name if the file has no title metadata #5147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion beets/autotag/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


import datetime
import os
import re
from collections import namedtuple
from typing import (
Expand Down Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 8 additions & 0 deletions test/test_autotag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading