Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track Spotify play history similar to Now Playing? #334

Closed
4 tasks done
Tracked by #199
lydavid opened this issue Jul 30, 2023 · 2 comments · Fixed by #888
Closed
4 tasks done
Tracked by #199

track Spotify play history similar to Now Playing? #334

lydavid opened this issue Jul 30, 2023 · 2 comments · Fixed by #888
Labels
enhancement New feature or request

Comments

@lydavid
Copy link
Owner

lydavid commented Jul 30, 2023

  • don't increment the same track's listen count if the elapsed time is less than its track length. Rather than calculating this ourselves, https://developer.spotify.com/documentation/android/tutorials/android-media-notifications provides us timeSent which we can use as part of the primary key when inserting
  • don't increment the current track if nothing is playing. Even if nothing is playing, our broadcast receiver will have Spotify's last played track
  • would be nice to have broadcast listener start from home screen, or in background, so that no matter what screen user is on, it will keep recording. see now playing
  • instead of counting how many times the user listened to a track, track it chronologically similar to Spotify's Recently played. later, we can group by track_id if we want that info
  • overlay to nav to search artist/rg/rec? is presenter overkill here?
@lydavid lydavid added the enhancement New feature or request label Apr 1, 2024
@lydavid
Copy link
Owner Author

lydavid commented Apr 30, 2024

SQLDelight seems to generate this upsert function with a Long type if I used number_of_listens = :numberOfListens + 1,, whereas number_of_listens = number_of_listens + 1, will make it an Int, which is what I want.

upsert {
  UPDATE spotify_history
  SET artist_name = :artistName,
    album_name = :albumName,
    track_name = :trackName,
    track_length = :trackLength,
    number_of_listens = number_of_listens + 1,
    last_listened = :lastListened
  WHERE track_id = :trackId;

  INSERT OR IGNORE INTO spotify_history
  VALUES (
    :trackId,
    :artistName,
    :albumName,
    :trackName,
    :trackLength,
    :numberOfListens,
    :lastListened
  );
}

The table for reference:

CREATE TABLE IF NOT EXISTS spotify_history (
  `track_id` TEXT PRIMARY KEY NOT NULL,
  `artist_name` TEXT,
  `album_name` TEXT,
  `track_name` TEXT,
  `track_length` INTEGER AS Int,
  `number_of_listens` INTEGER AS Int NOT NULL,
  `last_listened` INTEGER AS Instant NOT NULL
);

@lydavid lydavid linked a pull request May 1, 2024 that will close this issue
@lydavid
Copy link
Owner Author

lydavid commented May 1, 2024

An interesting observation while working with sql and lazy Compose is we will often use the primary key as the id.
eg. id = "$trackId$lastListened",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant