Skip to content

Commit

Permalink
Merge pull request #3 from derwentx/master
Browse files Browse the repository at this point in the history
Fixes #1 and #2
  • Loading branch information
sn3p authored Dec 23, 2020
2 parents 4a767a0 + 6a1bcb7 commit b7d9758
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 18 additions & 2 deletions shazam-tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'''
Expand All @@ -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()

0 comments on commit b7d9758

Please sign in to comment.