Commit Graph

6033 Commits

Author SHA1 Message Date
Laurent Monin
a930e688e3 country_list_from_node(): country -> countries
That's a list of countries.
2019-03-25 14:36:56 +01:00
Laurent Monin
f9e1373d9a country_list_from_node(): returns [] instead of implicit None if no release-event in node
Since this code was introduced in f8559fdd7, it was returning None implicitly if no "release-events" were found in node.
This behavior differs from other methods of the same kind like release_dates_and_countries_from_node()

This change shouldn't have any negative impact, since callers always test for emptyness
2019-03-25 14:36:56 +01:00
Laurent Monin
5ae92454f4 Add a test for release without events vs countries 2019-03-25 14:36:56 +01:00
Laurent Monin
4983631f70 Merge pull request #1142 from zas/coverimage_metadata_cleanup
CoverArtImage/ImageList/Metadata cleanup
2019-03-24 14:33:50 +01:00
Laurent Monin
7fe2fda12e Merge pull request #1144 from zas/cluster_match_cleanup
Clean up various matching iterations, unify a bit
2019-03-24 14:33:26 +01:00
Laurent Monin
195f3ab9bb Drop debug parameter and associate output, make code easier to read 2019-03-24 12:10:12 +01:00
Laurent Monin
6ab7755f74 Use same parameter name as the overridden method, fixing a pylint warning
https://github.com/metabrainz/picard/pull/1142#discussion_r268423763

Replace `image` by `value` according to https://hg.python.org/cpython/file/3.5/Lib/_collections_abc.py#l895
2019-03-24 12:06:20 +01:00
Laurent Monin
1159df51da Remove extra parenthesis 2019-03-24 11:36:10 +01:00
Laurent Monin
3cbcc1cf0e Reduce code redundancy, using a locally-defined method to output messages 2019-03-23 18:45:24 +01:00
Laurent Monin
7e8235ebf8 rg_id -> release_group_id 2019-03-23 17:19:06 +01:00
Laurent Monin
b9bcf47805 Album._match_files(): add a debug parameter
- it will ease testing, using debug=False will not call log.debug()
2019-03-23 17:13:15 +01:00
Laurent Monin
ecf3cbb3bc Move part of File._lookup_finished() to new File._match_to_track()
- separate UI-related code from processing code
- it will ease testing
2019-03-23 17:11:14 +01:00
Laurent Monin
5e4b698c25 Move part of code from Cluster._lookup_finished() to new _match_to_album()
It will ease testing, separating UI-related code from processing code
2019-03-23 16:46:09 +01:00
Laurent Monin
b33e59428f Clean up various matching iterations, unify a bit
- use generators for candidates
- introduce picard.util.find_best_match() and sort_by_similarity() with tests
- partially revert change that removed sorted(), it was actually faster and cleaner
- use namedtuples to get rid of numeric indexes
- when no match, output max similarity, threshold and number of candidates to debug log
- make code easier to understand, using long names and namedtuple attributes, and simpler workflow
- use repr(best_match) for debug, as it provides all the needed info
- set values explicitly using namedtuple kw parameters
- use same prefix for namedtuples names, it eases searching through code

Typical debug output looks like:
```
D: 13:16:41,806 cluster._lookup_finished:223: BestMatch(similarity=0.79, result=SimMatchRelease(similarity=0.79, release={'id': '36b8f767-c4c0-4ba1-becd-f40a452303d5', 'score': 79, 'count': 1, 'title': 'Purple', 'status': 'Official', 'packaging': 'Jewel Case', 'text-representation': {'language': 'eng', 'script': 'Latn'}, 'artist-credit': [{'artist': {'id': '8c32bb01-58a3-453b-8050-8c0620edb0e5', 'name': 'Stone Temple Pilots', 'sort-name': 'Stone Temple Pilots'}}], 'release-group': {'id': '01d45519-54a6-3427-b0dc-222203fa5d57', 'type-id': 'f529b476-6e62-324f-b0aa-1f3e33d313fc', 'title': 'Purple', 'primary-type': 'Album'}, 'date': '1995-08-25', 'country': 'US', 'release-events': [{'date': '1995-08-25', 'area': {'id': '489ce91b-6658-3307-9877-795b68554c98', 'name': 'United States', 'sort-name': 'United States', 'iso-3166-1-codes': ['US']}}], 'track-count': 11, 'media': [{'format': 'CD', 'disc-count': 10, 'track-count': 11}]}), num_results=25) < threshold=0.800000
```
2019-03-23 16:29:44 +01:00
Laurent Monin
4730e42e45 Merge pull request #1143 from zas/fix_missing_clear_existing_tags
Cleanup missing clear existing tags setting fix
2019-03-23 10:51:09 +01: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
b3d1ef2f41 Metadata.strip_whitespace(): no need of lambda, directly pass str.strip 2019-03-22 10:54:09 +01:00
Laurent Monin
99896bff8b Add tests for ImageList copy()/clear()/del
Note: clear() is apparently inherited, i read docs saying otherwise, so i add a test for it to be sure
2019-03-22 10:32:32 +01:00
Laurent Monin
3a44ec41e2 Disable pylint warning about ImageList.insert() 2019-03-22 10:32:32 +01:00
Laurent Monin
9340c6c2ec Drop Metadata.set_front_image(), replace with ImageList.strip_front_images()
- only used in ui/coverartbox.py and not directly linked to metadata
- add tests
-
2019-03-22 10:32:31 +01:00
Laurent Monin
76b85a4e1f Introduce ImageList.copy()
- imagelist[:] returns a list, not an ImageList
- it returns an instance of ImageList
2019-03-22 10:32:31 +01:00
Laurent Monin
caa03f3f0a ImageList: inherit from MutableSequence instead of list
Note: i got rid of old __getitem__() which makes no sense imho
It returned an instance of itself for each element, not sure what was the goal
2019-03-22 10:32: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
0b837ebe8d Move Metadata.images_to_be_saved_to_tags() to ImageList.to_be_saved_to_tags()
- make it a generator
- drop @property, it's a function, no point in hiding it
- add tests
2019-03-22 10:32:31 +01:00
Laurent Monin
eb73ea6bc4 Replace Metadata.get_single_front_image() with ImageList.get_front_image()
- it makes much more sense, Metadata.images is an ImageList
- minimal changes required
- add tests for it
2019-03-22 10:32:31 +01:00
Laurent Monin
d60afe35d7 ImageList(): fix untestable class, since it requires gettext...
- image.types_as_string() was called from get_image_type() without translate=False
- dependency wasn't satisfied, so impossible to test as is
- make tests depending on languages isn't a good idea anyway
- use new CoverArtImage.normalized_types() instead
- simplify code
- add tests for ImageList.append() and ImageList.__eq__()
2019-03-22 10:32:31 +01:00
Laurent Monin
45e70a676f CoverArtImage: add a function normalizing types
This is needed because types can be in any order (and even contains duplicate)
So output of types_as_string() was differing, depending on how types were set
2019-03-22 10:32:31 +01:00
Laurent Monin
9d7b8dc995 CoverArtImage.__init__(): add parameters to override supported types
It's convenient for testing
2019-03-22 10:32:31 +01:00
Laurent Monin
bc11a330ab Introduce SettingsOverride class to fix this more elegantly
- basically it returns config.setting[key] when key isn't in the internal dict
- it protects config.setting from any write, since __setitem__ only write to self._dict
- del settings['xxx'] will remove 'xxx' from internal dict, but still allow access to config.setting
- it can be used for tests
- minimal implementation based on MutableMapping
- add tests for it
2019-03-22 10:29:57 +01:00
Laurent Monin
25ceef01e4 Remove unused (and obsolete) use_va_format from settings 2019-03-22 10:29:57 +01:00
Laurent Monin
26b5f56f04 Sort settings 2019-03-22 10:29:57 +01:00
Laurent Monin
4990cef589 Fix crash introduced when opening Options: KeyError: 'clear_existing_tags'
It was introduced in 04dcd4691b, settings for examples were missing this setting
2019-03-22 10:28:56 +01:00
Laurent Monin
ca069ae767 Merge pull request #1141 from zas/metadata_use_cleanup
Metadata cleanup, second pass
2019-03-21 21:52:14 +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
13e8e83bc4 Merge pull request #1137 from zas/metadata_mapping
Metadata class: inherit from MutableMapping instead of dict
2019-03-21 10:52:17 +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
Laurent Monin
090c1e4eaf Reduce code redundancy in tests 2019-03-20 10:42:50 +01:00
Laurent Monin
4e977cfb2c Improve dict compatibility of Metadata.update() + minor fixes 2019-03-20 10:42:50 +01:00
Laurent Monin
503b5203f1 Metadata class: inherit from MutableMapping instead of dict 2019-03-20 10:42:49 +01:00
Laurent Monin
2282114147 Merge pull request #1140 from zas/preservetimes_test
Fix broken preserve times test logic
2019-03-20 00:03:34 +01:00
Laurent Monin
a9cf9d55c8 File._preserve_times(): fix broken logic
- access times are likely to differ, a race condition is possible
- stat() has be done after the change to be able to compare
- comments added
- force sync after modifying test file
- make code easier to understand

See https://github.com/metabrainz/picard/pull/1132#issuecomment-474113665
2019-03-19 23:21:59 +01:00
Laurent Monin
a13a95723e Merge pull request #1136 from zas/_make_filename_fix
Make filename fix
2019-03-19 18:54:52 +01:00
Laurent Monin
70e08b47db Merge pull request #1135 from zas/file_changed_normal
Cleanup File state, tracknumber, discnumber properties
2019-03-19 17:20:51 +01:00