Yooooomi / your_spotify

Self hosted Spotify tracking dashboard
GNU General Public License v3.0
2.77k stars 110 forks source link

import extended streaming history error: "Expected string, received null" #291

Closed jakesmorrison closed 10 months ago

jakesmorrison commented 10 months ago

Describe the bug

When importing extended streaming history data I get the following error:

{
  "code": "invalid_type",
  "expected": "string",
  "received": "null",
  "path": [ "reason_end"],
  "message": "Expected string, received null"
}
[error]  TypeError: Cannot read properties of null (reading 'length')
    at FullPrivacyImporter.<anonymous> (/app/lib/tools/importers/full_privacy.js:107:51)
    at Generator.next (<anonymous>)
    at fulfilled (/app/lib/tools/importers/full_privacy.js:5:58)

I requested my streaming history 3 weeks ago and received it today. The json naming is not "endsong". It is "Streaming_History_Audio". I have manually changed it to endsong, but I am getting a format error. I am guessing the output format has changed?

Expected behavior

When I go from Settings -> Account -> Import Data, click "extended streaming history" and add my endsong.json I expect the data to be added to the your_spotify app. This process worked with 1 of my json files.

Additional context

Docker compose

image

Shared link

Let me figure out how to get a shared link. I will update with it.

jakesmorrison commented 10 months ago

I ran a python script to see what all the possible values of reason_end

Reason End
['trackdone', 'playbtn', 'endplay', 'fwdbtn', 'backbtn', 'unexpected-exit-while-paused', 'clickrow', None, 'logout', 'unknown', 'unexpected-exit']

It looks like there is a None (Null). I ended up fixing this issue by cleaning up those values with this snippet. After running the code I am able to import the data.

import json
with open('endsong.json') as f:
    d = json.load(f)

for x in d:
    if x['reason_end'] == None:
        x['reason_end'] = 'endplay'
with open('endsong_clean.json', 'w') as f:
    json.dump(d, f)
LucasGenoud commented 10 months ago

Thank you !

I've adapted your script a little bit to read all the json files in the current folder since I have multiple file exports and they don't event end with endSong... I also just replace the original file

import json
import os

json_files = [file for file in os.listdir() if file.endswith('.json')]

for filename in json_files:
    with open(filename, 'r') as f:
        d = json.load(f)

    for x in d:
        if x['reason_end'] is None:
            x['reason_end'] = 'endplay'

    with open(filename, 'w') as f:
        json.dump(d, f)
Yooooomi commented 10 months ago

Should be fixed with latest release 1.7.1.