Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d944fdd0c0 | |||
| e345631e27 | |||
| 59d0108fe5 | |||
| 8d67b672f9 | |||
| 376650f937 | |||
| 485fbd63a3 |
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "vrobbler"
|
name = "vrobbler"
|
||||||
version = "0.9.0"
|
version = "0.9.3"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Colin Powell <colin@unbl.ink>"]
|
authors = ["Colin Powell <colin@unbl.ink>"]
|
||||||
|
|
||||||
|
|||||||
@ -37,12 +37,6 @@ class AudioScrobblerTSVImport(TimeStampedModel):
|
|||||||
return f"Audioscrobbler TSV upload: {self.tsv_file.path}"
|
return f"Audioscrobbler TSV upload: {self.tsv_file.path}"
|
||||||
return f"Audioscrobbler TSV upload {self.id}"
|
return f"Audioscrobbler TSV upload {self.id}"
|
||||||
|
|
||||||
def save(self, **kwargs):
|
|
||||||
"""On save, attempt to import the TSV file"""
|
|
||||||
super().save(**kwargs)
|
|
||||||
self.process()
|
|
||||||
return
|
|
||||||
|
|
||||||
def process(self, force=False):
|
def process(self, force=False):
|
||||||
from scrobbles.tsv import process_audioscrobbler_tsv_file
|
from scrobbles.tsv import process_audioscrobbler_tsv_file
|
||||||
|
|
||||||
@ -56,6 +50,7 @@ class AudioScrobblerTSVImport(TimeStampedModel):
|
|||||||
scrobbles = process_audioscrobbler_tsv_file(
|
scrobbles = process_audioscrobbler_tsv_file(
|
||||||
self.tsv_file.path, user_tz=tz
|
self.tsv_file.path, user_tz=tz
|
||||||
)
|
)
|
||||||
|
self.process_log = ""
|
||||||
if scrobbles:
|
if scrobbles:
|
||||||
for count, scrobble in enumerate(scrobbles):
|
for count, scrobble in enumerate(scrobbles):
|
||||||
scrobble_str = f"{scrobble.id}\t{scrobble.timestamp}\t{scrobble.track.title}"
|
scrobble_str = f"{scrobble.id}\t{scrobble.timestamp}\t{scrobble.track.title}"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
from scrobbles.models import LastFmImport
|
from scrobbles.models import AudioScrobblerTSVImport, LastFmImport
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -13,3 +13,12 @@ def process_lastfm_import(import_id):
|
|||||||
logger.warn(f"LastFmImport not found with id {import_id}")
|
logger.warn(f"LastFmImport not found with id {import_id}")
|
||||||
|
|
||||||
lastfm_import.process()
|
lastfm_import.process()
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def process_tsv_import(import_id):
|
||||||
|
tsv_import = AudioScrobblerTSVImport.objects.filter(id=import_id).first()
|
||||||
|
if not tsv_import:
|
||||||
|
logger.warn(f"AudioScrobblerTSVImport not found with id {import_id}")
|
||||||
|
|
||||||
|
tsv_import.process()
|
||||||
|
|||||||
@ -37,7 +37,7 @@ def process_audioscrobbler_tsv_file(file_path, user_tz=None):
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
artist = get_or_create_artist(row[0])
|
artist = get_or_create_artist(row[0])
|
||||||
album = get_or_create_album(row[1])
|
album = get_or_create_album(row[1], artist)
|
||||||
|
|
||||||
track = get_or_create_track(
|
track = get_or_create_track(
|
||||||
title=row[2],
|
title=row[2],
|
||||||
@ -45,15 +45,14 @@ def process_audioscrobbler_tsv_file(file_path, user_tz=None):
|
|||||||
artist=artist,
|
artist=artist,
|
||||||
album=album,
|
album=album,
|
||||||
run_time=row[4],
|
run_time=row[4],
|
||||||
run_time_ticks=row[4] * 1000,
|
run_time_ticks=int(row[4]) * 1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
timestamp = (
|
timestamp = (
|
||||||
datetime.utcfromtimestamp(int(row[6]))
|
datetime.fromtimestamp(int(row[6]))
|
||||||
.replace(tzinfo=user_tz)
|
.replace(tzinfo=user_tz)
|
||||||
.astimezone(pytz.utc)
|
.astimezone(pytz.utc)
|
||||||
)
|
)
|
||||||
source = 'Audioscrobbler File'
|
|
||||||
|
|
||||||
new_scrobble = Scrobble(
|
new_scrobble = Scrobble(
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
|
|||||||
@ -48,7 +48,7 @@ from scrobbles.serializers import (
|
|||||||
AudioScrobblerTSVImportSerializer,
|
AudioScrobblerTSVImportSerializer,
|
||||||
ScrobbleSerializer,
|
ScrobbleSerializer,
|
||||||
)
|
)
|
||||||
from scrobbles.tasks import process_lastfm_import
|
from scrobbles.tasks import process_lastfm_import, process_tsv_import
|
||||||
from scrobbles.thesportsdb import lookup_event_from_thesportsdb
|
from scrobbles.thesportsdb import lookup_event_from_thesportsdb
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -173,6 +173,7 @@ class AudioScrobblerImportCreateView(
|
|||||||
self.object = form.save(commit=False)
|
self.object = form.save(commit=False)
|
||||||
self.object.user = self.request.user
|
self.object.user = self.request.user
|
||||||
self.object.save()
|
self.object.save()
|
||||||
|
process_tsv_import.delay(self.object.id)
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user