feat(import): keep the artist and the time of plays of artists I do not have

The plays of songs that are not in the library were only counted. Now, when
such a play counts as listened (not a skip, long enough), its artist and its
time are kept in a new table (migration 0031, outside_plays), so a model can
later learn which artists are played together, also those not in the library.
No title, album, IP address, country or platform is stored. The same play is
kept once however many times the export is imported, and the report says how
many were kept (history.kept_outside).
This commit is contained in:
tgiachi 2026-11-15 10:50:29 +01:00
commit 3ba087bcc5
7 changed files with 314 additions and 28 deletions

View file

@ -1572,7 +1572,9 @@ export interface paths {
*
* Everything happens on this server and nothing is sent to anyone. The files are read from the request and not
* kept, and of each play only the song, the artist, the album, the time and how it ended are read: the IP
* addresses, the country and the platform in the file are never looked at.
* addresses, the country and the platform in the file are never looked at. Of a play that is not in your
* library and counts as listened, the name of the artist and the time are kept (and nothing else), so that
* Sonda can learn which artists you play together.
*
* A play is matched to a song of your library by artist and title (case, accents and punctuation do not matter,
* a "Remastered" note on either side does not either, and any of the credited artists will do; a play of a
@ -3836,6 +3838,8 @@ export interface components {
not_found: number;
/** @description Podcast episodes, and plays with no time that can be read. */
ignored: number;
/** @description Of the plays not in your library, the ones that count as listened, whose artist and time are kept to learn what you listen to together (never the title, the album or anything else). */
kept_outside: number;
};
playlists: {
name: string;

View file

@ -12,7 +12,7 @@ beforeEach(async () => {
const report: SpotifyImportReport = {
id: 3,
created_at: '2026-11-15T10:00:00Z',
history: { entries: 120, matched: 100, imported: 80, already_there: 20, not_found: 20, ignored: 3 },
history: { entries: 120, matched: 100, imported: 80, already_there: 20, not_found: 20, ignored: 3, kept_outside: 12 },
playlists: [
{ name: 'Road', tracks: 20, matched: 15, status: 'created' },
{ name: 'Mine', tracks: 5, matched: 5, status: 'exists' },
@ -29,6 +29,12 @@ test('a card says when the import was done and what it did', () => {
expect(within(card).getByText('20 were already there.')).toBeInTheDocument()
expect(within(card).getByText('20 plays are of songs that are not in your library.')).toBeInTheDocument()
expect(within(card).getByText(/3 plays skipped/)).toBeInTheDocument()
expect(within(card).getByText('Of those, 12 plays were kept as an artist and a time only, to learn what you listen to together.')).toBeInTheDocument()
})
test('an import that kept nothing for learning does not mention it', () => {
render(<ImportReportCard report={{ ...report, history: { ...report.history, kept_outside: 0 } }} />)
expect(screen.queryByText(/kept as an artist and a time/)).not.toBeInTheDocument()
})
test('the playlists say what became of each', () => {
@ -50,7 +56,7 @@ test('the missing artists are behind a summary that counts them, most played fir
test('an import with nothing to show says so, and has no empty lists', () => {
render(
<ImportReportCard
report={{ ...report, history: { entries: 0, matched: 0, imported: 0, already_there: 0, not_found: 0, ignored: 0 }, playlists: [], missing: { total: 0, artists: [] } }}
report={{ ...report, history: { entries: 0, matched: 0, imported: 0, already_there: 0, not_found: 0, ignored: 0, kept_outside: 0 }, playlists: [], missing: { total: 0, artists: [] } }}
/>,
)
expect(screen.getByText('No plays in these files.')).toBeInTheDocument()

View file

@ -26,6 +26,7 @@ export default function ImportReportCard({ report }: { report: SpotifyImportRepo
{h.already_there > 0 && <li>{t('spotify.already', { count: h.already_there })}</li>}
{h.not_found > 0 && <li>{t('spotify.notFound', { count: h.not_found })}</li>}
{h.ignored > 0 && <li>{t('spotify.ignored', { count: h.ignored })}</li>}
{h.kept_outside > 0 && <li className="text-sm text-muted-foreground">{t('spotify.keptOutside', { count: h.kept_outside })}</li>}
</ul>
)
)}

View file

@ -14,7 +14,7 @@ beforeEach(async () => {
const report = {
id: 3,
created_at: '2026-11-15T10:00:00Z',
history: { entries: 120, matched: 100, imported: 80, already_there: 20, not_found: 20, ignored: 3 },
history: { entries: 120, matched: 100, imported: 80, already_there: 20, not_found: 20, ignored: 3, kept_outside: 12 },
playlists: [
{ name: 'Road', tracks: 20, matched: 15, status: 'created' },
{ name: 'Mine', tracks: 5, matched: 5, status: 'exists' },

View file

@ -789,7 +789,7 @@
},
"spotify": {
"intro": "Bring in your listening history and your playlists from Spotify, so that your mixes, Discover and smart playlists know what you listened to before. Ask Spotify for your data (Account, Privacy, “Extended streaming history” and “Account data”), then choose the zip it sends you, or the JSON files inside it.",
"privacy": "Everything is read on your server. Nothing is sent anywhere and the files are not kept. Songs are matched to your library by artist and title; the ones you do not have are only counted.",
"privacy": "Everything is read on your server. Nothing is sent anywhere and the files are not kept. Songs are matched to your library by artist and title. Of the plays of songs you do not have, only the artist and the time are kept, to learn what you listen to together.",
"files": "Files from Spotify",
"chosen_one": "{{count}} file chosen",
"chosen_other": "{{count}} files chosen",
@ -808,6 +808,8 @@
"already_other": "{{count}} were already there.",
"notFound_one": "{{count}} play is of a song that is not in your library.",
"notFound_other": "{{count}} plays are of songs that are not in your library.",
"keptOutside_one": "Of those, {{count}} play was kept as an artist and a time only, to learn what you listen to together.",
"keptOutside_other": "Of those, {{count}} plays were kept as an artist and a time only, to learn what you listen to together.",
"ignored_one": "{{count}} play skipped (a podcast, or with no readable time).",
"ignored_other": "{{count}} plays skipped (podcasts, or with no readable time).",
"playlists": "Playlists",

View file

@ -789,7 +789,7 @@
},
"spotify": {
"intro": "Porta qui la cronologia di ascolto e le playlist di Spotify, così i tuoi mix, Discover e le smart playlist sanno cosa ascoltavi prima. Chiedi a Spotify i tuoi dati (Account, Privacy, «Cronologia di streaming estesa» e «Dati dell'account»), poi scegli lo zip che ti manda, oppure i file JSON che contiene.",
"privacy": "Tutto viene letto sul tuo server. Non viene inviato niente a nessuno e i file non vengono conservati. I brani si abbinano alla tua libreria per artista e titolo; quelli che non hai vengono solo contati.",
"privacy": "Tutto viene letto sul tuo server. Non viene inviato niente a nessuno e i file non vengono conservati. I brani si abbinano alla tua libreria per artista e titolo. Degli ascolti dei brani che non hai si conservano solo artista e orario, per imparare cosa ascolti insieme.",
"files": "File di Spotify",
"chosen_one": "{{count}} file scelto",
"chosen_other": "{{count}} file scelti",
@ -808,6 +808,8 @@
"already_other": "{{count}} c'erano già.",
"notFound_one": "{{count}} ascolto è di un brano che non è nella tua libreria.",
"notFound_other": "{{count}} ascolti sono di brani che non sono nella tua libreria.",
"keptOutside_one": "Di questi, {{count}} ascolto è stato conservato solo come artista e orario, per imparare cosa ascolti insieme.",
"keptOutside_other": "Di questi, {{count}} ascolti sono stati conservati solo come artista e orario, per imparare cosa ascolti insieme.",
"ignored_one": "{{count}} ascolto saltato (un podcast, o senza un orario leggibile).",
"ignored_other": "{{count}} ascolti saltati (podcast, o senza un orario leggibile).",
"playlists": "Playlist",

View file

@ -15,7 +15,7 @@ beforeEach(async () => {
const run = (id: number, imported: number, at: string) => ({
id,
created_at: at,
history: { entries: imported + 5, matched: imported, imported, already_there: 0, not_found: 5, ignored: 0 },
history: { entries: imported + 5, matched: imported, imported, already_there: 0, not_found: 5, ignored: 0, kept_outside: 4 },
playlists: [],
missing: { total: 1, artists: [{ name: 'Blur', count: 5 }] },
})