[SCM] morituri/master: * morituri/common/common.py: Create some common functions to parse MSF and back. * morituri/image/toc.py: Use it here.

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


The following commit has been merged in the master branch:
commit d76e0a3495790b34567cf372fc907a3e633347e0
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Fri May 1 18:29:39 2009 +0000

    	* morituri/common/common.py:
    	  Create some common functions to parse MSF and back.
    	* morituri/image/toc.py:
    	  Use it here.

diff --git a/ChangeLog b/ChangeLog
index d75f957..4ff0dec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-05-01  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/common/common.py:
+	  Create some common functions to parse MSF and back.
+	* morituri/image/toc.py:
+	  Use it here.
+
+2009-05-01  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* examples/trm.py:
 	  Allow loading and saving fingerprints from a pickle.
 
diff --git a/morituri/common/common.py b/morituri/common/common.py
new file mode 100644
index 0000000..6c6cdcb
--- /dev/null
+++ b/morituri/common/common.py
@@ -0,0 +1,59 @@
+# -*- Mode: Python; test-case-name: morituri.test.test_common_common -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+# Morituri - for those about to RIP
+
+# Copyright (C) 2009 Thomas Vander Stichele
+
+# This file is part of morituri.
+# 
+# morituri is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# morituri is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with morituri.  If not, see <http://www.gnu.org/licenses/>.
+
+def msfToFrames(msf):
+    """
+    Converts a string value in MM:SS:FF to frames
+
+    @param msf:
+    @type  msf: str
+
+    @rtype int
+    @returns number of frames
+    """
+    if not ':' in msf:
+        return int(msf)
+
+    m, s, f = msf.split(':')
+
+    return 60 * 75 * int(m) + 75 * int(s) + int(f)
+
+def framesToMSF(frames):
+    f = frames % 75
+    frames -= f
+    s = (frames / 75) % 60
+    frames -= s * 60
+    m = frames / 75 / 60
+
+    return "%02d:%02d:%02d" % (m, s, f)
+
+def framesToHMSF(frames):
+    # cdparanoia style
+    f = frames % 75
+    frames -= f
+    s = (frames / 75) % 60
+    frames -= s * 75
+    m = (frames / 75 / 60) % 60
+    frames -= m * 75 * 60
+    h = frames / 75 / 60 / 60
+
+    return "%02d:%02d:%02d.%02d" % (h, m, s, f)
diff --git a/morituri/image/toc.py b/morituri/image/toc.py
index 0d68f43..a2aa701 100644
--- a/morituri/image/toc.py
+++ b/morituri/image/toc.py
@@ -27,6 +27,8 @@ Reading .toc files
 import os
 import re
 
+from morituri.common import common
+
 # header
 _CATALOG_RE = re.compile(r'^CATALOG "(?P<catalog>\d+)"$')
 
@@ -115,7 +117,7 @@ class TOC:
             m = _SILENCE_RE.search(line)
             if m:
                 length = m.group('length')
-                currentLength += self._parseMSF(length)
+                currentLength += common.msfToFrames(length)
 
             # look for FILE lines
             m = _FILE_RE.search(line)
@@ -124,8 +126,8 @@ class TOC:
                 start = m.group('start')
                 length = m.group('length')
                 currentFile = File(filePath, start, length)
-                #currentOffset += self._parseMSF(start)
-                currentLength += self._parseMSF(length)
+                #currentOffset += common.msfToFrames(start)
+                currentLength += common.msfToFrames(length)
 
             # look for START lines
             m = _START_RE.search(line)
@@ -135,7 +137,7 @@ class TOC:
                     print 'ouch'
                     continue
 
-                length = self._parseMSF(m.group('length'))
+                length = common.msfToFrames(m.group('length'))
                 currentTrack.index(0, currentOffset, currentFile)
                 currentLength += length
                 pregapLength = length
@@ -146,7 +148,7 @@ class TOC:
                 if not currentTrack:
                     self.message(number, 'INDEX without preceding TRACK')
                     indexNumber += 1
-                    offset = self._parseMSF(m.group('offset'))
+                    offset = common.msfToFrames(m.group('offset'))
                     currentTrack.index(indexNumber, offset, currentFile)
 
         # handle index 1 of final track, if any
@@ -210,13 +212,6 @@ class TOC:
 
         raise KeyError, "Cannot find file for %s" % path
 
-    def _parseMSF(self, msf):
-        # parse str value in MM:SS:FF to frames
-        if not ':' in msf:
-            return int(msf)
-        m, s, f = msf.split(':')
-        return 60 * 75 * int(m) + 75 * int(s) + int(f)
-
 class File:
     """
     I represent a FILE line in a .toc file.

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list