[black] Reformat to use 88 line lengths
This commit is contained in:
@ -109,9 +109,9 @@ class Artist(TimeStampedModel):
|
||||
def scrobbles(self):
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
return Scrobble.objects.filter(
|
||||
track__in=self.track_set.all()
|
||||
).order_by("-timestamp")
|
||||
return Scrobble.objects.filter(track__in=self.track_set.all()).order_by(
|
||||
"-timestamp"
|
||||
)
|
||||
|
||||
@property
|
||||
def tracks(self):
|
||||
@ -130,9 +130,7 @@ class Artist(TimeStampedModel):
|
||||
if not self.allmusic_id or force:
|
||||
slug = get_allmusic_slug(self.name)
|
||||
if not slug:
|
||||
logger.info(
|
||||
"No allmusic link found", extra={"track_id": self.id}
|
||||
)
|
||||
logger.info("No allmusic link found", extra={"track_id": self.id})
|
||||
return
|
||||
self.allmusic_id = slug
|
||||
self.save(update_fields=["allmusic_id"])
|
||||
@ -141,9 +139,7 @@ class Artist(TimeStampedModel):
|
||||
if not self.bandcamp_id or force:
|
||||
slug = get_bandcamp_slug(self.name)
|
||||
if not slug:
|
||||
logger.info(
|
||||
"No bandcamp link found", extra={"track_id": self.id}
|
||||
)
|
||||
logger.info("No bandcamp link found", extra={"track_id": self.id})
|
||||
return
|
||||
self.bandcamp_id = slug
|
||||
self.save(update_fields=["bandcamp_id"])
|
||||
@ -193,13 +189,9 @@ class Artist(TimeStampedModel):
|
||||
Thus, when we find or create an artist, we should always provide an optional
|
||||
album name or track name, but probably not both."""
|
||||
if album_name:
|
||||
logger.info(
|
||||
f"Looking for artist with name {name} and album {album_name}"
|
||||
)
|
||||
logger.info(f"Looking for artist with name {name} and album {album_name}")
|
||||
if track_name:
|
||||
logger.info(
|
||||
f"Looking for artist with name {name} and track {track_name}"
|
||||
)
|
||||
logger.info(f"Looking for artist with name {name} and track {track_name}")
|
||||
keys = {}
|
||||
|
||||
name = clean_artist_name(name)
|
||||
@ -310,9 +302,9 @@ class Album(TimeStampedModel):
|
||||
def scrobbles(self):
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
return Scrobble.objects.filter(
|
||||
track__in=self.track_set.all()
|
||||
).order_by("-timestamp")
|
||||
return Scrobble.objects.filter(track__in=self.track_set.all()).order_by(
|
||||
"-timestamp"
|
||||
)
|
||||
|
||||
@property
|
||||
def primary_image_url(self) -> str:
|
||||
@ -349,9 +341,7 @@ class Album(TimeStampedModel):
|
||||
if self.album_artist and (not self.allmusic_id or force):
|
||||
slug = get_allmusic_slug(self.album_artist.name, self.name)
|
||||
if not slug:
|
||||
logger.info(
|
||||
f"No allmsuic link for {self} by {self.album_artist}"
|
||||
)
|
||||
logger.info(f"No allmsuic link for {self} by {self.album_artist}")
|
||||
return
|
||||
self.allmusic_id = slug
|
||||
self.save(update_fields=["allmusic_id"])
|
||||
@ -380,9 +370,7 @@ class Album(TimeStampedModel):
|
||||
try:
|
||||
Album.objects.filter(pk=self.pk).update(**album_data)
|
||||
except:
|
||||
logger.info(
|
||||
f"Could not save info for album {self} with data {album_data}"
|
||||
)
|
||||
logger.info(f"Could not save info for album {self} with data {album_data}")
|
||||
|
||||
def scrape_bandcamp(self, force=False) -> None:
|
||||
if not self.bandcamp_id or force:
|
||||
@ -404,13 +392,13 @@ class Album(TimeStampedModel):
|
||||
self.musicbrainz_id, includes=["artists", "release-groups"]
|
||||
)
|
||||
if not self.musicbrainz_releasegroup_id:
|
||||
self.musicbrainz_releasegroup_id = mb_data["release"][
|
||||
"release-group"
|
||||
]["id"]
|
||||
self.musicbrainz_releasegroup_id = mb_data["release"]["release-group"][
|
||||
"id"
|
||||
]
|
||||
if not self.musicbrainz_albumartist_id:
|
||||
self.musicbrainz_albumartist_id = mb_data["release"][
|
||||
"artist-credit"
|
||||
][0]["artist"]["id"]
|
||||
self.musicbrainz_albumartist_id = mb_data["release"]["artist-credit"][
|
||||
0
|
||||
]["artist"]["id"]
|
||||
if not self.year:
|
||||
try:
|
||||
self.year = mb_data["release"]["date"][0:4]
|
||||
@ -435,10 +423,7 @@ class Album(TimeStampedModel):
|
||||
if not new_artist:
|
||||
for t in self.track_set.all():
|
||||
self.artists.add(t.artist)
|
||||
if (
|
||||
not self.cover_image
|
||||
or self.cover_image == "default-image-replace-me"
|
||||
):
|
||||
if not self.cover_image or self.cover_image == "default-image-replace-me":
|
||||
self.fetch_artwork()
|
||||
self.fix_album_artist()
|
||||
self.scrape_theaudiodb()
|
||||
@ -448,20 +433,15 @@ class Album(TimeStampedModel):
|
||||
if not self.cover_image and not force:
|
||||
if self.musicbrainz_id:
|
||||
try:
|
||||
img_data = musicbrainzngs.get_image_front(
|
||||
self.musicbrainz_id
|
||||
)
|
||||
img_data = musicbrainzngs.get_image_front(self.musicbrainz_id)
|
||||
name = f"{self.name}_{self.uuid}.jpg"
|
||||
self.cover_image = ContentFile(img_data, name=name)
|
||||
logger.info(f"Setting image to {name}")
|
||||
except musicbrainzngs.ResponseError:
|
||||
logger.warning(
|
||||
f"No cover art found for {self.name} by release"
|
||||
)
|
||||
logger.warning(f"No cover art found for {self.name} by release")
|
||||
|
||||
if (
|
||||
not self.cover_image
|
||||
or self.cover_image == "default-image-replace-me"
|
||||
not self.cover_image or self.cover_image == "default-image-replace-me"
|
||||
) and self.musicbrainz_releasegroup_id:
|
||||
try:
|
||||
img_data = musicbrainzngs.get_release_group_image_front(
|
||||
@ -522,9 +502,7 @@ class Album(TimeStampedModel):
|
||||
|
||||
@classmethod
|
||||
def find_or_create(cls, name: str, artist_name: str) -> "Album":
|
||||
logger.info(
|
||||
f"Looking for album with name {name} and artist_name {artist_name}"
|
||||
)
|
||||
logger.info(f"Looking for album with name {name} and artist_name {artist_name}")
|
||||
artist = Artist.find_or_create(artist_name, album_name=name)
|
||||
album_dict = get_album_metadata_with_artist(name, artist.name)
|
||||
|
||||
@ -572,9 +550,7 @@ class Album(TimeStampedModel):
|
||||
if found_name and name != found_name:
|
||||
alt_name = name
|
||||
|
||||
album = Album.objects.filter(
|
||||
musicbrainz_id=album_dict.get("mbid")
|
||||
).first()
|
||||
album = Album.objects.filter(musicbrainz_id=album_dict.get("mbid")).first()
|
||||
|
||||
if not album:
|
||||
year = None
|
||||
@ -583,9 +559,7 @@ class Album(TimeStampedModel):
|
||||
album = Album.objects.create(
|
||||
name=found_name,
|
||||
musicbrainz_id=album_dict.get("mbid"),
|
||||
musicbrainz_releasegroup_id=album_dict.get(
|
||||
"release_group_mbid"
|
||||
),
|
||||
musicbrainz_releasegroup_id=album_dict.get("release_group_mbid"),
|
||||
year=year,
|
||||
album_artist=artist,
|
||||
alt_names=alt_name,
|
||||
@ -666,9 +640,7 @@ class Track(ScrobblableMixin):
|
||||
album = None
|
||||
if album_name:
|
||||
logger.info("Looking up album for: {album_name}")
|
||||
album = Album.find_or_create(
|
||||
name=album_name, artist_name=artist_name
|
||||
)
|
||||
album = Album.find_or_create(name=album_name, artist_name=artist_name)
|
||||
artist = album.album_artist
|
||||
else:
|
||||
artist = Artist.find_or_create(artist_name, track_name=title)
|
||||
@ -709,15 +681,11 @@ class Track(ScrobblableMixin):
|
||||
},
|
||||
)
|
||||
try:
|
||||
mbid, length = get_recording_mbid_exact(
|
||||
title, artist_name, album_name
|
||||
)
|
||||
mbid, length = get_recording_mbid_exact(title, artist_name, album_name)
|
||||
except Exception:
|
||||
print("No musicbrainz result found, cannot enrich")
|
||||
return track
|
||||
track.base_run_time_seconds = run_time_seconds or int(
|
||||
length / 1000
|
||||
)
|
||||
track.base_run_time_seconds = run_time_seconds or int(length / 1000)
|
||||
track.musicbrainz_id = mbid
|
||||
if commit:
|
||||
track.save()
|
||||
|
||||
Reference in New Issue
Block a user