Commit Graph

62 Commits

Author SHA1 Message Date
Laurent Monin
2835732962 match -> match_: match is a statement in Python 3.10+
It doesn't really conflict with variable name but it confuses syntax highlighters (if they are Python 3.10+ aware ofc)
2024-05-25 12:21:31 +02:00
Laurent Monin
f28dec2469 Move cluster & file comparison weights at module level
- it reduces the size of Cluster and File objects
- those are constant
2024-04-02 19:51:02 +02:00
Laurent Monin
65d0b10c10 test_length_score(): make results a tuple and reformat 2023-12-22 09:58:17 +01:00
Philipp Wolfer
82821c0992 PICARD-2805: Handle None length in Metadata.length_score 2023-12-22 09:58:17 +01:00
Philipp Wolfer
d21b4f6558 PICARD-2792: Recordings without releases must score lower than with
Apply a weighted scoring based on "Other" release type for recordings
without releases. Otherwise "no release" always gives full score, while
matching against a releases usually always gives some deduction to the
matching score.
2023-12-20 00:24:39 +01:00
Philipp Wolfer
35f8fd01e1 Additional test for Metadata.compare_to_track 2023-10-28 00:50:19 +02:00
Philipp Wolfer
618c4f2104 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.
2023-10-28 00:50:19 +02:00
Philipp Wolfer
1e33a4c357 PICARD-2781: Fix matching release type score for releases without type
No type should use the "Other" type weight instead of leading to zero
match score.
2023-10-28 00:50:19 +02:00
Laurent Monin
2f6479747d Update headers 2022-02-07 09:41:57 +01:00
Philipp Wolfer
e32e116d5e PICARD-2368: Use totalalbumtracks for cluster matching 2021-12-18 17:26:57 +01:00
Philipp Wolfer
8ed8075cea PICARD-2368: When comparing metadata to a release consider the actual medium track count
tracktotal in a file is supposed to have the total number of tracks on the specific medium. Comparing to the total tracks of a release across all medium hence gives wrong results.
2021-12-18 17:26:56 +01:00
Laurent Monin
14ce07756e Update Copyright headers, with the help of fix-headers.py script 2021-11-10 21:38:54 +01:00
Philipp Wolfer
c0e6243a13 PICARD-1926: Adjust test cases for new config structure 2020-12-25 12:37:15 +01:00
Wieland Hoffmann
1386f1db03 PICARD-2036: Add MultiMetadataProxy::pop to WRITE_METHODS 2020-11-29 19:53:51 +01:00
Philipp Wolfer
53a2e3bb60 PICARD-1972: When matching files to tracks preserve track length (#1659)
PICARD-1972: Allow initializing Metadata with another Metadata object

If calling Metadata(other_metadata) make a full copy and don't just treat other_metadata as a dict.

Apart of making the API more intuitive this fixes issues with track metadata being not fully preserved when attaching files to tracks.
2020-10-16 13:27:10 +02:00
Philipp Wolfer
c3ccd6a392 Make MultiMetadataProxy fully compatible with Metadata
Run the same test cases against both Metadata and MultiMetadataProxy
2020-10-07 17:48:24 +02:00
Philipp Wolfer
06508560f9 MultiMetadataProxy to combine multiple metadata objects 2020-10-06 20:04:52 +02:00
Philipp Wolfer
21d4f04029 PICARD-259: Preserve manual changes to tracks on matched files
Keep track of manual changes to a track's metadata and reapply them to matched files.
2020-09-22 09:34:27 +02:00
dukeyin
f042928433 Don't use release relationships if they are disabled in metadata options 2020-07-17 19:57:37 -04:00
Philipp Wolfer
cbe88786a6 PICARD-1846: Do not raise KeyError in Metadata.unset 2020-06-19 14:47:03 +02:00
Philipp Wolfer
fb83a8e76b Enable flake8 E265: Block comment should start with '# '
Most changes involve replacing non-breaking space with a simple space after the #.
2020-05-13 11:03:13 +02:00
Laurent Monin
6b5e852a60 Run fix-header on *.py 2020-02-24 10:25:09 +01:00
Laurent Monin
3f25bda3c8 Fix a bunch of flake8 warnings, mostly cosmetic changes 2020-02-21 21:43:40 +01:00
Philipp Wolfer
d653270b71 PICARD-1723: Consider disc number when comparing metadata
Improves results when matching files to multi-disc albums.
2020-02-03 11:16:52 +01:00
Philipp Wolfer
3d2a5cf250 PICARD-1719: Fix $unset must not mark tags for deletion.
This regressed in Picard 2.2.0 with commit 503b520 and $unset behaves the same as $delete.
2020-01-31 18:09:07 +01:00
Philipp Wolfer
c52519d91a PICARD-239: Handle tags like "comment" and "comment:" the same
Some of Picard's tag names allow an additional description separated by a colon, e.g. "comment:desc". In case the description part is empty and the tag ends on a colon this is now treated the same as without any colon. So "lyrics" and "lyrics:" are the same tag.

Handling this in Metadata makes this change immediately available in scripting and to all formats. Script using both forms will still work.
2020-01-26 17:07:42 +01:00
Laurent Monin
aefbdb6a73 Move more code from Metadata to external small functions, test them 2020-01-23 18:01:28 +01:00
Laurent Monin
210e71b426 Pass parts to weights_from_release_type_scores() 2020-01-23 18:01:28 +01:00
Laurent Monin
e44c6929c5 Move code outside Metadata class, to ease testing 2020-01-19 13:51:41 +01:00
Philipp Wolfer
5c2e1eaa0a PICARD-1664: Use preferred release type for cluster lookup 2019-12-02 13:52:13 +01:00
Philipp Wolfer
4dffc55ef1 Merge pull request #1379 from phw/PICARD-1677-ignore-tags
PICARD-1677: Tags can be ignored for metadata comparisson
2019-11-29 17:02:15 +01:00
Philipp Wolfer
4f684d0a48 PICARD-1678: Fix Picard crashing on non-integer search scores
If the search scores returned by the server are not integer values Picard crashed during metadata comparisson.
2019-11-29 17:00:59 +01:00
Philipp Wolfer
c6fcf3f1a0 PICARD-1677: Allow ignoring tags for metadata comparisson
Files that only differ in the tags set in the ignore list will not show up as changed even if those tags have changed.
2019-11-29 15:21:10 +01:00
Philipp Wolfer
96ca9188ba PICARD-1406: Make setting data in Metadata consistently use strings
- All Metadata methods setting data (__setitem__, set, add, add_unique) will convert values to strings
- __setitem__ and set are equivalent
2019-11-12 07:55:54 +01:00
Philipp Wolfer
05ffd72884 tests: use assertIn and assertNotIn 2019-09-13 22:09:36 +02:00
Philipp Wolfer
cdaf812587 PICARD-1573: Metadata.apply_func() must handle tags getting removed 2019-08-14 18:59:55 +02:00
Philipp Wolfer
40f12e5eb2 Simplified metadata comparisson in tests 2019-06-24 14:59:22 +02:00
Philipp Wolfer
604e542d10 Check if images get copied in test for Metadata.update() 2019-06-23 11:39:38 +02:00
Philipp Wolfer
0c57969735 PICARD-1529: Allow copying metadata without images 2019-06-23 11:35:18 +02:00
Laurent Monin
7e3c9673c8 Add test for Metadata.apply_func() with preserved tags 2019-03-22 11:04:44 +01:00
Laurent Monin
b81947e22d Add test for Metadata.strip_whitespace() 2019-03-22 10:54:31 +01:00
Laurent Monin
78c9890e21 Drop Metadata.append_image(), use Metadata.images.append() instead 2019-03-22 10:32:31 +01:00
Laurent Monin
6bf103bf34 Drop useless Metadata.remove_image() 2019-03-22 10:32:31 +01:00
Laurent Monin
b58c353259 Metadata.__setitem__(): accept any iterable as values
https://github.com/metabrainz/picard/pull/1137#discussion_r266974994
2019-03-21 11:53:39 +01:00
Laurent Monin
b5cc54e255 Make Metadata.__setitem__() consistent with Metadata.add() regarding 0 values
m['tag'] = 0 wasn't doing the same thing as m.add('tag', 0), because the test in __setitem__()
was different: if value vs if value or value == 0
So modify it to make behavior much more consistent.

m['tag'] = 0 or m.add('tag', 0) actually set tag to ['0']
m.add('tag', '') does nothing
m['tag'] = '' explicitly delete the tag (removing it from store, adding it to deleted tags)
m = Metadata(tag='') doesn't create an entry 'tag' (at all)
m = Metadata(tag=0) creates a tag, with internal value ['0']

This way, one can rewrite:

self.metadata = Metadata()
self.metadata['album'] = name
self.metadata['albumartist'] = artist
self.metadata['totaltracks'] = 0

to:
self.metadata = Metadata(album=name, albumartist=artist, totaltracks=0)

Without this patch, totaltracks wasn't set at all.
2019-03-21 11:38:58 +01:00
Laurent Monin
99604ac01f Test and annotate the case of del with unknown keys 2019-03-20 21:17:06 +01:00
Laurent Monin
f6e3aedf7a Raises TypeError if Metadata.update() is called without argument
This is more consistent with dict.update() behavior (and shouldn't happen anyway).
2019-03-20 11:03:56 +01:00
Laurent Monin
39b069adae Test Metadata.len() with images 2019-03-20 10:42:50 +01:00
Laurent Monin
1a1e250489 Add tests for Metadata with images 2019-03-20 10:42:50 +01:00
Laurent Monin
2aec4a4185 Metadata.update(): fix a corner case leading to inconsistent data
```python
m = Metadata(tag1='a', tag2='b')
del m['tag1']
```

```
m store: {'tag2': ['b']}
m deleted: {'tag1'}
```

```python
m2 = Metadata(tag1='c', tag2='d')
del m2['tag2']
```

```
m2 store: {'tag2': ['b']}
m2 deleted: {'tag1'}
```

```python
m.update(m2)
```

```
m store: {'tag1': ['c']}
m deleted: {'tag1', 'tag2'} <---- this was incorrect, and untested case
```

This patch fixes it, and results to:

```
m store: {'tag1': ['c']}
m deleted: {'tag2'}
```
2019-03-20 10:42:50 +01:00