Compare commits

...

3 Commits
18.3 ... 18.4

4 changed files with 57 additions and 16 deletions

View File

@ -79,20 +79,7 @@ fetching and simple saving.
:LOGBOOK:
CLOCK: [2025-07-09 Wed 09:55]--[2025-07-09 Wed 10:15] => 0:20
:END:
* Backlog [4/27]
** STRT Only create a LastFM import if there are files to import :vrobbler:feature:lastfm:importers:project:personal:
:PROPERTIES:
:ID: 7a1456af-c5f1-6385-b34f-0be24a6b65b0
:END:
- Note taken on [2025-07-20 Sun 16:21]
This thing is kicking my butt. As it stands it works, but the scrobbles are not assigned to the tracks properly.
** TODO Add timezone awarness to IMAP importer :personal:project:vrobbler:feature:importer:imap:timezones:
** DONE Track timezone changes for profiles :vrobbler:feature:profiles:personal:project:
:PROPERTIES:
:ID: 89ec867f-29fd-82f1-be17-b49dddc30c78
:END:
[2025-07-11 14:23]
* Backlog [7/28]
** TODO [#A] Add classmethod for metadata fetching to tracks :vrobbler:feature:music:personal:project:
:PROPERTIES:
:ID: bc4b45e5-4c65-13c5-ab7b-1937d3fbf5c2
@ -456,6 +443,29 @@ it's annoying.
** TODO [#C] Allow users to see tasks on calendar view :vrobbler:personal:project:templates:feature:
https://codepen.io/oliviale/pen/QYqybo
** TODO [#C] Come up with a possible flow using WebDAV and super-productivity for tasks :personal:feature:project:vrobbler:tasks:
* Version 18.4
** DONE Track timezone changes for profiles :vrobbler:feature:profiles:personal:project:
:PROPERTIES:
:ID: 89ec867f-29fd-82f1-be17-b49dddc30c78
:END:
[2025-07-11 14:23]
** DONE Only create a LastFM import if there are files to import :vrobbler:feature:lastfm:importers:project:personal:
:PROPERTIES:
:ID: 7a1456af-c5f1-6385-b34f-0be24a6b65b0
:END:
- Note taken on [2025-07-20 Sun 16:21]
This thing is kicking my butt. As it stands it works, but the scrobbles are not assigned to the tracks properly.
* Version 18.3
** DONE Add timezone awarness to IMAP importer :personal:project:vrobbler:feature:importer:imap:timezones:
:PROPERTIES:
:ID: 05837b7c-96aa-6190-3678-e2ae7c7cac75
:END:
* Version 18
** DONE Condense tracks of the same title by the same artist with multiple albums :vrobbler:feature:music:project:personal:
:PROPERTIES:
:ID: b39fcec8-59fd-eab0-5809-b8144c7d2708
:END:
** DONE Import from BG stats a "learning" log field when "Learning to play" is in the comment :vrobbler:feature:boardgames:project:personal:
:PROPERTIES:
:ID: fda59fab-4349-e99e-54c6-9f1392a1c474

View File

@ -93,7 +93,7 @@ class LastFM:
)
return created
def get_last_scrobbles(self, time_from=None, time_to=None):
def get_last_scrobbles(self, time_from=None, time_to=None, check=False):
"""Given a user, Last.fm api key, and secret key, grab a list of scrobbled
tracks"""
lfm_params = {}
@ -109,6 +109,9 @@ class LastFM:
found_scrobbles = self.user.get_recent_tracks(**lfm_params)
# TOOD spin this out into a celery task over certain threshold of found scrobbles?
if check and found_scrobbles:
return True
for scrobble in found_scrobbles:
logger.info(f"Processing {scrobble}")
run_time = None

View File

@ -2,7 +2,6 @@ import logging
import re
from datetime import datetime, timedelta
from typing import Any, Optional
from zoneinfo import ZoneInfo
import pendulum
import pytz
@ -27,6 +26,7 @@ from scrobbles.constants import (
SCROBBLE_CONTENT_URLS,
)
from scrobbles.models import Scrobble
from scrobbles.notifications import NtfyNotification
from scrobbles.utils import convert_to_seconds, extract_domain
from sports.models import SportEvent
from sports.thesportsdb import lookup_event_from_thesportsdb
@ -505,6 +505,7 @@ def email_scrobble_board_game(
scrobble.played_to_completion = True
scrobble.save()
scrobbles_created.append(scrobble)
NtfyNotification(scrobble).send()
return scrobbles_created

View File

@ -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
)