diff --git a/vrobbler/apps/music/utils.py b/vrobbler/apps/music/utils.py index dbf016a..e1a06cd 100644 --- a/vrobbler/apps/music/utils.py +++ b/vrobbler/apps/music/utils.py @@ -20,6 +20,7 @@ def get_or_create_artist(name: str, mbid: str = None) -> Artist: name = re.split("feat.", name, flags=re.IGNORECASE)[0].strip() if 'featuring' in name.lower(): name = re.split("featuring", name, flags=re.IGNORECASE)[0].strip() + artist_dict = lookup_artist_from_mb(name) mbid = mbid or artist_dict['id'] @@ -30,9 +31,9 @@ def get_or_create_artist(name: str, mbid: str = None) -> Artist: logger.debug(f"Cleaning artist {name} with {artist_dict['name']}") # Clean up bad names in our DB with MB names - if artist.name != artist_dict['name']: - artist.name = artist_dict["name"] - artist.save(update_fields=["name"]) + # if artist.name != artist_dict["name"]: + # artist.name = artist_dict["name"] + # artist.save(update_fields=["name"]) return artist diff --git a/vrobbler/apps/scrobbles/lastfm.py b/vrobbler/apps/scrobbles/lastfm.py index 01d729c..63e4dbc 100644 --- a/vrobbler/apps/scrobbles/lastfm.py +++ b/vrobbler/apps/scrobbles/lastfm.py @@ -47,17 +47,17 @@ class LastFM: new_scrobbles = [] source = "Last.fm" source_id = "" - latest_scrobbles = self.get_last_scrobbles(time_from=last_processed) + lastfm_scrobbles = self.get_last_scrobbles(time_from=last_processed) - for scrobble in latest_scrobbles: - timestamp = scrobble.pop('timestamp') + for lfm_scrobble in lastfm_scrobbles: + timestamp = lfm_scrobble.pop('timestamp') - artist = get_or_create_artist(scrobble.pop('artist')) - album = get_or_create_album(scrobble.pop('album'), artist) + artist = get_or_create_artist(lfm_scrobble.pop('artist')) + album = get_or_create_album(lfm_scrobble.pop('album'), artist) - scrobble['artist'] = artist - scrobble['album'] = album - track = get_or_create_track(**scrobble) + lfm_scrobble['artist'] = artist + lfm_scrobble['album'] = album + track = get_or_create_track(**lfm_scrobble) new_scrobble = Scrobble( user=self.vrobbler_user, @@ -134,7 +134,6 @@ class LastFM: logger.info(f"{artist},{scrobble.track.title},{timestamp}") scrobbles.append( { - "user": self.vrobbler_user, "artist": artist, "album": scrobble.album, "title": scrobble.track.title, diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index c5fd015..075c3a1 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -81,7 +81,7 @@ class BaseFileImportMixin(TimeStampedModel): self.process_log = "" if not scrobbles: self.process_count = 0 - self.save(update_fields=["process_log" "process_count"]) + self.save(update_fields=["process_log", "process_count"]) return for count, scrobble in enumerate(scrobbles): diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 3af4b77..8d599ea 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -35,7 +35,12 @@ from scrobbles.constants import ( from scrobbles.export import export_scrobbles from scrobbles.forms import ExportScrobbleForm, ScrobbleForm from scrobbles.imdb import lookup_video_from_imdb -from scrobbles.models import AudioScrobblerTSVImport, LastFmImport, Scrobble +from scrobbles.models import ( + AudioScrobblerTSVImport, + KoReaderImport, + LastFmImport, + Scrobble, +) from scrobbles.scrobblers import ( jellyfin_scrobble_track, jellyfin_scrobble_video, @@ -48,7 +53,11 @@ from scrobbles.serializers import ( AudioScrobblerTSVImportSerializer, ScrobbleSerializer, ) -from scrobbles.tasks import process_lastfm_import, process_tsv_import +from scrobbles.tasks import ( + process_koreader_import, + process_lastfm_import, + process_tsv_import, +) from scrobbles.thesportsdb import lookup_event_from_thesportsdb logger = logging.getLogger(__name__) @@ -177,6 +186,22 @@ class AudioScrobblerImportCreateView( return HttpResponseRedirect(self.get_success_url()) +class KoReaderImportCreateView( + LoginRequiredMixin, JsonableResponseMixin, CreateView +): + model = KoReaderImport + fields = ['sqlite_file'] + template_name = 'scrobbles/upload_form.html' + success_url = reverse_lazy('vrobbler-home') + + def form_valid(self, form): + self.object = form.save(commit=False) + self.object.user = self.request.user + self.object.save() + process_koreader_import.delay(self.object.id) + return HttpResponseRedirect(self.get_success_url()) + + @permission_classes([IsAuthenticated]) @api_view(['GET']) def lastfm_import(request): diff --git a/vrobbler/templates/scrobbles/scrobble_list.html b/vrobbler/templates/scrobbles/scrobble_list.html index 6d59b5f..faf8183 100644 --- a/vrobbler/templates/scrobbles/scrobble_list.html +++ b/vrobbler/templates/scrobbles/scrobble_list.html @@ -326,7 +326,18 @@ + +
+ +
diff --git a/vrobbler/urls.py b/vrobbler/urls.py index 8bf883d..798baaa 100644 --- a/vrobbler/urls.py +++ b/vrobbler/urls.py @@ -24,6 +24,11 @@ urlpatterns = [ scrobbles_views.AudioScrobblerImportCreateView.as_view(), name='audioscrobbler-file-upload', ), + path( + 'manual/koreader/', + scrobbles_views.KoReaderImportCreateView.as_view(), + name='koreader-file-upload', + ), path("", include(music_urls, namespace="music")), path("", include(video_urls, namespace="videos")), path(