Last active
June 13, 2023 23:38
-
-
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
This file contains 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
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