in the shape of an L on her forehead
This commit is contained in:
parent
14014e2e93
commit
dbed8bb926
2 changed files with 33 additions and 37 deletions
28
mutaext.py
28
mutaext.py
|
@ -1,8 +1,6 @@
|
||||||
import mutagen
|
import mutagen
|
||||||
import mutagen.id3
|
import mutagen.id3
|
||||||
import mutagen.easyid3
|
from mutagen.easyid3 import EasyID3
|
||||||
|
|
||||||
# TODO: custom interface to tracknumber/tracktotal/disc...
|
|
||||||
|
|
||||||
def popms(id3):
|
def popms(id3):
|
||||||
for k, v in id3.iteritems():
|
for k, v in id3.iteritems():
|
||||||
|
@ -34,7 +32,7 @@ def rating_get(id3, key):
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
return [byte2rating(popm.rating)]
|
return [unicode(byte2rating(popm.rating))]
|
||||||
else:
|
else:
|
||||||
return list(rating.text)
|
return list(rating.text)
|
||||||
|
|
||||||
|
@ -65,20 +63,14 @@ def rating_delete(id3, key):
|
||||||
if 'TXXX:RATING' in id3:
|
if 'TXXX:RATING' in id3:
|
||||||
del(id3['TXXX:RATING'])
|
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_tags = ('replaygain_album_gain', 'replaygain_album_peak', \
|
||||||
'replaygain_track_gain', 'replaygain_track_peak')
|
'replaygain_track_gain', 'replaygain_track_peak')
|
||||||
|
|
||||||
for tag in replaygain_tags:
|
for tag in replaygain_tags:
|
||||||
mutagen.easyid3.EasyID3.RegisterTXXXKey(tag, tag)
|
EasyID3.RegisterTXXXKey(tag, tag)
|
||||||
mutagen.easyid3.EasyID3.RegisterTXXXKey('sync', 'SYNC')
|
|
||||||
mutagen.easyid3.EasyID3.RegisterKey('rating', rating_get, rating_set, rating_delete)
|
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)
|
||||||
|
|
42
unsync.py
42
unsync.py
|
@ -9,6 +9,14 @@ import sys
|
||||||
import mutagen
|
import mutagen
|
||||||
import mutaext
|
import mutaext
|
||||||
|
|
||||||
|
updatabletags = [\
|
||||||
|
'albumartist', 'composer', 'comment' \
|
||||||
|
'tracknumber', 'discnumber', \
|
||||||
|
'genre', 'date', \
|
||||||
|
]
|
||||||
|
updatabletags.extend(mutaext.replaygain_tags)
|
||||||
|
updatabletags.extend(mutaext.extra_tags)
|
||||||
|
|
||||||
def G(d, k):
|
def G(d, k):
|
||||||
try:
|
try:
|
||||||
return d[k]
|
return d[k]
|
||||||
|
@ -29,8 +37,10 @@ def filterext(paths, exts):
|
||||||
def shouldsync(md):
|
def shouldsync(md):
|
||||||
rating = G(md, 'rating')
|
rating = G(md, 'rating')
|
||||||
sync = G(md, 'sync')
|
sync = G(md, 'sync')
|
||||||
if rating:
|
try:
|
||||||
rating = rating[0]
|
rating = int(rating[0])
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
pass
|
||||||
if sync:
|
if sync:
|
||||||
sync = sync[0].lower()
|
sync = sync[0].lower()
|
||||||
else:
|
else:
|
||||||
|
@ -40,7 +50,7 @@ def shouldsync(md):
|
||||||
return False
|
return False
|
||||||
if sync == u'yes' or sync == u'share':
|
if sync == u'yes' or sync == u'share':
|
||||||
return True
|
return True
|
||||||
if rating != None and rating >= 3:
|
if type(rating) == int and rating >= 3:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -77,19 +87,14 @@ def findmatching(haystack, needle):
|
||||||
|
|
||||||
def updatemetadata(mdold, mdnew):
|
def updatemetadata(mdold, mdnew):
|
||||||
modified = False
|
modified = False
|
||||||
updatabletags = ('rating', 'sync', 'comment')
|
# TODO: ensure genre and date work properly (special cases in EasyID3)
|
||||||
# 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
|
|
||||||
for tag in updatabletags:
|
for tag in updatabletags:
|
||||||
if tag in mdnew:
|
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]
|
mdold[tag] = mdnew[tag]
|
||||||
modified = True
|
modified = True
|
||||||
elif tag in mdold:
|
elif tag in mdold:
|
||||||
|
@ -134,15 +139,14 @@ def run(args):
|
||||||
if match:
|
if match:
|
||||||
if updatemetadata(md, match):
|
if updatemetadata(md, match):
|
||||||
print("UPD", p)
|
print("UPD", p)
|
||||||
# save here
|
md.save()
|
||||||
else:
|
else:
|
||||||
print("DEL", p)
|
pass #print("DEL", p)
|
||||||
# delete files here
|
# delete files here
|
||||||
|
|
||||||
for md in tosync:
|
for md in tosync:
|
||||||
if md.seen:
|
if md.seen == False:
|
||||||
continue
|
print("ADD", md.path)
|
||||||
print("ADD", md.path)
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue