Created
December 29, 2018 04:36
-
-
Save JohnBrodie/7602bfa0c4d4312820d4c64c4057e4db to your computer and use it in GitHub Desktop.
Delete low rated songs from Kodi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Probably not useful to most people, but an easy way to get rid of 1-star rated songs from Kodi and disk. | |
# This works on my setup, where both Kodi and the computer the script is running on have the same share mounted. | |
# Use line 24 to correct the paths relative to the two boxes. | |
import os | |
import sqlite3 | |
import sys | |
# Get database via SCP: | |
# scp "<user>@<kodi-host>:/path/to/.kodi/userdata/Database/MyMusic60.db" . | |
conn = sqlite3.connect('MyMusic60.db') | |
c = conn.cursor() | |
# userrating == 2 * stars, so a "1 star" song has a userrating = 2 | |
c.execute( | |
'SELECT p.strPath || s.strFileName AS f FROM song s, path p' | |
' WHERE s.userrating = 2 AND s.idPath = p.idPath;' | |
) | |
# Compute final song file paths | |
songs = set() | |
skipped = 0 | |
for row in c: | |
song_path = row[0].replace('smb://some-path', '/other-path') | |
# Keep track of count of files that don't exist | |
if not os.path.exists(song_path): | |
skipped += 1 | |
continue | |
songs.append(song_path) | |
print('Skipping {} songs that do not exist.'.format(skipped)) | |
print('Deleting {} 1-star songs...'.format(len(songs))) | |
# Delete songs and write deleted path to file | |
with open('deleted_songs.txt', 'a') as f: | |
for song in songs: | |
f.write('{}\n'.format(song)) | |
os.remove(song) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment