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..40e1394 100644 --- a/shazam-tags.py +++ b/shazam-tags.py @@ -3,9 +3,25 @@ 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) +connection.text_factory = lambda x: x cursor = connection.cursor() results = cursor.execute( ''' @@ -17,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()