Skip to content

Commit

Permalink
fix: convert Album.cover to a cached_property
Browse files Browse the repository at this point in the history
  • Loading branch information
billsioros committed Jun 8, 2021
1 parent 899006a commit 6777ad3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions dotify/models/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, AnyStr, Iterator, Optional

import requests
from cached_property import cached_property
from mutagen.id3 import APIC
from requests.models import HTTPError

Expand Down Expand Up @@ -44,7 +45,7 @@ def url(self) -> AnyStr:
"""
return self.external_urls.spotify

@property
@cached_property
def cover(self) -> APIC:
"""Return the cover art of the album.
Expand All @@ -57,7 +58,10 @@ def cover(self) -> APIC:
response = requests.get(self.images[0].url)

if response.status_code != HTTPStatus.OK.value:
raise HTTPError(response=response)
raise HTTPError(
"Failed to fetch %s" % (self.images[0].url,),
response=response,
)

return APIC(
encoding=3,
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ moviepy = "*"
spotipy = "*"
mutagen = "*"
pytube = "*"
cached-property = "^1.5.2"

[tool.poetry.dev-dependencies]
flake8 = "*"
Expand Down

0 comments on commit 6777ad3

Please sign in to comment.