Created
April 8, 2022 02:45
-
-
Save da2x/7c843cd254529ca7d369d6af14ded345 to your computer and use it in GitHub Desktop.
Migrate your music play counts from Rythmbox 3.4.4. to Tauon 7.1.3
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
#!/usr/bin/python3 | |
# SPDX-License-Identifier: CC0-1.0 | |
# | |
# One-time Rhythmbox to Tauon playcount migration tool | |
import os | |
import pickle | |
import shutil | |
import urllib.parse as urlparser | |
import xml.etree.ElementTree as ET | |
# Customize these two paths | |
tauon_star_path = '/home/username/.var/app/com.github.taiko2k.tauonmb/data/TauonMusicBox/star.p' | |
rhythmboxdb_path = '/home/username/.var/app/org.gnome.Rhythmbox3/data/rhythmbox/rhythmdb.xml' | |
tauon_db = pickle.load(open(tauon_star_path, 'rb')) | |
rhythmbox_db = ET.parse(rhythmboxdb_path) | |
changes = False | |
for entry in rhythmbox_db.getroot().findall('./entry[@type="song"]'): | |
play_count = entry.find('./play-count') | |
if play_count is None: | |
continue | |
play_count = play_count.text | |
title = entry.find('./title').text | |
artist = entry.find('./artist').text | |
duration = entry.find('./duration').text | |
location = entry.find('./location').text | |
if title is None or artist is None or duration is None or location is None: | |
continue | |
changes = True | |
location = urlparser.unquote(location) | |
path = location.split(os.sep)[-1] | |
try: | |
song = tauon_db[(artist, title, path)] | |
except KeyError: | |
tauon_db[(artist, title, path)]= [0.0, '', 0] | |
playtime = float(int(duration) * int(play_count)) | |
song[0] += playtime | |
if changes: | |
shutil.copyfile(tauon_star_path, tauon_star_path + '.pre-rhythmbox-backup') | |
print('Warning: Only run this script once! Every time it runs it adds plays to Tauon.') | |
with open(tauon_star_path, 'wb') as f: | |
pickle.dump(tauon_db, f) | |
else: | |
print('Didn’t find any play counts to migrate, sorry.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some usage instructions: Taiko2k/Tauon#725