Skip to content
Browse files

TSO2 for album artist sort in iTunes

  • Loading branch information...
1 parent 9d5ed55 commit 36edbbccb38a4a625daa27fe00f2e85295a390a5 @rodbegbie committed Nov 26, 2011
Showing with 81 additions and 6 deletions.
  1. +2 −1 Util/Convert-010.py
  2. +74 −0 Util/UpdateSort.py
  3. +2 −2 data/AudioScrobbler.py
  4. +3 −3 data/MusicBrainz.py
View
3 Util/Convert-010.py
@@ -3,6 +3,7 @@
import gst
import os,sys
from eyeD3 import Tag, FrameHeader, TextFrame, UTF_8_ENCODING
+
from data.MusicBrainz import *
from Util import walk
from time import sleep
@@ -25,7 +26,7 @@ def convert(flacfile, mp3file):
#mp3.set_property("vbr", 4)
#mp3.set_property("vbr-quality", 2)
- id3 = gst.element_factory_make("id3mux", "tagger")
+ id3 = gst.element_factory_make("id3v2mux", "tagger")
#xing = gst.element_factory_make("xingmux", "vbrfixer")
View
74 Util/UpdateSort.py
@@ -0,0 +1,74 @@
+import os,sys
+from eyeD3 import Tag, FrameHeader, TextFrame, UTF_8_ENCODING
+
+from Util import walk
+from time import sleep
+
+if __name__ == "__main__":
+ import gnosis.xml.pickle
+ tag = Tag()
+ root = "/mnt/tera/flac/"
+ if sys.argv:
+ root = sys.argv[1]
+ for root, dirs, files in walk(root, followlinks=True):
+ mp3dir = root.replace("/flac/", "/mp3/")
+ if not os.path.exists(mp3dir):
+ os.makedirs(mp3dir)
+
+ discmetafile = os.path.join(root, "discmetadata.xml")
+
+ if not os.path.exists(discmetafile):
+ continue
+ else:
+ f = open(discmetafile, "r")
+ xml = f.read()
+ discMeta = gnosis.xml.pickle.loads(xml)
+ f.close()
+
+ print "\n---------------------"
+ print ("%s - %s" % (discMeta.artist, discMeta.title)).encode("ascii", "ignore")
+
+ for file in files:
+ if file.endswith(".flac"):
+ import glob
+ flacfile = os.path.join(root,file)
+ mp3glob = glob.glob(os.path.join(root.replace("/flac/", "/mp3/"), file[:3] + "*.mp3"))
+ try:
+ mp3file = mp3glob[0]
+ except IndexError:
+ print "%s - mp3 not there :(" % flacfile
+ continue
+ print mp3file
+
+ tag.link(mp3file)
+
+ gotTSO2 = False
+ needsUpdate = False
+
+ for frame in tag.frames:
+ if frame.header.id == 'TSO2':
+ gotTSO2 = True
+
+ if not gotTSO2:
+ try:
+ print "Updating TSO2 fields"
+ tpe2Header = FrameHeader(tag.header)
+ tpe2Header.id = "TSO2"
+ tpe2 = TextFrame(tpe2Header)
+ tpe2.text = discMeta.artistSort if 'artistSort' in dir(discMeta) else discMeta.artist
+ tag.frames.append(tpe2)
+ needsUpdate = True
+ except:
+ print "SOMETHING WENT BAD :("
+
+ if needsUpdate:
+ try:
+ tag.setTextEncoding(UTF_8_ENCODING)
+ tag.update()
+ except:
+ print "FAILED first time -- trying again"
+ try:
+ sleep(1.0)
+ tag.update()
+ except:
+ print "MEGA FAIL!"
View
4 data/AudioScrobbler.py
@@ -1,10 +1,10 @@
import xml.etree.cElementTree as ET
import urllib
from time import sleep
-from musicbrainz import MBI_VARIOUS_ARTIST_ID
+#from musicbrainz import MBI_VARIOUS_ARTIST_ID
def getArtistTopTag(artistName, mbArtistId):
- if mbArtistId == MBI_VARIOUS_ARTIST_ID:
+ if mbArtistId == "89ad4ac3-39f7-470e-963a-56509c546377": #MBI_VARIOUS_ARTIST_ID:
return None
artistName = artistName.replace("&","and")
View
6 data/MusicBrainz.py
@@ -252,10 +252,10 @@ def writeTags(filename, discMeta, trackNum):
from time import sleep
i = 0
while noti[1] <> 3:
+ print noti
i = i + 1
- if i == 200:
- raise "Taking too long to save"
- if noti[0] <> 0:
+ if i == 1000:
+ raise Exception("Taking too long to save")
sleep(0.1)
noti = tp.getNotification()

0 comments on commit 36edbbc

Please sign in to comment.
Something went wrong with that request. Please try again.