|
@@ -114,6 +114,8 @@ def get_long_plays_completed(user: User) -> list:
|
|
|
|
|
|
def import_lastfm_for_all_users(restart=False):
|
|
|
"""Grab a list of all users with LastFM enabled and kickoff imports for them"""
|
|
|
+ from scrobbles.importers.lastfm import LastFM
|
|
|
+
|
|
|
LastFmImport = apps.get_model("scrobbles", "LastFMImport")
|
|
|
lastfm_enabled_user_ids = UserProfile.objects.filter(
|
|
|
lastfm_username__isnull=False,
|
|
@@ -124,6 +126,31 @@ def import_lastfm_for_all_users(restart=False):
|
|
|
lastfm_import_count = 0
|
|
|
|
|
|
for user_id in lastfm_enabled_user_ids:
|
|
|
+
|
|
|
+ lfm_import = LastFmImport.objects.filter(
|
|
|
+ user_id=user_id, processed_finished__isnull=False
|
|
|
+ ).last()
|
|
|
+ if lfm_import:
|
|
|
+ last_processed = lfm_import.processed_finished
|
|
|
+ else:
|
|
|
+ logger.info(
|
|
|
+ f"Not resuming failed LastFM import {lfm_import.id} for user {user_id}, use restart=True to restart"
|
|
|
+ "No existing LastFM import, we should start a monthly parsing of lastFm for this user going back to 2002"
|
|
|
+ )
|
|
|
+ continue
|
|
|
+
|
|
|
+ lfm_client = LastFM(
|
|
|
+ user=get_user_model().objects.filter(id=user_id).first()
|
|
|
+ )
|
|
|
+
|
|
|
+ has_scrobbles = lfm_client.get_last_scrobbles(
|
|
|
+ time_from=last_processed, check=True
|
|
|
+ )
|
|
|
+
|
|
|
+ if not has_scrobbles:
|
|
|
+ logger.info("No new scrobbles to import from LastFM")
|
|
|
+ continue
|
|
|
+
|
|
|
lfm_import, created = LastFmImport.objects.get_or_create(
|
|
|
user_id=user_id, processed_finished__isnull=True
|
|
|
)
|