Blacken quotes

This commit is contained in:
2023-03-04 17:29:25 -05:00
parent 3d7528030a
commit 94f1396f2e
60 changed files with 593 additions and 594 deletions

View File

@ -28,7 +28,7 @@ class Artist(TimeStampedModel):
thumbnail = models.ImageField(upload_to="artist/", **BNULL)
class Meta:
unique_together = [['name', 'musicbrainz_id']]
unique_together = [["name", "musicbrainz_id"]]
def __str__(self):
return self.name
@ -38,27 +38,27 @@ class Artist(TimeStampedModel):
return f"https://musicbrainz.org/artist/{self.musicbrainz_id}"
def get_absolute_url(self):
return reverse('music:artist_detail', kwargs={'slug': self.uuid})
return reverse("music:artist_detail", kwargs={"slug": self.uuid})
def scrobbles(self):
from scrobbles.models import Scrobble
return Scrobble.objects.filter(
track__in=self.track_set.all()
).order_by('-timestamp')
).order_by("-timestamp")
@property
def tracks(self):
return (
self.track_set.all()
.annotate(scrobble_count=models.Count('scrobble'))
.order_by('-scrobble_count')
.annotate(scrobble_count=models.Count("scrobble"))
.order_by("-scrobble_count")
)
def charts(self):
from scrobbles.models import ChartRecord
return ChartRecord.objects.filter(track__artist=self).order_by('-year')
return ChartRecord.objects.filter(track__artist=self).order_by("-year")
def fix_metadata(self):
tadb_info = lookup_artist_from_tadb(self.name)
@ -66,19 +66,19 @@ class Artist(TimeStampedModel):
logger.warn(f"No response from TADB for artist {self.name}")
return
self.biography = tadb_info['biography']
self.theaudiodb_genre = tadb_info['genre']
self.theaudiodb_mood = tadb_info['mood']
self.biography = tadb_info["biography"]
self.theaudiodb_genre = tadb_info["genre"]
self.theaudiodb_mood = tadb_info["mood"]
img_temp = NamedTemporaryFile(delete=True)
img_temp.write(urlopen(tadb_info['thumb_url']).read())
img_temp.write(urlopen(tadb_info["thumb_url"]).read())
img_temp.flush()
img_filename = f"{self.name}_{self.uuid}.jpg"
self.thumbnail.save(img_filename, File(img_temp))
@property
def rym_link(self):
artist_slug = self.name.lower().replace(' ', '-')
artist_slug = self.name.lower().replace(" ", "-")
return f"https://rateyourmusic.com/artist/{artist_slug}/"
@property
@ -116,21 +116,21 @@ class Album(TimeStampedModel):
return self.name
def get_absolute_url(self):
return reverse("music:album_detail", kwargs={'slug': self.uuid})
return reverse("music:album_detail", kwargs={"slug": self.uuid})
def scrobbles(self):
from scrobbles.models import Scrobble
return Scrobble.objects.filter(
track__in=self.track_set.all()
).order_by('-timestamp')
).order_by("-timestamp")
@property
def tracks(self):
return (
self.track_set.all()
.annotate(scrobble_count=models.Count('scrobble'))
.order_by('-scrobble_count')
.annotate(scrobble_count=models.Count("scrobble"))
.order_by("-scrobble_count")
)
@property
@ -142,7 +142,7 @@ class Album(TimeStampedModel):
if self.primary_artist:
artist = self.primary_artist.name
album_data = lookup_album_from_tadb(self.name, artist)
if not album_data.get('theaudiodb_id'):
if not album_data.get("theaudiodb_id"):
logger.info(f"No data for {self} found in TheAudioDB")
return
@ -154,21 +154,21 @@ class Album(TimeStampedModel):
or not self.year
or not self.musicbrainz_releasegroup_id
):
musicbrainzngs.set_useragent('vrobbler', '0.3.0')
musicbrainzngs.set_useragent("vrobbler", "0.3.0")
mb_data = musicbrainzngs.get_release_by_id(
self.musicbrainz_id, includes=['artists', 'release-groups']
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]
self.year = mb_data["release"]["date"][0:4]
except KeyError:
pass
except IndexError:
@ -176,9 +176,9 @@ class Album(TimeStampedModel):
self.save(
update_fields=[
'musicbrainz_albumartist_id',
'musicbrainz_releasegroup_id',
'year',
"musicbrainz_albumartist_id",
"musicbrainz_releasegroup_id",
"year",
]
)
@ -192,7 +192,7 @@ class Album(TimeStampedModel):
self.artists.add(t.artist)
if (
not self.cover_image
or self.cover_image == 'default-image-replace-me'
or self.cover_image == "default-image-replace-me"
):
self.fetch_artwork()
self.scrape_theaudiodb()
@ -206,10 +206,10 @@ class Album(TimeStampedModel):
)
name = f"{self.name}_{self.uuid}.jpg"
self.cover_image = ContentFile(img_data, name=name)
logger.info(f'Setting image to {name}')
logger.info(f"Setting image to {name}")
except musicbrainzngs.ResponseError:
logger.warning(
f'No cover art found for {self.name} by release'
f"No cover art found for {self.name} by release"
)
if (
@ -222,10 +222,10 @@ class Album(TimeStampedModel):
)
name = f"{self.name}_{self.uuid}.jpg"
self.cover_image = ContentFile(img_data, name=name)
logger.info(f'Setting image to {name}')
logger.info(f"Setting image to {name}")
except musicbrainzngs.ResponseError:
logger.warning(
f'No cover art found for {self.name} by release group'
f"No cover art found for {self.name} by release group"
)
if not self.cover_image:
logger.debug(
@ -257,8 +257,8 @@ class Album(TimeStampedModel):
@property
def rym_link(self):
artist_slug = self.primary_artist.name.lower().replace(' ', '-')
album_slug = self.name.lower().replace(' ', '-')
artist_slug = self.primary_artist.name.lower().replace(" ", "-")
album_slug = self.name.lower().replace(" ", "-")
return f"https://rateyourmusic.com/release/album/{artist_slug}/{album_slug}/"
@property
@ -269,25 +269,25 @@ class Album(TimeStampedModel):
class Track(ScrobblableMixin):
COMPLETION_PERCENT = getattr(settings, 'MUSIC_COMPLETION_PERCENT', 90)
COMPLETION_PERCENT = getattr(settings, "MUSIC_COMPLETION_PERCENT", 90)
class Opinion(models.IntegerChoices):
DOWN = -1, 'Thumbs down'
NEUTRAL = 0, 'No opinion'
UP = 1, 'Thumbs up'
DOWN = -1, "Thumbs down"
NEUTRAL = 0, "No opinion"
UP = 1, "Thumbs up"
artist = models.ForeignKey(Artist, on_delete=models.DO_NOTHING)
album = models.ForeignKey(Album, on_delete=models.DO_NOTHING, **BNULL)
musicbrainz_id = models.CharField(max_length=255, **BNULL)
class Meta:
unique_together = [['album', 'musicbrainz_id']]
unique_together = [["album", "musicbrainz_id"]]
def __str__(self):
return f"{self.title} by {self.artist}"
def get_absolute_url(self):
return reverse('music:track_detail', kwargs={'slug': self.uuid})
return reverse("music:track_detail", kwargs={"slug": self.uuid})
@property
def subtitle(self):
@ -310,8 +310,8 @@ class Track(ScrobblableMixin):
exist.
"""
if not artist_dict.get('name') or not artist_dict.get(
'musicbrainz_id'
if not artist_dict.get("name") or not artist_dict.get(
"musicbrainz_id"
):
logger.warning(
f"No artist or artist musicbrainz ID found in message from source, not scrobbling"
@ -325,8 +325,8 @@ class Track(ScrobblableMixin):
if not album.cover_image:
album.fetch_artwork()
track_dict['album_id'] = getattr(album, "id", None)
track_dict['artist_id'] = artist.id
track_dict["album_id"] = getattr(album, "id", None)
track_dict["artist_id"] = artist.id
track, created = cls.objects.get_or_create(**track_dict)