Skip to content

Instantly share code, notes, and snippets.

@jasonbot
Last active June 13, 2023 23:38
Show Gist options
  • Save jasonbot/5b64692f45cadc9c9d83821cbf69988a to your computer and use it in GitHub Desktop.
Save jasonbot/5b64692f45cadc9c9d83821cbf69988a to your computer and use it in GitHub Desktop.
Change the "date added" column in Rhythmbox's DB to the creation time of the music file
import pathlib
import xml.dom.minidom
path = pathlib.Path("~/.local/share/rhythmbox/rhythmdb.xml").expanduser()
out_path = path.parent / "new_rhythmdb.xml"
print("Updating date addeds in", path, "and outputting to", out_path)
d = xml.dom.minidom.parse(str(path))
for e in d.getElementsByTagName("entry"):
if e.getAttribute("type") == "song":
artist = e.getElementsByTagName("artist")[0].firstChild.nodeValue
title = e.getElementsByTagName("title")[0].firstChild.nodeValue
mtime = e.getElementsByTagName("mtime")[0].firstChild.nodeValue
firstseen = e.getElementsByTagName("first-seen")[0].firstChild.nodeValue
if int(mtime) < int(firstseen):
newFirstSeen = d.createTextNode(mtime)
firstSeenNode = e.getElementsByTagName("first-seen")[0]
for c in firstSeenNode.childNodes:
firstSeenNode.removeChild(c)
firstSeenNode.appendChild(newFirstSeen)
print(artist, "*", title, mtime)
with open(out_path, "w") as out_handle:
d.writexml(out_handle)
print("Copy", out_path, "to", path, "if you're satified with the results")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment