Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fedecalendino/spotify-data-reader
https://github.com/fedecalendino/spotify-data-reader
spotify spotify-data
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fedecalendino/spotify-data-reader
- Owner: fedecalendino
- Created: 2020-11-04T16:57:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-16T12:42:05.000Z (over 1 year ago)
- Last Synced: 2024-06-19T06:04:22.533Z (3 months ago)
- Topics: spotify, spotify-data
- Language: Python
- Homepage: https://support.stats.fm/docs/import/spotify-import/
- Size: 1.55 MB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SPOTIFY-DATA-READER
Tiny tool to read Spotify's extended streaming history, you can follow [this guide](https://support.stats.fm/docs/import/spotify-import/) to get yours.
Once you download your streaming history, you are going to see a zip file containing multiple json files.
Put all of them into the `data` folder so the tool can find them.# json files contents
```json
[
...,
{
"conn_country": "SI",
"episode_name": null,
"episode_show_name": null,
"incognito_mode": false,
"ip_addr_decrypted": "1.2.3.4",
"master_metadata_album_album_name": "Humanz",
"master_metadata_album_artist_name": "Gorillaz",
"master_metadata_track_name": "Andromeda (feat. DRAM)",
"ms_played": 8778,
"offline": false,
"offline_timestamp": 1572964071330,
"platform": "OS X 10.15.1 [x86 8]",
"reason_end": "endplay",
"reason_start": "clickrow",
"shuffle": true,
"skipped": null,
"spotify_episode_uri": null,
"spotify_track_uri": "spotify:track:2C0KFbb4v9CNWR5c9jWcKC",
"ts": "2019-11-05T14:28:00Z",
"user_agent_decrypted": "unknown",
"username": "username"
},
...,
]
```## usage
```python
from collections import Counterfrom reader import streaming_history
def top_songs(year: int = None):
tracks = []for item in streaming_history():
if year is not None:
if item.playback.timestamp.year != year:
continueif item.track:
tracks.append(
(
item.track.name,
item.track.artist,
)
)for (track, artist), counter in Counter(tracks).most_common(5):
print(f"{track} by {artist} [{counter}]")top_songs()
# >> Andromeda (feat. DRAM) by Gorillaz [877]
# >> Undercover Martyn by Two Door Cinema Club [682]
# >> Sleeping Powder by Gorillaz [669]
# >> Submission (feat. Danny Brown & Kelela) by Gorillaz [666]
# >> On Melancholy Hill by Gorillaz [606]
```