From 6452cf1092b1d6ab0cbbc4134ded9a659e51d0eb Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Fri, 23 Oct 2020 22:00:43 -0600 Subject: [PATCH] A couple more ignored article fixes --- sublime_music/adapters/subsonic/adapter.py | 6 +- .../adapters/subsonic/api_objects.py | 4 +- .../mock_data/get_artists-supysonic.json | 67 +++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 tests/adapter_tests/mock_data/get_artists-supysonic.json diff --git a/sublime_music/adapters/subsonic/adapter.py b/sublime_music/adapters/subsonic/adapter.py index dd2ad77..a4529e8 100644 --- a/sublime_music/adapters/subsonic/adapter.py +++ b/sublime_music/adapters/subsonic/adapter.py @@ -642,12 +642,14 @@ class SubsonicAdapter(Adapter): try: # If we already got the ignored articles from the get_artists, do that here. with open(self.ignored_articles_cache_file, "rb+") as f: - ignored_articles = pickle.load(f) + if ia := pickle.load(f): + ignored_articles = ia except Exception: try: # Whatever the exception, fall back on getting from the server. if artists := self._get_json(self._make_url("getArtists")).artists: - ignored_articles = artists.ignored_articles + if ia := artists.ignored_articles: + ignored_articles = ia except Exception: # Use the default ignored articles. pass diff --git a/sublime_music/adapters/subsonic/api_objects.py b/sublime_music/adapters/subsonic/api_objects.py index 6cb669a..73561bd 100644 --- a/sublime_music/adapters/subsonic/api_objects.py +++ b/sublime_music/adapters/subsonic/api_objects.py @@ -284,7 +284,7 @@ class IndexID3: @dataclass_json(letter_case=LetterCase.CAMEL) @dataclass class ArtistsID3: - ignored_articles: str + ignored_articles: Optional[str] = None index: List[IndexID3] = field(default_factory=list) @@ -303,7 +303,7 @@ class Genres: @dataclass_json(letter_case=LetterCase.CAMEL) @dataclass class Indexes: - ignored_articles: str + ignored_articles: Optional[str] = None index: List[Index] = field(default_factory=list) diff --git a/tests/adapter_tests/mock_data/get_artists-supysonic.json b/tests/adapter_tests/mock_data/get_artists-supysonic.json new file mode 100644 index 0000000..1c42505 --- /dev/null +++ b/tests/adapter_tests/mock_data/get_artists-supysonic.json @@ -0,0 +1,67 @@ +{ + "subsonic-response": { + "status": "ok", + "version": "1.15.0", + "artists": { + "index": [ + { + "name": "A", + "artist": [ + { + "id": "102", + "name": "Adele", + "coverArt": "ar-102", + "albumCount": 1 + }, + { + "id": "122", + "name": "Austin French", + "coverArt": "ar-122", + "albumCount": 1 + }, + { + "id": "75", + "name": "The Afters", + "coverArt": "ar-75", + "albumCount": 2 + } + ] + }, + { + "name": "B", + "artist": [ + { + "id": "95", + "name": "The Band Perry", + "coverArt": "ar-95", + "albumCount": 1 + }, + { + "id": "41", + "name": "Basshunter", + "coverArt": "ar-41", + "albumCount": 1 + } + ] + }, + { + "name": "X-Z", + "artist": [ + { + "id": "154", + "name": "Zac Brown Band", + "coverArt": "ar-154", + "albumCount": 3 + }, + { + "id": "25", + "name": "Zach Williams", + "coverArt": "ar-25", + "albumCount": 1 + } + ] + } + ] + } + } +}