Skip to content

Instantly share code, notes, and snippets.

@da2x
Created April 8, 2022 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save da2x/7c843cd254529ca7d369d6af14ded345 to your computer and use it in GitHub Desktop.
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
#!/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.')
@da2x
Copy link
Author

da2x commented Apr 8, 2022

Some usage instructions: Taiko2k/TauonMusicBox#725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment