2 * API modes (implementations should call these objects which inherit the mvBaseRemoteSearch
5 "mwe-stream_title" : "$1 $2 to $3"
7 var metavidSearch = function( iObj ) {
8 return this.init( iObj );
10 metavidSearch.prototype = {
11 defaultReq: { // set up the default request paramaters
13 'feed_format':'json_rss',
14 'cb_inx': 1 // Not really used (we should update the metavid json retrun system)
16 init:function( iObj ) {
17 // init base class and inherit:
18 var baseSearch = new baseRemoteSearch( iObj );
19 for ( var i in baseSearch ) {
20 if ( typeof this[i] == 'undefined' ) {
21 this[i] = baseSearch[i];
23 this['parent_' + i] = baseSearch[i];
27 getSearchResults:function() {
29 this.parent_getSearchResults();
32 js_log( 'metavidSearch::getSearchResults()' );
33 // Proccess all options
34 var url = this.cp.api_url;
35 var reqObj = $j.extend({}, this.defaultReq);
36 reqObj[ 'f[0][t]' ] = 'match';
37 reqObj[ 'f[0][v]' ] = $j( '#rsd_q' ).val();
40 reqObj[ 'limit' ] = this.cp.limit;
41 reqObj[ 'offset' ] = this.cp.offset;
48 js_log( 'mvSearch: got data response::' );
49 var xmldata = ( data && data['pay_load'] ) ? mw.parseXML( data['pay_load'] ) : false;
51 // XML Error or No results:
52 _this.resultsObj = {};
57 // Add the data xml payload with context url:
58 _this.addRSSData( xmldata , url );
60 // Do some metavid specific pos processing on the rObj data:
61 for ( var i in _this.resultsObj ) {
62 var rObj = _this.resultsObj[i];
63 var proe = mw.parseUri( rObj['roe_url'] );
64 rObj['start_time'] = proe.queryKey['t'].split( '/' )[0];
65 rObj['end_time'] = proe.queryKey['t'].split( '/' )[1];
66 rObj['stream_name'] = proe.queryKey['stream_name'];
68 // All metavid content is public domain:
69 rObj['license'] = _this.rsd.getLicenceFromKey( 'pd' );
71 // Transform the title into a wiki_safe title:
72 rObj['titleKey'] = _this.getTitleKey( rObj );
74 // Default width of metavid clips:
75 rObj['target_width'] = 400;
77 rObj['author'] = 'US Government';
79 // Add in the date as UTC "toDateString" :
80 var d = _this.getDateFromLink( rObj.link );
81 rObj['date'] = d.toDateString();
83 // Set the license_template_tag ( all metavid content is PD-USGov )
84 rObj['license_template_tag'] = 'PD-USGov';
91 * Get a Title key for the assset name inside the mediaWiki system
93 getTitleKey:function( rObj ) {
94 return rObj['stream_name'] + '_part_' + rObj['start_time'].replace(/:/g, '.' ) + '_to_' + rObj['end_time'].replace(/:/g, '.' ) + '.ogv';
96 getTitle:function( rObj ) {
97 var sn = rObj['stream_name'].replace( /_/g, ' ' );
98 sn = sn.charAt( 0 ).toUpperCase() + sn.substr( 1 );
99 return gM( 'mwe-stream_title', [ sn, rObj.start_time, rObj.end_time ] );
101 getExtraResourceDescWiki:function( rObj ) {
104 if ( rObj.person && rObj.person['label'] )
105 o += '* featuring [[' + rObj.person['label'] + ']]' + "\n";
107 if ( rObj.parent_clip )
108 o += '* part of longer [' + rObj.parent_clip + ' video clip]' + "\n";
110 if ( rObj.person && rObj.person['url'] && rObj.person['label'] )
111 o += '* also see speeches by [' + $j.trim( rObj.person.url ) + ' ' + rObj.person['label'] + ']' + "\n";
114 if ( rObj.bill && rObj.bill['label'] && rObj.bill['url'] )
115 o += '* related to bill: [[' + rObj.bill['label'] + ']] more bill [' + rObj.bill['url'] + ' video clips]' + "\n";
118 // format is "quote" followed by [[name of person]]
119 getInlineDescWiki:function( rObj ) {
120 var o = this.parent_getInlineDescWiki( rObj );
121 // add in person if found
122 if ( rObj.person && rObj.person['label'] ) {
123 o = $j.trim( o.replace( rObj.person['label'], '' ) );
125 if ( o.substr( 0, 1 ) == ':' )
127 // add quotes and person at the end:
128 var d = this.getDateFromLink( rObj.link );
129 o = '"' + o + '" [[' + rObj.person['label'] + ']] on ' + d.toDateString();
131 // could do ref or direct link:
132 o += ' \'\'[' + $j.trim( rObj.link ) + ' source clip]\'\' ';
134 // var o= '"' + o + '" by [[' + rObj.person['label'] + ']] '+
135 // '<ref>[' + rObj.link + ' Metavid Source Page] for ' + rObj.title +'</ref>';
138 // give an updated start and end time updates the title and url
139 applyVideoAdj: function( rObj ) {
140 js_log( 'mv ApplyVideoAdj::' );
141 // update the titleKey:
142 rObj['titleKey'] = this.getTitleKey( rObj );
145 rObj['title'] = this.getTitle( rObj );
147 // update the interface:
148 js_log( 'update title to: ' + rObj['title'] );
149 $j( '#rsd_resource_title' ).html( gM( 'rsd_resource_edit', rObj['title'] ) );
151 // if the video is "roe" based select the ogg stream
152 if ( rObj.roe_url && rObj.pSobj.cp.stream_import_key ) {
153 var source = $j( '#embed_vid' ).get( 0 ).media_element.getSourceById( rObj.pSobj.cp.stream_import_key );
155 js_error( 'Error::could not find source: ' + rObj.pSobj.cp.stream_import_key );
157 rObj['src'] = source.getURI();
158 js_log( "g src_key: " + rObj.pSobj.cp.stream_import_key + ' src:' + rObj['src'] ) ;
163 getEmbedHTML:function( rObj , options ) {
166 var id_attr = ( options['id'] ) ? ' id = "' + options['id'] + '" ': '';
167 var style_attr = ( options['max_width'] ) ? ' style="width:' + options['max_width'] + 'px;"':'';
168 // @@maybe check type here ?
169 if ( options['only_poster'] ) {
170 return '<img ' + id_attr + ' src="' + rObj['poster'] + '" ' + style_attr + '>';
172 return '<video ' + id_attr + ' roe="' + rObj['roe_url'] + '"></video>';
175 getImageTransform:function( rObj, opt ) {
176 if ( opt.width <= 80 ) {
177 return getURLParamReplace( rObj.poster, { 'size' : "icon" } )
178 } else if ( opt.width <= 160 ) {
179 return getURLParamReplace( rObj.poster, { 'size' : "small" } )
180 } else if ( opt.width <= 320 ) {
181 return getURLParamReplace( rObj.poster, { 'size' : 'medium' } )
182 } else if ( opt.width <= 512 ) {
183 return getURLParamReplace( rObj.poster, { 'size' : 'large' } )
185 return getURLParamReplace( rObj.poster, { 'size' : 'full' } )
188 addResourceInfoFromEmbedInstance : function( rObj, embed_id ) {
189 var sources = $j( '#' + embed_id ).get( 0 ).media_element.getSources();
190 rObj.other_versions = '*[' + rObj['roe_url'] + ' XML of all Video Formats and Timed Text]' + "\n";
191 for ( var i in sources ) {
192 var cur_source = sources[i];
193 // rObj.other_versions += '*['+cur_source.getURI() +' ' + cur_source.title +']' + "\n";
194 if ( cur_source.id == this.cp.target_source_id )
195 rObj['url'] = cur_source.getURI();
197 // js_log('set url to: ' + rObj['url']);
200 getDateFromLink:function( link ) {
201 var dateExp = new RegExp( /_([0-9]+)\-([0-9]+)\-([0-9]+)/ );
202 var dParts = link.match ( dateExp );
204 var year_full = ( dParts[3].length == 2 ) ? '20' + dParts[3].toString():dParts[3];
205 d.setFullYear( year_full, dParts[1] - 1, dParts[2] );