PICARD-2780: Fix checking "video" flag in track comparison

The MB API can return "null" for the video flag of a recording. This was
not considered False in the check.
This commit is contained in:
Philipp Wolfer
2023-10-26 15:04:50 +02:00
parent 1e33a4c357
commit 618c4f2104
3 changed files with 119 additions and 1 deletions

View File

@@ -373,7 +373,7 @@ class Metadata(MutableMapping):
if 'isvideo' in weights:
metadata_is_video = self['~video'] == '1'
track_is_video = track.get('video', False)
track_is_video = bool(track.get('video'))
score = 1 if metadata_is_video == track_is_video else 0
parts.append((score, weights['isvideo']))

View File

@@ -0,0 +1,106 @@
{
"id": "46b97aca-a524-4993-8ec5-93c736081442",
"score": 100,
"title": "Lune",
"length": 567032,
"video": null,
"artist-credit": [
{
"name": "Tim Green",
"artist": {
"id": "5103b22e-514f-46b1-afdf-c99517c791e2",
"name": "Tim Green",
"sort-name": "Tim Green",
"disambiguation": "UK House artist aka \"TG\", started activity in the 2000s",
"aliases": [
{
"sort-name": "TG",
"type-id": "894afba6-2816-3c24-8072-eadb66bd04bc",
"name": "TG",
"locale": null,
"type": "Artist name",
"primary": null,
"begin-date": null,
"end-date": null
},
{
"sort-name": "T.G",
"type-id": "894afba6-2816-3c24-8072-eadb66bd04bc",
"name": "T.G",
"locale": null,
"type": "Artist name",
"primary": null,
"begin-date": null,
"end-date": null
},
{
"sort-name": "Tg",
"name": "Tg",
"locale": null,
"type": null,
"primary": null,
"begin-date": null,
"end-date": null
}
]
}
}
],
"first-release-date": "2022-10-28",
"releases": [
{
"id": "af96cd94-f759-4f9f-8c63-75404d4853dc",
"status-id": "4e304316-386d-3409-af2e-78857eec5cfe",
"count": 1,
"title": "Eastbound Silhouette",
"status": "Official",
"artist-credit": [
{
"name": "Tim Green",
"artist": {
"id": "5103b22e-514f-46b1-afdf-c99517c791e2",
"name": "Tim Green",
"sort-name": "Tim Green",
"disambiguation": "UK House artist aka \"TG\", started activity in the 2000s"
}
}
],
"release-group": {
"id": "275f2ad4-a506-4ab1-8ae2-ff7f203cbf6b",
"title": "Eastbound Silhouette"
},
"date": "2022-10-28",
"country": "XW",
"release-events": [
{
"date": "2022-10-28",
"area": {
"id": "525d4e18-3d00-31b9-a58b-a146a916de8f",
"name": "[Worldwide]",
"sort-name": "[Worldwide]",
"iso-3166-1-codes": [
"XW"
]
}
}
],
"track-count": 6,
"media": [
{
"position": 1,
"format": "Digital Media",
"track": [
{
"id": "2d321de5-c84e-4b39-85d1-f375b1af1f7c",
"number": "4",
"title": "Lune",
"length": 567032
}
],
"track-count": 6,
"track-offset": 3
}
]
}
]
}

View File

@@ -671,6 +671,18 @@ class CommonTests:
match = track.metadata.compare_to_track(track_json, File.comparison_weights)
self.assertEqual(sim, match.similarity)
def test_compare_to_track_is_video(self):
recording = load_test_json('recording_video_null.json')
m = Metadata()
match = m.compare_to_track(recording, {'isvideo': 1})
self.assertEqual(1.0, match.similarity)
m['~video'] = '1'
match = m.compare_to_track(recording, {'isvideo': 1})
self.assertEqual(0.0, match.similarity)
recording['video'] = True
match = m.compare_to_track(recording, {'isvideo': 1})
self.assertEqual(1.0, match.similarity)
class MetadataTest(CommonTests.CommonMetadataTestCase):
@staticmethod