[mnet-devel] nej's ogg patch

Zooko zooko at zooko.com
Sun Feb 2 04:04:14 GMT 2003


Nurse Donna:	Oh, Groucho, I'm afraid I'm gonna wind up an old maid.
Groucho:	Well, bring her in and we'll wind her up together.
Nurse Donna:	Do you believe in computer dating?
Groucho:	Only if the computers really love each other.




- ------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <16732.1044155141.2 at noether.shacknet.nu>

? .cvsup.log
? .cvsup.patched
? .cvsup.unknown
? .swp
? Mnet.sh
? ogg-vorbis-describe.patch
? artwork/.cvsup.unknown
? artwork/.cvsup.updated
? client/blockshare/Python/.cvsup.unknown
? client/blockshare/Python/builtforpython2.2
? client/localhost/.cvsup.modified
? client/localhost/.cvsup.patched
? client/localhost/.cvsup.unknown
? client/localhost/.cvsup.updated
? common/.cvsup.patched
? common/.cvsup.unknown
? common/.cvsup.updated
? common/c_mencode/.cvsup.unknown
? common/c_mencode/builtforpython2.2
? common/crypto/Python/.cvsup.patched
? common/crypto/Python/.cvsup.unknown
? common/crypto/Python/builtforpython2.2-debug
? hackerdocs/.cvsup.patched
? hackerdocs/.cvsup.unknown
? hackerdocs/.cvsup.updated
? localweb/templates/.cvsup.patched
? localweb/templates/.cvsup.unknown
? utilscripts/.cvsup.modified
? utilscripts/.cvsup.unknown
? utilscripts/.cvsup.updated
? wxBroker/.cvsup.patched
? wxBroker/.cvsup.unknown
Index: client/localhost/Describe.py
===================================================================
RCS file: /cvsroot/mnet/mnet/client/localhost/Describe.py,v
retrieving revision 1.3
diff -u -r1.3 Describe.py
- --- client/localhost/Describe.py	12 Jan 2003 16:24:38 -0000	1.3
+++ client/localhost/Describe.py	2 Feb 2003 03:04:03 -0000
@@ -14,6 +14,13 @@
 import debug
 import traceback
 
+# Non-standard, non-mnet modules:
+try:
+    import ogg.vorbis
+except ImportError, e:
+    ogg = None # Signifies the import didn't happen.
+    oggerrorinfo = `e`
+
 # Mnet Modules:
 from human_readable import hr
 import mp3
@@ -79,6 +86,8 @@
         # A mime type could not be determined.
         if string.lower(os.path.splitext(path)[1]) == '.mp3':
             return 'Audio'
+        elif string.lower(os.path.splitext(path)[1]) == '.ogg':
+            return 'Audio'
         return "Generic Description"
         
     # Now check in out MimeToCType dict to guess the content type.
@@ -177,12 +186,46 @@
         mp3v = mp3v + ", layer " + `od.get('LAYER')`
     metainfodict['Encoding'] = mp3v
 
- -    sizeinbytes = os.path.getsize(f)
- -    sizeinkb = sizeinbytes / (2 ** 10)
- -    metainfodict['Size in KB'] = sizeinkb
+    metainfodict['Size in KB'] = get_size_in_kb(path)
 
     return metainfodict
     
+def describe_ogg(path):
+    if ogg is None:
+        return {'Encoding': 'ogg/vorbis',
+                'Description': '[The metadate for this file could not be automatically processed because the ogg/vorbis module is misconfigured or not installed: %s]' % e
+               }
+    else:
+        vfile = ogg.vorbis.VorbisFile(path)
+
+        desc = {}
+        for oggkey, value in vfile.comment().items():
+            oggkey = oggkey.capitalize()
+            mnetkey = OggToMnetFieldNames.get(oggkey, 'Description')
+
+            if oggkey == mnetkey:
+                desc.setdefault(oggkey, ([], []))[0].append(value)
+            else:
+                desc.setdefault(mnetkey, ([], []))[1].append('%s=%s' % (oggkey, value))
+
+        # Reformat desc into flat string values:
+        for key, (primaries, secondaries) in desc.items():
+            value = string.join(primaries, ', ')
+            if len(secondaries) > 0:
+                secstr = string.join(secondaries, '; ')
+                if len(value) > 0:
+                    value = '%s (%s)' % (value, secstr)
+                else:
+                    value = secstr
+            desc[key] = value
+
+        # Over-write these special fields:
+        desc['Encoding'] = 'ogg/vorbis'
+        # I think -1 parameter to bitrate means average of whole file: --Neju 2003-01-12
+        desc['Bitrate in kbit/sec'] = vfile.bitrate(-1) / (2**10)
+        desc['Size in KB'] = get_size_in_kb(path)
+        return desc
+
 def describe_audio(path):
     # XXX, content type wish list item:
     # It would be nice if the following fields were in the audio content type:
@@ -196,10 +239,12 @@
             'Title' : get_title_from_path(path),
             'Encoding' : info[0],
             'Bitrate in kbit/sec' : info[1],
- -            'Size in KB' : os.path.getsize(path) / (2 ** 10),
+            'Size in KB' : get_size_in_kb(path)
             }
     elif string.lower(os.path.splitext(path)[1]) == '.mp3':
         return describe_mp3(path)
+    elif string.lower(os.path.splitext(path)[1]) == '.ogg':
+        return describe_ogg(path)
     else:
         return {}
 
@@ -212,6 +257,9 @@
 def get_title_from_path(path):
     return os.path.splitext(os.path.basename(path))[0]
 
+def get_size_in_kb(path):
+    return os.path.getsize(path) / (2 ** 10)
+
 # This maps mime type strings to Mojo Nation content type strings.  The keys can either be the
 # full mimetype string or they can be just the major part.  Full mimetypes are checked before
 # the less specific major mimetypes.
@@ -235,6 +283,42 @@
         },
     }
 
+# Maps ogg suggested fields to Mnet audio fields:
+# Ref for ogg fields: http://xiph.org/ogg/vorbis/doc/v-comment.html
+#
+# Note, two keys mapping to the same field will both show up in the
+# description, with identical mappings appearing first, and non-identical
+# mappings explicitly labelled.  All unmapped names default to
+# 'Description'.  For example:
+#
+# Ogg description:
+# Title=My Song
+# Artist=Me
+# Version=6.52.3beta7
+# Performer=My Robot Violinist
+# Copyright=2042
+# Licence=End user to pay $2/ml of endorphin produced as result of hearing.
+# Organization=Precision Productions
+#
+# maps to the Mnet description dict:
+# {'Title': 'My Song (Version=6.52.3beta7)',
+#  'Performer': 'My Robot Violinist (Artist=Me; Copyright=2042; Organization=Precision Productions)',
+#  'Description': '(Licence=End user to pay $2/ml of endorphin produced as result of hearing.)',
+# }
+#
+# XXX todo, IMHO: Throwout silly content description categories and have
+# arbitrary number of arbitrary length key/value pairs, like Ogg/Vorbis. --Neju 2003-01-12
+
+OggToMnetFieldNames = {
+    # These are identical, and appear first in relevant fields:
+    'Title': 'Title', 'Performer': 'Performer', 'Genre': 'Genre',
+    'Description': 'Description',
+
+    # These are fields which are flattened into the available mnet fields:
+    'Artist': 'Performer', 'Version': 'Title', 'Tracknumber': 'Title',
+    'Copyright': 'Performer', 'Organization': 'Performer',
+    }
+
 def interactive_test_describe(path):
     """
     This function doesn't work with testem, because you need to point it to a directory full of
@@ -245,3 +329,4 @@
     pprint.pprint(results)
     return results
     
+ 

- ------- =_aaaaaaaaaa0--


------- End of Forwarded Message



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
mnet-devel mailing list
mnet-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mnet-devel




More information about the Mnet-devel mailing list