Brian Wolff has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/108203


Change subject: Output ogg metadata on image description page.
......................................................................

Output ogg metadata on image description page.

As an aside, this was one of the primary goals of my 2010
gsoc project. I'm only 4 years late.

This just does basic support (throws all the metadata of each
type together), nothing fancy like separating out metadata by
different streams is attempted.

Change-Id: I2adacf4199a4da559f8225fd9f37cbcc3eac21ce
---
M handlers/OggHandler/OggHandler.php
1 file changed, 87 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/03/108203/1

diff --git a/handlers/OggHandler/OggHandler.php 
b/handlers/OggHandler/OggHandler.php
index a225483..c90e8c2 100644
--- a/handlers/OggHandler/OggHandler.php
+++ b/handlers/OggHandler/OggHandler.php
@@ -49,6 +49,93 @@
        }
 
        /**
+        * Display metadata box on file description page.
+        *
+        * This is pretty basic, it puts data from all the streams together,
+        * and only outputs a couple of the most commonly used ogg "comments",
+        * with comments from all the streams combined
+        *
+        * @param File $file
+        * @return array|bool
+        */
+       public function formatMetadata( $file ) {
+               $meta = $this->getCommonMetaArray( $file );
+               if ( count( $meta ) === 0 ) {
+                       return false;
+               }
+               return $this->formatMetadataHelper( $meta );
+       }
+
+       /**
+        * Get some basic metadata properties that are common across file types.
+        *
+        * @param File $file
+        * @return array Array of metadata. See MW's FormatMetadata class for 
format.
+        */
+       public function getCommonMetaArray( $file ) {
+               $metadata = $this->unpackMetadata( $file->getMetadata() );
+               if ( !$metadata || isset( $metadata['error'] ) || !isset( 
$metadata['streams'] ) ) {
+                       return false;
+               }
+               wfProfileIn( __METHOD__ );
+
+               // See http://www.xiph.org/vorbis/doc/v-comment.html
+               // http://age.hobba.nl/audio/mirroredpages/ogg-tagging.html
+               $metadataMap = array(
+                       'title' => 'ObjectName',
+                       'artist' => 'Artist',
+                       'performer' => 'Artist',
+                       'description' => 'ImageDescription',
+                       'license' => 'UsageTerms',
+                       'copyright' => 'Copyright',
+                       'organization' => 'dc-publisher',
+                       'date' => 'DateTimeDigitized',
+                       'location' => 'LocationDest',
+                       'contact' => 'Contact',
+                       'encoded_using' => 'Software',
+                       'encoder' => 'Software',
+                       // OpenSubtitles.org hash. Identifies source video.
+                       'source_ohash' => 'OriginalDocumentID',
+                       'comment' => 'UserComment',
+                       'language' => 'LanguageCode',
+               );
+
+               $props = array();
+
+               foreach( $metadata['streams'] as $stream ) {
+                       if ( isset( $stream['vendor'] ) ) {
+                               if ( !isset( $props['Software'] ) ) {
+                                       $props['Software'] = array();
+                               }
+                               $props['Software'][] = trim( $stream['vendor'] 
);
+                       }
+                       if ( !isset( $stream['comments'] ) ) {
+                               continue;
+                       }
+                       foreach( $stream['comments'] as $name => $value ) {
+                               if ( trim( $value ) === '' ) {
+                                       continue;
+                               }
+                               if ( isset( $metadataMap[strtolower( $name )] ) 
) {
+                                       $convertedName = 
$metadataMap[strtolower( $name )];
+                                       if ( !isset( $props[$convertedName] ) ) 
{
+                                               $props[$convertedName] = 
array();
+                                       }
+                                       $props[$convertedName][] = trim( $value 
);
+                               }
+                       }
+
+               }
+               // properties might be duplicated across streams
+               foreach( $props as &$type ) {
+                       $type = array_unique( $type );
+                       $type = array_values( $type );
+               }
+               wfProfileOut( __METHOD__ );
+               return $props;
+       }
+
+       /**
         * Get the "media size"
         *
         * @param $file File

-- 
To view, visit https://gerrit.wikimedia.org/r/108203
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2adacf4199a4da559f8225fd9f37cbcc3eac21ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <bawolff...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to