[brickset] Fix manual scrobbling and admin
This commit is contained in:
@ -8,6 +8,7 @@ import pytz
|
||||
from beers.models import Beer
|
||||
from boardgames.models import BoardGame
|
||||
from books.models import Book
|
||||
from bricksets.models import BrickSet
|
||||
from dateutil.parser import parse
|
||||
from django.utils import timezone
|
||||
from locations.constants import LOCATION_PROVIDERS
|
||||
@ -23,7 +24,7 @@ from scrobbles.constants import (
|
||||
SCROBBLE_CONTENT_URLS,
|
||||
)
|
||||
from scrobbles.models import Scrobble
|
||||
from scrobbles.utils import convert_to_seconds
|
||||
from scrobbles.utils import convert_to_seconds, extract_domain
|
||||
from sports.models import SportEvent
|
||||
from sports.thesportsdb import lookup_event_from_thesportsdb
|
||||
from tasks.models import Task
|
||||
@ -322,14 +323,12 @@ def manual_scrobble_from_url(
|
||||
we know about the content type, and routes it to the appropriate media
|
||||
scrobbler. Otherwise, return nothing."""
|
||||
content_key = ""
|
||||
try:
|
||||
domain = url.split("//")[-1].split("/")[0]
|
||||
except IndexError:
|
||||
domain = None
|
||||
domain = extract_domain(url)
|
||||
|
||||
for key, content_url in SCROBBLE_CONTENT_URLS.items():
|
||||
if domain in content_url:
|
||||
content_key = key
|
||||
for key, content_urls in SCROBBLE_CONTENT_URLS.items():
|
||||
for content_url in content_urls:
|
||||
if domain in content_url:
|
||||
content_key = key
|
||||
|
||||
item_id = None
|
||||
if not content_key:
|
||||
@ -343,8 +342,10 @@ def manual_scrobble_from_url(
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if content_key == "-i":
|
||||
if content_key == "-i" and "v=" in url:
|
||||
item_id = url.split("v=")[1].split("&")[0]
|
||||
elif content_key == "-i" and "title/tt" in url:
|
||||
item_id = "tt" + str(item_id)
|
||||
|
||||
scrobble_fn = MANUAL_SCROBBLE_FNS[content_key]
|
||||
return eval(scrobble_fn)(item_id, user_id, action=action)
|
||||
@ -853,3 +854,32 @@ def manual_scrobble_puzzle(
|
||||
|
||||
# TODO Kick out a process to enrich the media here, and in every scrobble event
|
||||
return Scrobble.create_or_update(puzzle, user_id, scrobble_dict)
|
||||
|
||||
|
||||
def manual_scrobble_brickset(
|
||||
brickset_id: str, user_id: int, action: Optional[str] = None
|
||||
):
|
||||
brickset = BrickSet.find_or_create(brickset_id)
|
||||
|
||||
if not brickset:
|
||||
logger.error(f"No brickset found for Brickset ID {brickset_id}")
|
||||
return
|
||||
|
||||
scrobble_dict = {
|
||||
"user_id": user_id,
|
||||
"timestamp": timezone.now(),
|
||||
"playback_position_seconds": 0,
|
||||
"source": "Vrobbler",
|
||||
}
|
||||
logger.info(
|
||||
"[vrobbler-scrobble] brickset scrobble request received",
|
||||
extra={
|
||||
"brickset_id": brickset.id,
|
||||
"user_id": user_id,
|
||||
"scrobble_dict": scrobble_dict,
|
||||
"media_type": Scrobble.MediaType.BRICKSET,
|
||||
},
|
||||
)
|
||||
|
||||
# TODO Kick out a process to enrich the media here, and in every scrobble event
|
||||
return Scrobble.create_or_update(brickset, user_id, scrobble_dict)
|
||||
|
||||
Reference in New Issue
Block a user