in the shape of an L on her forehead

This commit is contained in:
Connor Olding 2014-04-27 13:47:08 -07:00
parent 14014e2e93
commit dbed8bb926
2 changed files with 33 additions and 37 deletions

View File

@ -1,8 +1,6 @@
import mutagen
import mutagen.id3
import mutagen.easyid3
# TODO: custom interface to tracknumber/tracktotal/disc...
from mutagen.easyid3 import EasyID3
def popms(id3):
for k, v in id3.iteritems():
@ -34,7 +32,7 @@ def rating_get(id3, key):
except StopIteration:
return []
else:
return [byte2rating(popm.rating)]
return [unicode(byte2rating(popm.rating))]
else:
return list(rating.text)
@ -65,20 +63,14 @@ def rating_delete(id3, key):
if 'TXXX:RATING' in id3:
del(id3['TXXX:RATING'])
def tracknumber_get(id3, key):
# TODO: use for both track and disc
pass
def tracknumber_set(id3, key, val):
pass
def tracknumber_delete(id3, key):
pass
replaygain_tags = ('replaygain_album_gain', 'replaygain_album_peak', \
'replaygain_track_gain', 'replaygain_track_peak')
for tag in replaygain_tags:
mutagen.easyid3.EasyID3.RegisterTXXXKey(tag, tag)
mutagen.easyid3.EasyID3.RegisterTXXXKey('sync', 'SYNC')
mutagen.easyid3.EasyID3.RegisterKey('rating', rating_get, rating_set, rating_delete)
EasyID3.RegisterTXXXKey(tag, tag)
extra_tags = ('sync', 'totaltracks', 'totaldiscs')
for tag in extra_tags:
EasyID3.RegisterTXXXKey(tag, tag.upper())
EasyID3.RegisterTextKey('albumartist', 'TPE2')
EasyID3.RegisterKey('rating', rating_get, rating_set, rating_delete)

View File

@ -9,6 +9,14 @@ import sys
import mutagen
import mutaext
updatabletags = [\
'albumartist', 'composer', 'comment' \
'tracknumber', 'discnumber', \
'genre', 'date', \
]
updatabletags.extend(mutaext.replaygain_tags)
updatabletags.extend(mutaext.extra_tags)
def G(d, k):
try:
return d[k]
@ -29,8 +37,10 @@ def filterext(paths, exts):
def shouldsync(md):
rating = G(md, 'rating')
sync = G(md, 'sync')
if rating:
rating = rating[0]
try:
rating = int(rating[0])
except (IndexError, ValueError):
pass
if sync:
sync = sync[0].lower()
else:
@ -40,7 +50,7 @@ def shouldsync(md):
return False
if sync == u'yes' or sync == u'share':
return True
if rating != None and rating >= 3:
if type(rating) == int and rating >= 3:
return True
return False
@ -77,19 +87,14 @@ def findmatching(haystack, needle):
def updatemetadata(mdold, mdnew):
modified = False
updatabletags = ('rating', 'sync', 'comment')
# TODO:
# composer : probably safe
# genre : might need deep equal?
# trackNum : TRCK with optional /[total]
# discNum : TPOS " " "
# total tracks : ?
# total discs : ?
# [replaygain] : TXXX:* in id3
# albumArtist : TPE2 in id3
# TODO: ensure genre and date work properly (special cases in EasyID3)
for tag in updatabletags:
if tag in mdnew:
if not tag in mdold or mdnew[tag] != mdold[tag]:
if not tag in mdold:
#print("not in old:",tag)
mdold[tag] = mdnew[tag]
elif mdnew[tag][0] != mdold[tag][0]:
#print("in old:",tag)
mdold[tag] = mdnew[tag]
modified = True
elif tag in mdold:
@ -134,15 +139,14 @@ def run(args):
if match:
if updatemetadata(md, match):
print("UPD", p)
# save here
md.save()
else:
print("DEL", p)
pass #print("DEL", p)
# delete files here
for md in tosync:
if md.seen:
continue
print("ADD", md.path)
if md.seen == False:
print("ADD", md.path)
return 0