Procházet zdrojové kódy

[music] Fix timezones on lastfm imports

Colin Powell před 2 měsíci
rodič
revize
b2077678e2
1 změnil soubory, kde provedl 8 přidání a 6 odebrání
  1. 8 6
      vrobbler/apps/scrobbles/importers/lastfm.py

+ 8 - 6
vrobbler/apps/scrobbles/importers/lastfm.py

@@ -50,20 +50,22 @@ class LastFM:
                 enrich=True,
             )
 
-            timezone = settings.TIME_ZONE
-            if self.vrobbler_user.profile:
-                timezone = self.vrobbler_user.profile.timezone
-
-            timestamp = lfm_scrobble.get("timestamp")
+            timestamp = self.vrobbler_user.profile.get_timestamp_with_tz(
+                lfm_scrobble.get("timestamp")
+            )
+            stop_timestamp = timestamp + timedelta(
+                seconds=track.run_time_seconds
+            )
             new_scrobble = Scrobble(
                 user=self.vrobbler_user,
                 timestamp=timestamp,
+                stop_timestamp=stop_timestamp,
                 source=source,
                 track=track,
-                timezone=timezone,
                 played_to_completion=True,
                 in_progress=False,
                 media_type=Scrobble.MediaType.TRACK,
+                timezone=timestamp.tzinfo.name,
             )
             # Vrobbler scrobbles on finish, LastFM scrobbles on start
             seconds_eariler = timestamp - timedelta(seconds=20)