A Wrapped / Replay like for teal.fm and rocksky.app (currently on hiatus)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

filter out duplicate scrobbles

Mia 64fd1b01 05ed06cb

+26 -5
+26 -5
src/ingest/scrobbles.rs
··· 1 1 use crate::mbz::{FindMbzData, try_find_mbz_data}; 2 2 use chrono::prelude::*; 3 - use duckdb::{Connection, DuckdbConnectionManager, params}; 3 + use duckdb::{Connection, DuckdbConnectionManager, OptionalExt, params}; 4 4 use jacquard::types::datetime::Datetime; 5 5 use jacquard_api::app_rocksky::scrobble::Scrobble as RockskyScrobble; 6 6 use jacquard_api::fm_teal::alpha::feed::play::Play as TealAlphaPlay; ··· 16 16 let created = scrobble.played_time.unwrap_or(Datetime::now()); 17 17 let created = created.as_ref().to_utc(); 18 18 19 - // TODO: check track name and time (and artist?) to see if there's already been a scrobble. 20 - // this is notably an issue with the dual rocksky-teal records. 19 + if let Some(rkey) = check_duplicate_scrobble(&conn, did, &scrobble.track_name, created)? { 20 + tracing::debug!("skipping duplicate scrobble of {rkey}"); 21 + return Ok(()); 22 + } 21 23 22 24 let artist = scrobble 23 25 .artists ··· 45 47 let conn = db.connect()?; 46 48 let created = scrobble.created_at.as_ref().to_utc(); 47 49 48 - // TODO: check track name and time (and artist?) to see if there's already been a scrobble. 49 - // this is notably an issue with the dual rocksky-teal records. 50 + if let Some(rkey) = check_duplicate_scrobble(&conn, did, &scrobble.title, created)? { 51 + tracing::debug!("skipping duplicate scrobble of {rkey}"); 52 + return Ok(()); 53 + } 50 54 51 55 let find = FindMbzData { 52 56 release_name: Some(&scrobble.album), ··· 104 108 105 109 Ok(()) 106 110 } 111 + 112 + fn check_duplicate_scrobble( 113 + conn: &Connection, 114 + did: &str, 115 + track: &str, 116 + created: DateTime<Utc>, 117 + ) -> eyre::Result<Option<String>> { 118 + let mut stmt = conn.prepare_cached( 119 + "SELECT rkey FROM scrobbles WHERE did = $1 AND track_name = $2 AND created_at = $3", 120 + )?; 121 + 122 + let rkey = stmt 123 + .query_one(params![did, track, created], |row| row.get(0)) 124 + .optional()?; 125 + 126 + Ok(rkey) 127 + }