From 89a2918f0a1abb106743632b0761ad79d4f85c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Tue, 16 Nov 2021 23:00:45 +0100 Subject: [PATCH] Initial commit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Abdulkadir Furkan Şanlı --- lb_import.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 lb_import.py diff --git a/lb_import.py b/lb_import.py new file mode 100755 index 0000000..4f6f124 --- /dev/null +++ b/lb_import.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import json +import pylistenbrainz +import sys + +auth_token = sys.argv[1] +client = pylistenbrainz.ListenBrainz() +client.set_auth_token(auth_token) + +with open(sys.argv[2], "r") as read_file: + data = json.load(read_file) + +for raw in data: + listen = pylistenbrainz.Listen( + track_name = raw['track_metadata']['track_name'], + artist_name = raw['track_metadata']['artist_name'] + ) + if 'listened_at' in raw: + listen.listened_at = raw['listened_at'] + if 'user_name' in raw: + listen.username = raw['user_name'] + if 'release_name' in raw['track_metadata']: + listen.release_name = raw['track_metadata']['release_name'] + if 'additional_info' in raw['track_metadata']: + listen.additional_info = raw['track_metadata']['additional_info'] + if 'tracknumber' in raw['track_metadata']['additional_info']: + listen.tracknumber = raw['track_metadata']['additional_info']['tracknumber'] + if 'spotify_id' in raw['track_metadata']['additional_info']: + listen.spotify_id = raw['track_metadata']['additional_info']['spotify_id'] + if 'isrc' in raw['track_metadata']['additional_info']: + listen.spotify_id = raw['track_metadata']['additional_info']['isrc'] + if 'listening_from' in raw['track_metadata']['additional_info']: + listen.listening_from = raw['track_metadata']['additional_info']['listening_from'] + if 'mbid_mapping' in raw['track_metadata']: + if 'recording_mbid' in raw['track_metadata']['mbid_mapping']: + listen.recording_mbid = raw['track_metadata']['mbid_mapping']['recording_mbid'] + if 'artist_mbids' in raw['track_metadata']['mbid_mapping']: + listen.artist_mbids = raw['track_metadata']['mbid_mapping']['artist_mbids'] + if 'release_mbid' in raw['track_metadata']['mbid_mapping']: + listen.release_mbid = raw['track_metadata']['mbid_mapping']['release_mbid'] + response = client.submit_single_listen(listen) + assert response['status'] == 'ok'