rass_meta_search.php

00001 <?php
00002 # Sample script for RAWS tutorial 11: see http://rambla.eu/ for more info.
00003 #
00004 # Copyright (C) 2010 rambla.be
00005 
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #      http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 require_once '../RawsClient/Raws/Rass.php';
00018 
00019 # Provide the path to a local testfile, that can be uploaded via RASS
00020 define('LOCAL_FILE', '/my/path/to/a/file.mp4');
00021 
00022 # Provide your own RASS credentials here
00023 define('USER', 'xxx'); # your user account name
00024 define('PWD', 'xxx'); # your user account pwd
00025 define('CDN', "cdn0x"); # your sub-cdn (e.g. "cdn01")
00026 
00027 define('BASE', 'http://rass.' . CDN . '.rambla.be/');
00028 
00029 # all RASS API methods (except HEAD) will raise an exception if they don't return an HTTP SUCCESS CODE (200,201,204)
00030 try {
00031   # Instantiate an object that manages the RASS connection, passing it your login credentials and the base service uri
00032   $rass = new Rass(USER, PWD, BASE);
00033   
00034   # Create a "tutorial11" directory under the root-directory
00035   $dir_entry = $rass->createDir("tutorial11", True);
00036 
00037   # Upload a file 'da_funk.mp4' to your dir and attach some metadata to it
00038   $item_entry = $rass->postItem($dir_entry->path, "da_funk.mp4", LOCAL_FILE);
00039   $meta_elems = array(new Rass_Extension_Meta("dc", "creator", "Rambla"), new Rass_Extension_Meta("dc", "description", "Behind the scenes at Ramblaworld"), new Rass_Extension_Meta("dc", "date", "2010-12-31"));
00040   $meta_entry = $rass->setMetadataFromPath($item_entry->path, array(), $meta_elems);
00041   
00042   # Upload a file 'stream.mp4' to your dir and attach some metadata to it
00043   $item_entry = $rass->postItem($dir_entry->path, "stream.mp4", LOCAL_FILE);
00044   $meta_elems = array(new Rass_Extension_Meta("dc", "creator", "Rambla"), new Rass_Extension_Meta("dc", "title", "Harder, Better, Faster, Stronger"), new Rass_Extension_Meta("dc", "description", "Guide to streaming with Wowza Media Server 02."), new Rass_Extension_Meta("dc", "date", "2009-07-09"));
00045   $meta_entry = $rass->setMetadataFromPath($item_entry->path, array(), $meta_elems);
00046   
00047   # Upload a file 'world.mp4' to your dir and attach some metadata to it
00048   $item_entry = $rass->postItem($dir_entry->path, "world.mp4", LOCAL_FILE);
00049   $meta_elems = array(new Rass_Extension_Meta("dc", "creator", "Verne Travels"), new Rass_Extension_Meta("dc", "title", "Around the World in Eighty Days"), new Rass_Extension_Meta("dc", "date", "2008-11-04") );
00050   $meta_entry = $rass->setMetadataFromPath($item_entry->path, array(), $meta_elems);
00051 
00052   # Upload a file 'clip.mp4' to your dir and attach some metadata to it
00053   $item_entry = $rass->postItem($dir_entry->path, "clip.mp4", LOCAL_FILE);
00054   $meta_elems = array(new Rass_Extension_Meta("dc", "creator", "Daft Punk"), new Rass_Extension_Meta("dc", "title", "Tron: Legacy"), new Rass_Extension_Meta("dc", "description", "Music video from the movie TRON legacy."), new Rass_Extension_Meta("dc", "date", "2010-12-06") );
00055   $meta_entry = $rass->setMetadataFromPath($item_entry->path, array(), $meta_elems);
00056   
00057   # Upload two test files, without any metadata
00058   $item_entry = $rass->postItem($dir_entry->path, "test1.mp4", LOCAL_FILE);
00059   $item_entry = $rass->postItem($dir_entry->path, "test2.mp4", LOCAL_FILE);
00060   
00061   
00062   # GET feed
00063   
00064   echo "Getting meta entries for files in directory: " . $dir_entry->path . "\n";
00065   $query = new Rass_ExtQuery("file");
00066   $feed = $rass->getExtFeed($dir_entry->path, $query);
00067   foreach ($feed as $entry) {
00068     echo "\n" . $entry->id->text;
00069   }
00070 
00071   # 'meta' searches
00072   
00073   echo "\n\nSearch for all files with a 'dc:title' element :";
00074   $query->setSearchArg("meta", array("dc:title"));
00075   $feed = $rass->getExtFeed($dir_entry->path, $query);
00076   foreach ($feed as $entry) {
00077     echo "\n found " . $entry->id->text;
00078   }
00079   
00080   echo "\n\nSearch for all files that have a 'dc:title' OR 'dc:description' element :";
00081   $query->setSearchArg("meta", array("dc:title", "dc:description"));
00082   $feed = $rass->getExtFeed($dir_entry->path, $query);
00083   foreach ($feed as $entry) {
00084     echo "\n found " . $entry->id->text;
00085   }
00086   
00087   echo "\n\nSearch for all files that have 'dc:creator' set to 'Daft Punk' :";
00088   $query->setSearchArg("meta", array("dc:creator:Daft Punk"));
00089   $feed = $rass->getExtFeed($dir_entry->path, $query);
00090   foreach ($feed as $entry) {
00091     echo "\n found " . $entry->id->text;
00092   }
00093   
00094   echo "\n\nSearch for all files that have 'dc:creator' set to 'Rambla' but don't have a title element :";
00095   $query->setSearchArg("meta", array("dc:creator:rambla"), array(), array("dc:title"));
00096   $feed = $rass->getExtFeed($dir_entry->path, $query);
00097   foreach ($feed as $entry) {
00098     echo "\n found " . $entry->id->text;
00099   }
00100   
00101   
00102   # 'qmeta' or 'iqmeta' searches on content
00103   
00104   # qmeta is case sensitive
00105   echo "\n\nCase-sensitive search for all files with meta elements that contain the string 'World' :";
00106   $query = new Rass_ExtQuery("file");
00107   $query->setSearchArg("qmeta", array("World"));
00108   $feed = $rass->getExtFeed($dir_entry->path, $query);
00109   foreach ($feed as $entry) {
00110     echo "\n found " . $entry->id->text;
00111   }
00112   
00113   # iqmeta is case insensitive
00114   echo "\n\nCase-insensitive search for all files with meta elements that contain the string 'world' :";
00115   $query = new Rass_ExtQuery("file");
00116   $query->setSearchArg("iqmeta", array("world"));
00117   $feed = $rass->getExtFeed($dir_entry->path, $query);
00118   foreach ($feed as $entry) {
00119     echo "\n found " . $entry->id->text;
00120   }
00121   
00122   # search operators can also be used with (i)qmeta
00123   echo "\n\nCase-insensitive search for all files with meta elements that contain the strings 'world' OR 'rambla' :";
00124   $query = new Rass_ExtQuery("file");
00125   $query->setSearchArg("iqmeta", array("world", "rambla"));
00126   $feed = $rass->getExtFeed($dir_entry->path, $query);
00127   foreach ($feed as $entry) {
00128     echo "\n found " . $entry->id->text;
00129   }
00130   
00131   # search operators can also be used with (i)qmeta
00132   echo "\n\nCase-insensitive search for all files with meta elements that contain the strings '2010' AND 'daft' :";
00133   $query = new Rass_ExtQuery("file");
00134   $query->setSearchArg("iqmeta", array(), array("2010", "Daft"), array());
00135   $feed = $rass->getExtFeed($dir_entry->path, $query);
00136   foreach ($feed as $entry) {
00137     echo "\n found " . $entry->id->text;
00138   }
00139   
00140   # combined searches are NOT ALLOWED => if set, the meta argument will prevail
00141   echo "\n\nSearch for all files with 'dc:creator'='Rambla' (the iqmeta argument will be ignored) :";
00142   $query = new Rass_ExtQuery("file");
00143   $query->setSearchArg("meta", array("dc:creator:Rambla"));
00144   $query->setSearchArg("iqmeta", array(), array(), array("2010"));
00145   $feed = $rass->getExtFeed($dir_entry->path, $query);
00146   foreach ($feed as $entry) {
00147     echo "\n found " . $entry->id->text;
00148   }
00149   
00150   # combined searches are NOT ALLOWED => you can unset a search argument
00151   echo "\n\nSearch for all files with with meta elements that don't contain the string '2010' or '2009 :";
00152   $query = new Rass_ExtQuery("file");
00153   $query->setSearchArg("meta", array("dc:creator:Rambla"));
00154   $query->unsetSearchArg("meta");
00155   $query->setSearchArg("iqmeta", array(), array(), array("2009","2010"));
00156   $feed = $rass->getExtFeed($dir_entry->path, $query);
00157   foreach ($feed as $entry) {
00158     echo "\n found " . $entry->id->text;
00159   }
00160   
00161   // # DELETE directory on the CDN. Set second argument to True to delete recursively.
00162   // $rass->deleteDir($dir_entry->path, True);
00163   // echo "\nDeleted dir: " . $dir_entry->path . "\n";
00164     
00165 
00166 
00167 }
00168 catch(Zend_Gdata_App_Exception $e) {
00169     # Report the exception to the user
00170     echo "\nCaught exception: " . get_class($e) . "\n";
00171     echo "Message: " . $e->getMessage() . "\n";
00172     # get the HTTP status code
00173     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00174     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00175     # get the raws:error elements
00176     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00177     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00178     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00179     $reasons = $rawsResponse->getReasons();
00180     foreach ($reasons as $reason) {
00181       echo "Raws Reason: " . $reason . "\n";
00182     }
00183     $details = $rawsResponse->getDetails();
00184     foreach ($details as $key => $value) {
00185       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00186     }
00187 }
00188 catch (Zend_Exception $e) {
00189     echo "Caught exception: " . get_class($e) . "\n";
00190     echo "Message: " . $e->getMessage() . "\n";
00191 }

Generated on Mon Mar 28 15:03:20 2011 for RawsClient PHP by  doxygen 1.5.3