A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
98
fork

Configure Feed

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

feat(tealfm): implement recent plays check in teal.fm publishPlayingNow to avoid duplicate scrobbles and enable teal.fm for all

+36 -2
+1 -1
apps/api/src/nowplaying/nowplaying.service.ts
··· 847 847 ); 848 848 } 849 849 850 - if (userDid === "did:plc:7vdlgi2bflelz7mmuxoqjfcr" && mbTrack?.trackMBID) { 850 + if (mbTrack?.trackMBID) { 851 851 mbTrack.timestamp = track.timestamp 852 852 ? dayjs.unix(track.timestamp).toISOString() 853 853 : new Date().toISOString();
+35 -1
apps/api/src/tealfm/index.ts
··· 6 6 7 7 const SUBMISSION_CLIENT_AGENT = "rocksky/v0.0.1"; 8 8 9 + async function getRecentPlays(agent: Agent, limit = 5) { 10 + const res = await agent.com.atproto.repo.listRecords({ 11 + repo: agent.assertDid, 12 + collection: "fm.teal.alpha.feed.play", 13 + limit, 14 + reverse: true, 15 + }); 16 + return res.data.records; 17 + } 18 + 9 19 async function publishPlayingNow( 10 20 agent: Agent, 11 21 track: MusicbrainzTrack, 12 - duration: number, 22 + duration: number 13 23 ) { 14 24 try { 25 + const recentPlays = await getRecentPlays(agent, 5); 26 + // Check if the track was played in the last 5 plays (verify by MBID and timestamp to avoid duplicates) 27 + const alreadyPlayed = recentPlays.some((play) => { 28 + const record = Play.isRecord(play.value) ? play.value : null; 29 + return ( 30 + record?.recordingMbId === track.trackMBID && 31 + // diff in seconds less than 60 32 + Math.abs( 33 + new Date(record.playedTime).getTime() - 34 + new Date(track.timestamp).getTime() 35 + ) < 60000 36 + ); 37 + }); 38 + if (alreadyPlayed) { 39 + console.log( 40 + chalk.yellow( 41 + `Track ${chalk.cyan(track.name)} by ${chalk.cyan( 42 + track.artist.map((a) => a.name).join(", ") 43 + )} already played recently. Skipping...` 44 + ) 45 + ); 46 + return; 47 + } 48 + 15 49 const rkey = TID.nextStr(); 16 50 const record: Play.Record = { 17 51 $type: "fm.teal.alpha.feed.play",