[SCM] morituri/master: * morituri/common/program.py: * morituri/rip/image.py: feature: add %r/%R for release type to track/disc template.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:50 UTC 2014


The following commit has been merged in the master branch:
commit f987210f6c84ccc2c3c749c5fb1b8bb7ba26892b
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sat Dec 22 22:52:48 2012 +0000

    	* morituri/common/program.py:
    	* morituri/rip/image.py:
    	  feature: add %r/%R for release type to track/disc template.

diff --git a/ChangeLog b/ChangeLog
index 5445830..2a868f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2012-12-22  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/common/program.py:
+	* morituri/rip/image.py:
+	  feature: add %r/%R for release type to track/disc template.
+
+2012-12-22  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* morituri/common/musicbrainzngs.py:
 	* morituri/rip/debug.py:
 	  Also store releaseType for disc metadata.
diff --git a/morituri/common/program.py b/morituri/common/program.py
index 3befd2d..a9c0b8f 100644
--- a/morituri/common/program.py
+++ b/morituri/common/program.py
@@ -154,7 +154,7 @@ class Program(log.Loggable):
         assert type(outdir) is unicode, "%r is not unicode" % outdir
         assert type(template) is unicode, "%r is not unicode" % template
 
-        # the template is similar to grip, except for %s/%S
+        # the template is similar to grip, except for %s/%S/%r/%R
         # see #gripswitches
 
         # returns without extension
@@ -165,7 +165,9 @@ class Program(log.Loggable):
 
         # default values
         v['A'] = 'Unknown Artist'
-        v['d'] = mbdiscid
+        v['d'] = mbdiscid # fallback for title
+        v['r'] = 'unknown'
+        v['R'] = 'Unknown'
 
         v['a'] = v['A']
         if i == 0:
@@ -180,6 +182,8 @@ class Program(log.Loggable):
             v['A'] = filterForPath(self.metadata.artist)
             v['S'] = filterForPath(self.metadata.sortName)
             v['d'] = filterForPath(self.metadata.title)
+            v['R'] = self.metadata.releaseType
+            v['r'] = self.metadata.releaseType.lower()
             if i > 0:
                 try:
                     v['a'] = filterForPath(self.metadata.tracks[i - 1].artist)
diff --git a/morituri/rip/image.py b/morituri/rip/image.py
index ea526c1..a9afef8 100644
--- a/morituri/rip/image.py
+++ b/morituri/rip/image.py
@@ -22,7 +22,7 @@
 
 import os
 
-from morituri.common import logcommand, accurip, program, encode
+from morituri.common import logcommand, accurip, program, encode, renamer
 from morituri.image import image
 from morituri.result import result
 
@@ -147,6 +147,56 @@ class Retag(logcommand.LogCommand):
                     print '%s already tagged correctly' % path
             print
 
+class Rename(logcommand.LogCommand):
+
+    summary = "rename image and all files based on metadata"
+
+    def addOptions(self):
+        self.parser.add_option('-R', '--release-id',
+            action="store", dest="release_id",
+            help="MusicBrainz release id to match to (if there are multiple)")
+
+
+    def do(self, args):
+        prog = program.Program(stdout=self.stdout)
+        runner = task.SyncRunner()
+
+        for arg in args:
+            self.stdout.write('Renaming image %r\n' % arg)
+            arg = arg.decode('utf-8')
+            cueImage = image.Image(arg)
+            cueImage.setup(runner)
+
+            mbdiscid = cueImage.table.getMusicBrainzDiscId()
+
+            operator = renamer.Operator(statePath, mbdiscid)
+
+            self.stdout.write('MusicBrainz disc id is %s\n' % mbdiscid)
+            prog.metadata = prog.getMusicBrainz(cueImage.table, mbdiscid,
+                release=self.options.release_id)
+
+            if not prog.metadata:
+                print 'Not in MusicBrainz database, skipping'
+                continue
+
+            # FIXME: this feels like we're poking at internals.
+            prog.cuePath = arg
+            prog.result = result.RipResult()
+            for track in cueImage.table.tracks:
+                path = cueImage.getRealPath(track.indexes[1].path)
+
+                taglist = prog.getTagList(track.number)
+                self.debug(
+                    'possibly retagging %r from cue path %r with taglist %r',
+                    path, arg, taglist)
+                t = encode.SafeRetagTask(path, taglist)
+                runner.run(t)
+                path = os.path.basename(path)
+                if t.changed:
+                    print 'Retagged %s' % path
+                else:
+                    print '%s already tagged correctly' % path
+            print
 
 class Verify(logcommand.LogCommand):
 

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list