[scrobbles] Blacken scrobblers.py
This commit is contained in:
@ -96,14 +96,17 @@ def mopidy_scrobble_media(post_data: dict, user_id: int) -> Scrobble:
|
|||||||
user_id,
|
user_id,
|
||||||
source="Mopidy",
|
source="Mopidy",
|
||||||
playback_position_seconds=int(
|
playback_position_seconds=int(
|
||||||
post_data.get(MOPIDY_POST_KEYS.get("PLAYBACK_POSITION_TICKS"), 1) / 1000
|
post_data.get(MOPIDY_POST_KEYS.get("PLAYBACK_POSITION_TICKS"), 1)
|
||||||
|
/ 1000
|
||||||
),
|
),
|
||||||
status=post_data.get(MOPIDY_POST_KEYS.get("STATUS"), ""),
|
status=post_data.get(MOPIDY_POST_KEYS.get("STATUS"), ""),
|
||||||
log=log,
|
log=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def jellyfin_scrobble_media(post_data: dict, user_id: int) -> Optional[Scrobble]:
|
def jellyfin_scrobble_media(
|
||||||
|
post_data: dict, user_id: int
|
||||||
|
) -> Optional[Scrobble]:
|
||||||
media_type = Scrobble.MediaType.VIDEO
|
media_type = Scrobble.MediaType.VIDEO
|
||||||
if post_data.pop("ItemType", "") in JELLYFIN_AUDIO_ITEM_TYPES:
|
if post_data.pop("ItemType", "") in JELLYFIN_AUDIO_ITEM_TYPES:
|
||||||
media_type = Scrobble.MediaType.TRACK
|
media_type = Scrobble.MediaType.TRACK
|
||||||
@ -121,12 +124,13 @@ def jellyfin_scrobble_media(post_data: dict, user_id: int) -> Optional[Scrobble]
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
timestamp = parse(post_data.get(JELLYFIN_POST_KEYS.get("TIMESTAMP"), "")).replace(
|
timestamp = parse(
|
||||||
tzinfo=pytz.utc
|
post_data.get(JELLYFIN_POST_KEYS.get("TIMESTAMP"), "")
|
||||||
)
|
).replace(tzinfo=pytz.utc)
|
||||||
|
|
||||||
playback_position_seconds = int(
|
playback_position_seconds = int(
|
||||||
post_data.get(JELLYFIN_POST_KEYS.get("PLAYBACK_POSITION_TICKS"), 1) / 10000000
|
post_data.get(JELLYFIN_POST_KEYS.get("PLAYBACK_POSITION_TICKS"), 1)
|
||||||
|
/ 10000000
|
||||||
)
|
)
|
||||||
if media_type == Scrobble.MediaType.VIDEO:
|
if media_type == Scrobble.MediaType.VIDEO:
|
||||||
imdb_id = post_data.get("Provider_imdb", "")
|
imdb_id = post_data.get("Provider_imdb", "")
|
||||||
@ -136,7 +140,9 @@ def jellyfin_scrobble_media(post_data: dict, user_id: int) -> Optional[Scrobble]
|
|||||||
title=post_data.get("Name", ""),
|
title=post_data.get("Name", ""),
|
||||||
artist_name=post_data.get("Artist", ""),
|
artist_name=post_data.get("Artist", ""),
|
||||||
album_name=post_data.get("Album", ""),
|
album_name=post_data.get("Album", ""),
|
||||||
run_time_seconds=convert_to_seconds(post_data.get("RunTime", 900000)),
|
run_time_seconds=convert_to_seconds(
|
||||||
|
post_data.get("RunTime", 900000)
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# A hack because we don't worry about updating music ... we either finish it or we don't
|
# A hack because we don't worry about updating music ... we either finish it or we don't
|
||||||
playback_position_seconds = 0
|
playback_position_seconds = 0
|
||||||
@ -297,7 +303,9 @@ def manual_scrobble_book(
|
|||||||
if not page:
|
if not page:
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
logger.info("[scrobblers] Book page included in scrobble, should update!")
|
logger.info(
|
||||||
|
"[scrobblers] Book page included in scrobble, should update!"
|
||||||
|
)
|
||||||
|
|
||||||
source = READCOMICSONLINE_URL.replace("https://", "")
|
source = READCOMICSONLINE_URL.replace("https://", "")
|
||||||
|
|
||||||
@ -414,7 +422,9 @@ def email_scrobble_board_game(
|
|||||||
if not location.name:
|
if not location.name:
|
||||||
location.name = location_dict.get("name")
|
location.name = location_dict.get("name")
|
||||||
update_fields.append("name")
|
update_fields.append("name")
|
||||||
geoloc = GeoLocation.objects.filter(title__icontains=location.name).first()
|
geoloc = GeoLocation.objects.filter(
|
||||||
|
title__icontains=location.name
|
||||||
|
).first()
|
||||||
if geoloc:
|
if geoloc:
|
||||||
location.geo_location = geoloc
|
location.geo_location = geoloc
|
||||||
update_fields.append("geo_location")
|
update_fields.append("geo_location")
|
||||||
@ -466,7 +476,9 @@ def email_scrobble_board_game(
|
|||||||
log_data.pop("expansion_ids")
|
log_data.pop("expansion_ids")
|
||||||
|
|
||||||
if play_dict.get("locationRefId", False):
|
if play_dict.get("locationRefId", False):
|
||||||
log_data["location_id"] = locations[play_dict.get("locationRefId")].id
|
log_data["location_id"] = locations[
|
||||||
|
play_dict.get("locationRefId")
|
||||||
|
].id
|
||||||
if play_dict.get("rounds", False):
|
if play_dict.get("rounds", False):
|
||||||
log_data["rounds"] = play_dict.get("rounds")
|
log_data["rounds"] = play_dict.get("rounds")
|
||||||
if play_dict.get("board", False):
|
if play_dict.get("board", False):
|
||||||
@ -489,7 +501,9 @@ def email_scrobble_board_game(
|
|||||||
timestamp = parse(play_dict.get("playDate"))
|
timestamp = parse(play_dict.get("playDate"))
|
||||||
if hour and minute:
|
if hour and minute:
|
||||||
logger.info(f"Scrobble playDate has manual start time {timestamp}")
|
logger.info(f"Scrobble playDate has manual start time {timestamp}")
|
||||||
timestamp = timestamp.replace(hour=hour, minute=minute, second=second or 0)
|
timestamp = timestamp.replace(
|
||||||
|
hour=hour, minute=minute, second=second or 0
|
||||||
|
)
|
||||||
logger.info(f"Update to {timestamp}")
|
logger.info(f"Update to {timestamp}")
|
||||||
|
|
||||||
profile = UserProfile.objects.filter(user_id=user_id).first()
|
profile = UserProfile.objects.filter(user_id=user_id).first()
|
||||||
@ -584,7 +598,9 @@ def manual_scrobble_from_url(
|
|||||||
scrobbler. Otherwise, return nothing."""
|
scrobbler. Otherwise, return nothing."""
|
||||||
|
|
||||||
if RecipeScraperService.is_recipe_url(url):
|
if RecipeScraperService.is_recipe_url(url):
|
||||||
return scrobble_from_recipe_website(url, user_id, source=source, action=action)
|
return scrobble_from_recipe_website(
|
||||||
|
url, user_id, source=source, action=action
|
||||||
|
)
|
||||||
|
|
||||||
content_key = ""
|
content_key = ""
|
||||||
domain = extract_domain(url)
|
domain = extract_domain(url)
|
||||||
@ -787,7 +803,9 @@ def emacs_scrobble_update_task(
|
|||||||
if not scrobble.log.get('notes"'):
|
if not scrobble.log.get('notes"'):
|
||||||
scrobble.log["notes"] = []
|
scrobble.log["notes"] = []
|
||||||
if note.get("timestamp") not in existing_note_ts:
|
if note.get("timestamp") not in existing_note_ts:
|
||||||
scrobble.log["notes"].append({note.get("timestamp"): note.get("content")})
|
scrobble.log["notes"].append(
|
||||||
|
{note.get("timestamp"): note.get("content")}
|
||||||
|
)
|
||||||
notes_updated = True
|
notes_updated = True
|
||||||
|
|
||||||
if notes_updated:
|
if notes_updated:
|
||||||
@ -813,7 +831,9 @@ def emacs_scrobble_task(
|
|||||||
user_context_list: list[str] = [],
|
user_context_list: list[str] = [],
|
||||||
) -> Scrobble | None:
|
) -> Scrobble | None:
|
||||||
orgmode_id = task_data.get("source_id")
|
orgmode_id = task_data.get("source_id")
|
||||||
title = get_title_from_labels(task_data.get("labels", []), user_context_list)
|
title = get_title_from_labels(
|
||||||
|
task_data.get("labels", []), user_context_list
|
||||||
|
)
|
||||||
|
|
||||||
task = Task.find_or_create(title)
|
task = Task.find_or_create(title)
|
||||||
|
|
||||||
@ -936,7 +956,9 @@ def manual_scrobble_webpage(
|
|||||||
):
|
):
|
||||||
|
|
||||||
if RecipeScraperService.is_recipe_url(url):
|
if RecipeScraperService.is_recipe_url(url):
|
||||||
return scrobble_from_recipe_website(url, user_id, source=source, action=action)
|
return scrobble_from_recipe_website(
|
||||||
|
url, user_id, source=source, action=action
|
||||||
|
)
|
||||||
|
|
||||||
webpage = WebPage.find_or_create({"url": url})
|
webpage = WebPage.find_or_create({"url": url})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user