here’s the output of a lastfm export to csv. the Loved columnn is 0 for not loved and 1 for loved. I’m not a programmer. I’ve been using GPT(both openai GPT 3.5, and googles Bard), Bard has heard of pythonlistenbrainz but doesn’t know enough about it and openai, has no clue about it I’m just looking for a python script to import this format csv, both scrobbles and loved tracks. If anyone can help I’d appreciate it.
I don’t use LB so I haven’t tested that the submission code works, but I think that something similar to this should work for importing the listens without the “loved” data:
#!/usr/bin/env python3
import csv
import pylistenbrainz
import sys
import time
MAX_LISTENS_PER_REQUEST = 1000
if len(sys.argv) != 2:
print("Usage: %s <csv-file>" % sys.argv[0], file=sys.stderr)
sys.exit(2)
auth_token = input('Please enter your auth token: ')
client = pylistenbrainz.ListenBrainz()
client.set_auth_token(auth_token)
def submit_listens(listens):
print("Submitting %d listen(s)..." % len(listens))
response = client.submit_multiple_listens(listens)
assert response['status'] == 'ok'
listens = []
with open(sys.argv[1], newline='') as f:
reader = csv.reader(f, dialect='unix')
next(reader, None) # skip header row
for row in reader:
tm = time.strptime(row[3], '%Y-%m-%d %H:%M:%S')
listens.append(pylistenbrainz.Listen(
track_name=row[0],
artist_name=row[1],
release_name=row[2],
listened_at=int(time.mktime(tm)),
))
if len(listens) >= MAX_LISTENS_PER_REQUEST:
submit_listens(listens)
listens = []
if len(listens) > 0:
submit_listens(listens)
Presumably it’d be possible to run a separate small script that uses the metadata endpoint as described at Usage Examples — ListenBrainz 0.1.0 documentation to look up MBIDs and submit the “loved” data.
One way is to first look up the recording by artist name and track title using the /1/metadata/lookup endpoint (documentation) and the us the recording_mbid from the result to submit the loved track.
Of course there is some potential for wrong mapping. But as I understand the underlying functionality is the same that LB also uses to match submitted tracks without MBID, and this in my experience works rather well.