Skip to content

Instantly share code, notes, and snippets.

@fotile96
Created June 21, 2016 09:31
Show Gist options
  • Save fotile96/a2fced3d6bd7ac5d11fc37527df03ee7 to your computer and use it in GitHub Desktop.
Save fotile96/a2fced3d6bd7ac5d11fc37527df03ee7 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import sqlite3
import taglib
import sys
pathroot = {
'b:': '/Volumes/Transcend/Music Library'
}
conn = sqlite3.connect('usrlocal_media.db')
c = conn.cursor()
albums = list(map(lambda x:x[0], c.execute('select distinct album from media_table where has_child_file=0').fetchall()))
cnt = 0
for album in albums:
tracks = c.execute('select * from media_table where album=?', (album,)).fetchall()
# print(tracks)
res = []
for row in tracks:
# print(row)
filename = row[1].replace('\\', '/')
if filename[:2] not in pathroot:
tags = {}
else:
filename = pathroot[filename[:2]] + filename[2:]
# print(filename)
tags = taglib.File(filename).tags
# print(tags)
id = row[0]
title = tags['TITLE'][0] if 'TITLE' in tags else row[2]
trackno = int(tags['TRACKNUMBER'][0].split('/')[0]) if 'TRACKNUMBER' in tags else row[7]
cdno = int(tags['DISCNUMBER'][0].split('/')[0]) if 'DISCNUMBER' in tags else 1
res.append((cdno, trackno, title, id))
res.sort()
id = 0
for track in res:
print(track)
id += 1
c.execute('update media_table set name=?, ck_id=? where id=?', (track[2], id, track[3]))
# print(c.execute('select * from media_table where id=?', (track[3], )).fetchone())
cnt += 1
print('%d/%d albums have been processed.' % (cnt, len(albums)))
conn.commit()
conn.close()
@Harcyah
Copy link

Harcyah commented Feb 22, 2017

Hey, i'm interested in the Fiio firmware/database stuff. Do you have an example of this usrlocal_media.db file to share please ?

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