Skip to content

Commit b02b30f

Browse files
authored
add conditio to now playing track - it does not have date yet (#1)
1 parent 117bdea commit b02b30f

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Check
22

3-
on: push
3+
on:
4+
- push
5+
- pull_request
46

57
jobs:
68
qa:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ supabase start
3838
supabase function serve --no-verify-jwt
3939
```
4040

41+
**deploy modified function**
42+
43+
```bash
44+
supabase functions deploy --project-ref xxx
45+
```

supabase/functions/fetch-scrobbles/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ Deno.serve(async () => {
7878

7979
console.log(`Fetching page ${page}/${totalPages}`);
8080

81-
const toInsert: Row[] = tracks.map((track) => ({
82-
created_at: new Date().toISOString(),
83-
listened_at: new Date(track.date.uts * 1000).toISOString(),
84-
artist_name: track.artist.name,
85-
track_name: track.name,
86-
album_name: track.album["#text"],
87-
lastfm_data: track,
88-
}));
81+
const toInsert: Row[] = tracks
82+
.filter((track) => !(track["@attr"] && track["@attr"].nowplaying))
83+
.map((track) => ({
84+
created_at: new Date().toISOString(),
85+
listened_at: new Date(track.date!.uts * 1000).toISOString(),
86+
artist_name: track.artist.name,
87+
track_name: track.name,
88+
album_name: track.album["#text"],
89+
lastfm_data: track,
90+
}));
8991

9092
const { error, message } = await table.save(toInsert);
9193
if (error) {

supabase/functions/fetch-scrobbles/lastfm.types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ interface Artist {
1212

1313
interface Track {
1414
artist: Artist;
15-
date: {
15+
// date is present only when the track is not playing right now...
16+
date?: {
1617
uts: number;
1718
"#text": string;
1819
};
@@ -26,6 +27,10 @@ interface Track {
2627
"#text": string;
2728
};
2829
loved: string;
30+
// present only when it is playing, weird I know
31+
"@attr"?: {
32+
nowplaying: boolean;
33+
};
2934
}
3035

3136
interface Attributes {

0 commit comments

Comments
 (0)