[beers] Add manual scrobbling from URLs
This commit is contained in:
@ -57,13 +57,19 @@ class Beer(ScrobblableMixin):
|
|||||||
BeerProducer, on_delete=models.DO_NOTHING, **BNULL
|
BeerProducer, on_delete=models.DO_NOTHING, **BNULL
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self) -> str:
|
||||||
return reverse("beers:beer_detail", kwargs={"slug": self.uuid})
|
return reverse("beers:beer_detail", kwargs={"slug": self.uuid})
|
||||||
|
|
||||||
def beeradvocate_link(self):
|
def beeradvocate_link(self):
|
||||||
|
if self.producer and self.beeradvocate_id:
|
||||||
|
if self.beeradvocate_id:
|
||||||
|
link = f"https://www.beeradvocate.com/beer/profile/{self.producer.beeradvocate_id}/{self.beeradvocate_id}/"
|
||||||
|
return link
|
||||||
|
|
||||||
|
def untappd_link(self) -> str:
|
||||||
link = ""
|
link = ""
|
||||||
if self.beeradvocate_id and self.producer:
|
if self.untappd_id:
|
||||||
link = f"https://www.beeradvocate.com/beer/profile/{self.producer.beeradvocate_id}/{self.beeradvocate_id}/"
|
link = f"https://www.untappd.com/beer/{self.untappd_id}/"
|
||||||
return link
|
return link
|
||||||
|
|
||||||
def primary_image_url(self) -> str:
|
def primary_image_url(self) -> str:
|
||||||
@ -77,8 +83,8 @@ class Beer(ScrobblableMixin):
|
|||||||
return BeerLogData
|
return BeerLogData
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_or_create(cls, title: str) -> "Beer":
|
def find_or_create(cls, untappd_id: str) -> "Beer":
|
||||||
return cls.objects.filter(title=title).first()
|
return cls.objects.filter(untappd_id=untappd_id).first()
|
||||||
|
|
||||||
def scrobbles(self, user_id):
|
def scrobbles(self, user_id):
|
||||||
Scrobble = apps.get_model("scrobbles", "Scrobble")
|
Scrobble = apps.get_model("scrobbles", "Scrobble")
|
||||||
|
|||||||
@ -30,7 +30,8 @@ SCROBBLE_CONTENT_URLS = {
|
|||||||
"-i": "https://www.imdb.com/title/",
|
"-i": "https://www.imdb.com/title/",
|
||||||
"-s": "https://www.thesportsdb.com/event/",
|
"-s": "https://www.thesportsdb.com/event/",
|
||||||
"-g": "https://boardgamegeek.com/boardgame/",
|
"-g": "https://boardgamegeek.com/boardgame/",
|
||||||
"-d": "https://beeradvocate.com/beer/profile/",
|
"-ba": "https://beeradvocate.com/beer/profile/{producer_id}/{id}/",
|
||||||
|
"-u": "https://untappd.com/beer/{id}",
|
||||||
"-b": "https://www.amazon.com/",
|
"-b": "https://www.amazon.com/",
|
||||||
"-t": "https://app.todoist.com/app/task/{id}",
|
"-t": "https://app.todoist.com/app/task/{id}",
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import re
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import pendulum
|
import pendulum
|
||||||
import pytz
|
import pytz
|
||||||
|
from beers.models import Beer
|
||||||
from boardgames.models import BoardGame
|
from boardgames.models import BoardGame
|
||||||
from books.models import Book
|
from books.models import Book
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@ -15,23 +16,24 @@ from music.constants import JELLYFIN_POST_KEYS, MOPIDY_POST_KEYS
|
|||||||
from music.models import Track
|
from music.models import Track
|
||||||
from music.utils import get_or_create_track
|
from music.utils import get_or_create_track
|
||||||
from podcasts.utils import get_or_create_podcast
|
from podcasts.utils import get_or_create_podcast
|
||||||
from scrobbles.constants import JELLYFIN_AUDIO_ITEM_TYPES
|
|
||||||
from scrobbles.models import Scrobble
|
|
||||||
from sports.models import SportEvent
|
|
||||||
from sports.thesportsdb import lookup_event_from_thesportsdb
|
|
||||||
from videogames.howlongtobeat import lookup_game_from_hltb
|
|
||||||
from videogames.models import VideoGame
|
|
||||||
from videos.models import Video
|
|
||||||
from scrobbles.constants import (
|
from scrobbles.constants import (
|
||||||
|
JELLYFIN_AUDIO_ITEM_TYPES,
|
||||||
MANUAL_SCROBBLE_FNS,
|
MANUAL_SCROBBLE_FNS,
|
||||||
SCROBBLE_CONTENT_URLS,
|
SCROBBLE_CONTENT_URLS,
|
||||||
)
|
)
|
||||||
|
from scrobbles.models import Scrobble
|
||||||
|
from sports.models import SportEvent
|
||||||
|
from sports.thesportsdb import lookup_event_from_thesportsdb
|
||||||
from tasks.models import Task
|
from tasks.models import Task
|
||||||
|
from videogames.howlongtobeat import lookup_game_from_hltb
|
||||||
|
from videogames.models import VideoGame
|
||||||
|
from videos.models import Video
|
||||||
|
from webpages.models import WebPage
|
||||||
|
|
||||||
from vrobbler.apps.tasks.constants import (
|
from vrobbler.apps.tasks.constants import (
|
||||||
TODOIST_TITLE_PREFIX_LABELS,
|
TODOIST_TITLE_PREFIX_LABELS,
|
||||||
TODOIST_TITLE_SUFFIX_LABELS,
|
TODOIST_TITLE_SUFFIX_LABELS,
|
||||||
)
|
)
|
||||||
from webpages.models import WebPage
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -345,9 +347,7 @@ def todoist_scrobble_task(todoist_task: dict, user_id: int) -> Scrobble:
|
|||||||
log__todoist_id=todoist_task.get("todoist_id"),
|
log__todoist_id=todoist_task.get("todoist_id"),
|
||||||
task=task,
|
task=task,
|
||||||
).last()
|
).last()
|
||||||
in_progress_in_todoist = (
|
in_progress_in_todoist = "inprogress" in todoist_task["todoist_label_list"]
|
||||||
"inprogress" in todoist_task["todoist_label_list"]
|
|
||||||
)
|
|
||||||
# We need either an in-progress scrobble OR an in-progress todoist task
|
# We need either an in-progress scrobble OR an in-progress todoist task
|
||||||
if not in_progress_scrobble and not in_progress_in_todoist:
|
if not in_progress_scrobble and not in_progress_in_todoist:
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -556,3 +556,30 @@ def web_scrobbler_scrobble_video_or_song(
|
|||||||
if episode:
|
if episode:
|
||||||
scrobble = Scrobble.create_or_update(episode, user_id, mopidy_data)
|
scrobble = Scrobble.create_or_update(episode, user_id, mopidy_data)
|
||||||
return scrobble
|
return scrobble
|
||||||
|
|
||||||
|
|
||||||
|
def manual_scrobble_beer(untappd_id: str, user_id: int):
|
||||||
|
beer = Beer.find_or_create(untappd_id)
|
||||||
|
|
||||||
|
if not beer:
|
||||||
|
logger.error(f"No beer found for Untappd ID {untappd_id}")
|
||||||
|
return
|
||||||
|
|
||||||
|
scrobble_dict = {
|
||||||
|
"user_id": user_id,
|
||||||
|
"timestamp": timezone.now(),
|
||||||
|
"playback_position_seconds": 0,
|
||||||
|
"source": "Vrobbler",
|
||||||
|
}
|
||||||
|
logger.info(
|
||||||
|
"[vrobbler-scrobble] beer scrobble request received",
|
||||||
|
extra={
|
||||||
|
"beer_id": beer.id,
|
||||||
|
"user_id": user_id,
|
||||||
|
"scrobble_dict": scrobble_dict,
|
||||||
|
"media_type": Scrobble.MediaType.BEER,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# TODO Kick out a process to enrich the media here, and in every scrobble event
|
||||||
|
return Scrobble.create_or_update(beer, user_id, scrobble_dict)
|
||||||
|
|||||||
Reference in New Issue
Block a user