idk i added a bunch of stuff like a month ago
This commit is contained in:
1 parent
95c4dc96f6
commit
851d5ebb35
13 files changed
+5044
-40
No files matched your search
+32
-3
@@ -6,6 +6,7 @@ import musicbrainzngs
|
||||
import flask
|
||||
|
||||
import ListenBrainz
|
||||
import MusicDatabase
|
||||
|
||||
logging.basicConfig(
|
||||
format="%(levelname)s %(module)s::%(filename)s::%(funcName)s %(asctime)s - %(message)s",
|
||||
@@ -27,14 +28,42 @@ def get_mbid(scrobble: ListenBrainz.ListenBrainzScrobble) -> tuple[str, str, lis
|
||||
|
||||
result = musicbrainzngs.search_recordings(f"{scrobble.track_name} {scrobble.release_name}", artist=scrobble.artist_name, **optional_args)
|
||||
|
||||
# logging.debug(json.dumps(result, indent=4))
|
||||
with open('listen-brain-request.json', 'w') as file:
|
||||
file.write(json.dumps(result, indent=4))
|
||||
|
||||
top_result: dict = result['recording-list'][0]
|
||||
|
||||
track_mbid: str = top_result['id']
|
||||
album_mbid: str = top_result['release-list'][0]['id']
|
||||
artist_mbids: list[str] = [artist['artist']['id'] for artist in top_result['artist-credit']]
|
||||
# print(json.dumps(top_result, indent=4))
|
||||
|
||||
track_mbid: str = top_result['id']
|
||||
track_name: str = top_result['title']
|
||||
album_mbid: str = top_result['release-list'][0]['id']
|
||||
album_name: str = top_result['release-list'][0]['title']
|
||||
# print(json.dumps(top_result['']))
|
||||
artist_mbids: list[str] = [artist['artist']['id'] for artist in top_result['artist-credit']]
|
||||
artist_names: list[str] = [artist['name'] for artist in top_result['artist-credit']]
|
||||
|
||||
logging.debug(f'Matched scrobble with {track_name=} {album_name=} {artist_names=}')
|
||||
return (track_mbid, album_mbid, artist_mbids)
|
||||
|
||||
def record_scrobble(scrobble: ListenBrainz.ListenBrainzScrobble) -> None:
|
||||
track_mbid, album_mbid, artist_mbids = get_mbid(scrobble)
|
||||
|
||||
if not (album := MusicDatabase.search_album_by_mbid(album_mbid)):
|
||||
album = MusicDatabase.insert_album(scrobble.release_name, album_mbid)
|
||||
|
||||
artists: list[MusicDatabase.Artist] = []
|
||||
for artist_mbid in artist_mbids:
|
||||
if not (artist := MusicDatabase.search_artist_by_mbid(artist_mbid)):
|
||||
artists.append(MusicDatabase.insert_artist(scrobble.artist_name, artist_mbid))
|
||||
|
||||
if not (track := MusicDatabase.search_song_mbid(track_mbid)) and scrobble.duration_ms:
|
||||
song_id: int = MusicDatabase.get_last_song_id() + 1
|
||||
MusicDatabase.insert_song(song_id, scrobble.track_name, scrobble.duration_ms, album.id, artist.id, track_mbid)
|
||||
|
||||
|
||||
|
||||
# See https://listenbrainz.readthedocs.io/en/latest/users/json.html#json-doc
|
||||
@app.route('/1/submit-listens', methods=["POST"])
|
||||
def submit_listens():
|
||||
|
||||
Reference in new issue
Block a user