Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e7c8ff137 | |||
| fae59849f8 | |||
| 837e1280bd | |||
| 8f9c825903 |
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "vrobbler"
|
name = "vrobbler"
|
||||||
version = "0.8.2"
|
version = "0.8.4"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Colin Powell <colin@unbl.ink>"]
|
authors = ["Colin Powell <colin@unbl.ink>"]
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,9 @@ class AudioScrobblerTSVImport(TimeStampedModel):
|
|||||||
tz = None
|
tz = None
|
||||||
if self.user:
|
if self.user:
|
||||||
tz = self.user.profile.tzinfo
|
tz = self.user.profile.tzinfo
|
||||||
scrobbles = process_audioscrobbler_tsv_file(self.tsv_file.path, tz=tz)
|
scrobbles = process_audioscrobbler_tsv_file(
|
||||||
|
self.tsv_file.path, user_tz=tz
|
||||||
|
)
|
||||||
if scrobbles:
|
if scrobbles:
|
||||||
self.process_log = f"Created {len(scrobbles)} scrobbles"
|
self.process_log = f"Created {len(scrobbles)} scrobbles"
|
||||||
for scrobble in scrobbles:
|
for scrobble in scrobbles:
|
||||||
|
|||||||
@ -6,14 +6,19 @@ import pytz
|
|||||||
from music.models import Album, Artist, Track
|
from music.models import Album, Artist, Track
|
||||||
from scrobbles.models import Scrobble
|
from scrobbles.models import Scrobble
|
||||||
|
|
||||||
|
from vrobbler.apps.scrobbles.musicbrainz import (
|
||||||
|
lookup_album_dict_from_mb,
|
||||||
|
lookup_artist_id_from_mb,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def process_audioscrobbler_tsv_file(file_path, tz=None):
|
def process_audioscrobbler_tsv_file(file_path, user_tz=None):
|
||||||
"""Takes a path to a file of TSV data and imports it as past scrobbles"""
|
"""Takes a path to a file of TSV data and imports it as past scrobbles"""
|
||||||
new_scrobbles = []
|
new_scrobbles = []
|
||||||
if not tz:
|
if not user_tz:
|
||||||
tz = pytz.utc
|
user_tz = pytz.utc
|
||||||
|
|
||||||
with open(file_path) as infile:
|
with open(file_path) as infile:
|
||||||
source = 'Audioscrobbler File'
|
source = 'Audioscrobbler File'
|
||||||
@ -32,9 +37,8 @@ def process_audioscrobbler_tsv_file(file_path, tz=None):
|
|||||||
continue
|
continue
|
||||||
artist, artist_created = Artist.objects.get_or_create(name=row[0])
|
artist, artist_created = Artist.objects.get_or_create(name=row[0])
|
||||||
if artist_created:
|
if artist_created:
|
||||||
logger.debug(f"Created artist {artist}")
|
artist.musicbrainz_id = lookup_artist_id_from_mb(artist.name)
|
||||||
else:
|
artist.save(update_fields=["musicbrainz_id"])
|
||||||
logger.debug(f"Found artist {artist}")
|
|
||||||
|
|
||||||
album = None
|
album = None
|
||||||
album_created = False
|
album_created = False
|
||||||
@ -52,9 +56,22 @@ def process_audioscrobbler_tsv_file(file_path, tz=None):
|
|||||||
album.artists.add(artist)
|
album.artists.add(artist)
|
||||||
|
|
||||||
if album_created:
|
if album_created:
|
||||||
logger.debug(f"Created album {album}")
|
album_dict = lookup_album_dict_from_mb(
|
||||||
else:
|
album.name, artist_name=artist.name
|
||||||
logger.debug(f"Found album {album}")
|
)
|
||||||
|
album.year = album_dict["year"]
|
||||||
|
album.musicbrainz_id = album_dict["mb_id"]
|
||||||
|
album.musicbrainz_releasegroup_id = album_dict["mb_group_id"]
|
||||||
|
album.musicbrainz_albumartist_id = artist.musicbrainz_id
|
||||||
|
album.save(
|
||||||
|
update_fields=[
|
||||||
|
"year",
|
||||||
|
"musicbrainz_id",
|
||||||
|
"musicbrainz_releasegroup_id",
|
||||||
|
"musicbrainz_albumartist_id",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
album.artists.add(artist)
|
||||||
|
|
||||||
track, track_created = Track.objects.get_or_create(
|
track, track_created = Track.objects.get_or_create(
|
||||||
title=row[2],
|
title=row[2],
|
||||||
@ -62,17 +79,16 @@ def process_audioscrobbler_tsv_file(file_path, tz=None):
|
|||||||
album=album,
|
album=album,
|
||||||
)
|
)
|
||||||
|
|
||||||
if track_created:
|
|
||||||
logger.debug(f"Created track {track}")
|
|
||||||
else:
|
|
||||||
logger.debug(f"Found track {track}")
|
|
||||||
|
|
||||||
if track_created:
|
if track_created:
|
||||||
track.musicbrainz_id = row[7]
|
track.musicbrainz_id = row[7]
|
||||||
|
track.run_time = int(row[4])
|
||||||
|
track.run_time_ticks = int(row[4]) * 1000
|
||||||
track.save()
|
track.save()
|
||||||
|
|
||||||
timestamp = datetime.utcfromtimestamp(int(row[6])).replace(
|
timestamp = (
|
||||||
tzinfo=tz
|
datetime.utcfromtimestamp(int(row[6]))
|
||||||
|
.replace(tzinfo=user_tz)
|
||||||
|
.astimezone(pytz.utc)
|
||||||
)
|
)
|
||||||
source = 'Audioscrobbler File'
|
source = 'Audioscrobbler File'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user