snejus / beetcamp

Bandcamp autotagger source for beets (http://beets.io)
GNU General Public License v2.0
64 stars 11 forks source link

Album metadata retrieval fails when no keywords(/genres) exist #52

Closed notjosh closed 4 months ago

notjosh commented 8 months ago

Hiya, I was getting an error when running the following:

$ beetcamp https://einpuls.bandcamp.com/album/haiti-2010
bandcamp: Failed obtaining albums from https://einpuls.bandcamp.com/album/haiti-2010
bandcamp: Failed obtaining singleton from https://einpuls.bandcamp.com/album/haiti-2010
Traceback (most recent call last):
  File "/path/to/venv/bin/beetcamp", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/path/to/venv/lib/python3.11/site-packages/beetsplug/bandcamp/__init__.py", line 365, in main
    raise AssertionError("Failed to find a release under the given url")
AssertionError: Failed to find a release under the given url

After a bit of print() debugging, I found it was failing in _metaguru.py when trying to find the genre. As the keywords property is missing from the JSON, it threw an error.

I patched it locally to allow keywords to use a default (empty) value:

    def genre(self) -> Optional[str]:
-        kws: Iterable[str] = map(str.lower, self.meta["keywords"])
+        kws: Iterable[str] = map(str.lower, self.meta.get("keywords", []))

...which seems to do the job.

My Python-fu is fairly weak so I'm not reaaaally sure how to set up the dev environment, otherwise I'd send a PR. Happy to do it if you can document a CONTRIBUTING.md kinda thing though!

snejus commented 8 months ago

@notjosh thanks for reporting this! I have indeed seen this and applied the exact same solution in a dev branch.

On the other hand I'm more than happy to have you contribute here. Before I document CONTRIBUTING.md feel free to simply open a PR with your fix - the GitHub workflow should test your change fine.

snejus commented 4 months ago

The fix has been merged now!