removed output-disable in dbms-output fetching procedure
[mediawiki.git] / js2 / mwEmbed / libAddMedia / searchLibs / archiveOrgSearch.js
blob78ceee1be13fe63ca3b80fb6b9821943cf659baf
1 /*
2 * Archive.org Search
3
4 * archive.org uses the solr engine: 
5 * more about solr here:  
6 * http://lucene.apache.org/solr/
7 */
9 var archiveOrgSearch = function ( iObj ) {
10         return this.init( iObj );
12 archiveOrgSearch.prototype = {
13         // Archive.org constants: 
14         downloadUrl : 'http://www.archive.org/download/',
15         detailsUrl : 'http://www.archive.org/details/',
16         /*
17         * Inititalize the archiveOrgSearch class.
18         * archiveOrgSearch inherits the baseSearch class 
19         */
20         init:function( options ) {              
21                 var baseSearch = new baseRemoteSearch( options );
22                 for ( var i in baseSearch ) {
23                         if ( typeof this[i] == 'undefined' ) {
24                                 this[i] = baseSearch[i];
25                         } else {
26                                 this['parent_' + i] =  baseSearch[i];
27                         }
28                 }
29         },
30         /**
31         * Gets the search results from the api query
32         */
33         getSearchResults:function() {
34                 // call parent: 
35                 this.parent_getSearchResults();
36                 var _this = this;
37                 js_log( 'f:getSearchResults for:' + $j( '#rsd_q' ).val() );
38                 // build the query var
39                 var q = $j( '#rsd_q' ).val();
40                 // @@todo check advanced options: include audio and images media types
41                 // for now force (Ogg video) & url based license
42                 q += ' format:(Ogg video)';
43                 q += ' licenseurl:(http\\:\\/\\/*)';
44                 var reqObj = {
45                         'q': q, // just search for video atm
46                         'fl':"description,title,identifier,licenseurl,format,license,thumbnail",
47                         'wt':'json',
48                         'rows' : this.cp.limit,
49                         'start' : this.cp.offset
50                 }
51                 do_api_req( {
52                         'data':reqObj,
53                         'url':this.cp.api_url,
54                         'jsonCB':'json.wrf'
55                         }, function( data ) {
56                                 _this.addResults( data );
57                                 _this.loading = false;
58                         }
59                 );
60         },
61         /**
62         * Adds the search results to the local resultsObj
63         */
64         addResults:function( data ) {
65                 var _this = this;
66                 if ( data.response && data.response.docs ) {
67                         // Set result info: 
68                         this.num_results = data.response.numFound;
69                 
70                         for ( var resource_id in data.response.docs ) {
71                                 var resource = data.response.docs[resource_id];
72                                 var rObj = {
73                                         // @@todo we should add .ogv or oga if video or audio:
74                                         'titleKey'       :  resource.identifier + '.ogg',
75                                         'resourceKey':  resource.identifier,
76                                         'link'           : _this.detailsUrl + resource.identifier,
77                                         'title'          : resource.title,
78                                         'poster'         : _this.downloadUrl + resource.identifier + '/format=thumbnail',
79                                         'poster_ani' : _this.downloadUrl + resource.identifier + '/format=Animated+Gif',
80                                         'thumbwidth' : 160,
81                                         'thumbheight': 110,
82                                         'desc'           : resource.description,
83                                         'src'            : _this.downloadUrl + resource.identifier + '/format=Ogg+video',
84                                         'mime'           : 'application/ogg',
85                                         // Set the license: (rsd is a pointer to the parent remoteSearchDriver )                 
86                                         'license'        : this.rsd.getLicenceFromUrl( resource.licenseurl ),
87                                         'pSobj'          :_this
88                                         
89                                 };
90                                 this.resultsObj[ resource_id ] = rObj;
91                         }
92                 }
93         },
94         /**
95         * Gets some media metadata via a archive.org special entry point "avinfo"
96         */ 
97         addResourceInfoCallback:function( rObj, callback ) {
98                 var _this = this;
99                 do_api_req( {
100                         'data': { 'avinfo' : 1 },
101                         'url':_this.downloadUrl + rObj.resourceKey + '/format=Ogg+video'
102                 }, function( data ) {
103                         if ( data['length'] )
104                                 rObj.duration = data['length'];
105                         if ( data['width'] )
106                                 rObj.width = data['width'];
107                         if ( data['height'] )
108                                 rObj.height = data['height'];
109                                                                    
110                         callback();
111                 } );
112         },
113         /*
114         * Returns html to embed a given result Object ( rObj ) 
115         */      
116         getEmbedHTML: function( rObj , options ) {
117                 js_log( 'getEmbedHTML:: ' + rObj.poster );
118                 if ( !options )
119                         options = { };
120                 var id_attr = ( options['id'] ) ? ' id = "' + options['id'] + '" ': '';
121                 if ( rObj.duration ) {
122                         var src = rObj.src + '?t=0:0:0/' + seconds2npt( rObj.duration );
123                 } else {
124                         var src = rObj.src;
125                 }
126                 if ( rObj.mime == 'application/ogg' || rObj.mime == 'audio/ogg' || rObj.mime == 'video/ogg' ) {
127                         return '<video ' + id_attr + ' src="' + src + '" poster="' + rObj.poster + '" type="video/ogg"></video>';
128                 }
129         }