Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / libAddMedia / searchLibs / archiveOrgSearch.js
blob83d211132bf821ec60f36eb2f8e6526f0813096c
1 //archive.org uses solr engine: 
2 //more about solr here: 
3 //http://lucene.apache.org/solr/
5 var archiveOrgSearch = function ( iObj){
6         return this.init( iObj );
8 archiveOrgSearch.prototype = {
9         //archive.org constants: 
10         dnUrl:'http://www.archive.org/download/',
11         dtUrl:'http://www.archive.org/details/',
12         init:function( iObj ){
13                 //init base class and inherit: 
14                 var baseSearch = new baseRemoteSearch( iObj );
15                 for(var i in baseSearch){
16                         if(typeof this[i] =='undefined'){
17                                 this[i] = baseSearch[i];
18                         }else{
19                                 this['parent_'+i] =  baseSearch[i];
20                         }
21                 }
22                 //inherit the cp settings for 
23         },
24         getSearchResults:function(){
25                 //call parent: 
26                 this.parent_getSearchResults();
27                 
28                 var _this = this;               
29                 this.loading=true;
30                 js_log('f:getSearchResults for:' + $j('#rsd_q').val() );                
31                 //build the query var
32                 var q = $j('#rsd_q').val();
33                 //@@todo check advanced options: include audio and images media types
34                 //for now force (Ogg video) & a creativecommons license
35                 q+=' format:(Ogg video)';
36                 q+=' licenseurl:(http\\:\\/\\/*)';
37                 var reqObj = {
38                         'q': q, //just search for video atm
39                         'fl':"description,title,identifier,licenseurl,format,license,thumbnail",                        
40                         'wt':'json',                    
41                         'rows':'30',
42                         'indent':'yes'                  
43                 }                                                                       
44                 do_api_req( {
45                         'data':reqObj, 
46                         'url':this.cp.api_url,
47                         'jsonCB':'json.wrf'
48                         }, function(data){                              
49                                 _this.addResults( data);
50                                 _this.loading = false;
51                         }
52                 );
53         },
54         addResults:function( data ){            
55                 var _this = this;                       
56                 if(data.response && data.response.docs){
57                         //set result info: 
58                         this.num_results = data.response.numFound;
59                 
60                         for(var resource_id in data.response.docs){
61                                 var resource = data.response.docs[resource_id];                         
62                                 var rObj = {
63                                         //@@todo we should add .ogv or oga if video or audio:
64                                         'titleKey'       :  resource.identifier + '.ogg',
65                                         'resourceKey':  resource.identifier,                            
66                                         'link'           : _this.dtUrl + resource.identifier,                           
67                                         'title'          : resource.title,
68                                         'poster'         : _this.dnUrl + resource.identifier+'/format=thumbnail',
69                                         'poster_ani' : _this.dnUrl + resource.identifier+'/format=Animated+Gif',
70                                         'thumbwidth' : 160,
71                                         'thumbheight': 110,                     
72                                         'desc'           : resource.description,
73                                         'src'             : _this.dnUrl + resource.identifier+'/format=Ogg+video',
74                                         'mime'            : 'application/ogg',
75                                         //set the licence: (rsd is a pointer to the parent remoteSearchDriver )          
76                                         'license'         : this.rsd.getLicenceFromUrl( resource.licenseurl ),
77                                         'pSobj'          :_this                         
78                                         
79                                 };                                                                                                                                                                                                               
80                                 this.resultsObj[ resource_id ] = rObj;
81                                 
82                                 //likely a audio clip if no poster and type application/ogg 
83                                 //@@todo we should return audio/ogg for the mime type or some other way to specify its "audio" 
84                                                 
85                                 //this.num_results++;   
86                                 //for(var i in this.resultsObj[page_id]){
87                                 //      js_log('added: '+ i +' '+ this.resultsObj[page_id][i]);
88                                 //}
89                         }
90                 }               
91         },
92         getEmbedTimeMeta:function(rObj, callback){
93                 var _this = this;
94                 do_api_req( {
95                         'data':{'avinfo':1},
96                         'url':_this.dnUrl + rObj.resourceKey + '/format=Ogg+video'
97                 },function(data){                       
98                         var cat = data;
99                         if(data['length'])
100                                 rObj.duration = data['length'];
101                         if(data['width'])
102                                 rObj.width = data['width'];
103                         if(data['height'])
104                                 rObj.height = data['height'];
105                                                                    
106                         callback();
107                 });
108         },
109         getEmbedHTML: function( rObj , options) {
110                 js_log('getEmbedHTML:: ' + rObj.poster );
111                 if(!options)
112                         options ={};
113                 var id_attr = (options['id'])?' id = "' + options['id'] +'" ': '';
114                 var src = rObj.src + '?t=0:0:0/'+ seconds2npt( rObj.duration );
115                 if(rObj.mime == 'application/ogg' || rObj.mime == 'audio/ogg' || rObj.mime=='video/ogg'){
116                         return '<video ' + id_attr + ' src="' + src + '" poster="' + rObj.poster + '" type="video/ogg"></video>';
117                 }
118         }