From 4d10d400c8e00cf5ccb2f551df45936c5ce1cff5 Mon Sep 17 00:00:00 2001 From: derwentx Date: Sun, 19 Apr 2020 12:29:12 +1000 Subject: [PATCH 1/2] =?UTF-8?q?[#1]=20=F0=9F=90=9B=20Fix=20Shazam=20databa?= =?UTF-8?q?se=20has=20moved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- shazam-tags.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57d66bc..50825bc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # Shazam tags This Python script lists your saved tags from the Shazam macOS app. -Shazam for macOS doesn't have an option to save your tags, but stores its data in a SQLite database located in: +Shazam for macOS doesn't have an option to save your tags, but stores its data in a SQLite database +located in one of these places: ``` ~/Library/Containers/com.shazam.mac.Shazam/Data/Documents/ShazamDataModel.sqlite +~/Library/Group Containers/*.group.com.shazam/com.shazam.mac.Shazam/ShazamDataModel.sqlite ``` ### Usage diff --git a/shazam-tags.py b/shazam-tags.py index 52afd92..49f6b67 100644 --- a/shazam-tags.py +++ b/shazam-tags.py @@ -3,7 +3,22 @@ import os import sqlite3 -db_path = os.path.expanduser('~/Library/Containers/com.shazam.mac.Shazam/Data/Documents/ShazamDataModel.sqlite') + +db_path = os.path.expanduser( + '~/Library/Containers/com.shazam.mac.Shazam/Data/Documents/ShazamDataModel.sqlite' +) +if not os.path.exists(db_path): + db_prefix = os.path.expanduser('~/Library/Group Containers/') + for child in os.listdir((db_prefix)): + if not child.endswith('.group.com.shazam'): + continue + db_path_ = os.path.join(db_prefix, child, 'com.shazam.mac.Shazam/ShazamDataModel.sqlite') + if os.path.exists(db_path_): + db_path = db_path_ + break + +if not db_path: + raise UserWarning("Could not find Shazam Database") connection = sqlite3.connect(db_path) cursor = connection.cursor() From 6a1bcb75a00212cf5ba43a4c401948ff699cea44 Mon Sep 17 00:00:00 2001 From: derwentx Date: Sun, 19 Apr 2020 13:30:29 +1000 Subject: [PATCH 2/2] =?UTF-8?q?[sn3p#2]=20=F0=9F=90=9B=20don't=20decode=20?= =?UTF-8?q?results,=20just=20print=20bytes=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shazam-tags.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shazam-tags.py b/shazam-tags.py index 49f6b67..40e1394 100644 --- a/shazam-tags.py +++ b/shazam-tags.py @@ -21,6 +21,7 @@ raise UserWarning("Could not find Shazam Database") connection = sqlite3.connect(db_path) +connection.text_factory = lambda x: x cursor = connection.cursor() results = cursor.execute( ''' @@ -32,6 +33,6 @@ ) for result in results: - print '{0} - {1}'.format(result[0], result[1]) + print b'{0} - {1}'.format(result[0], result[1]) connection.close()