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 reqObj
:{ //set up the default request paramaters
15 init:function( iObj
){
16 //init base class and inherit:
17 var baseSearch
= new baseRemoteSearch( iObj
);
18 for(var i
in baseSearch
){
19 if(typeof this[i
] =='undefined'){
20 this[i
] = baseSearch
[i
];
22 this['parent_'+i
] = baseSearch
[i
];
26 getSearchResults:function(){
28 this.parent_getSearchResults();
33 js_log('metavidSearch::getSearchResults()');
34 //proccess all options
35 var url
= this.cp
.api_url
;
36 //add on the req_param
37 for(var i
in this.reqObj
){
38 url
+= '&' + i
+ '=' + this.reqObj
[i
];
40 url
+= '&f[0][t]=match&f[0][v]=' + $j('#rsd_q').val();
42 url
+='&limit=' + this.cp
.limit
;
43 url
+='&offset=' + this.cp
.offset
;
45 do_request(url
, function(data
){
47 js_log('mvSearch: got data response');
48 //should have an xml rss data object:
49 _this
.addRSSData( data
, url
);
51 //do some metavid specific pos processing on the rObj data:
52 for(var i
in _this
.resultsObj
){
53 var rObj
= _this
.resultsObj
[i
];
54 var proe
= parseUri( rObj
['roe_url'] );
55 rObj
['start_time'] = proe
.queryKey
['t'].split('/')[0];
56 rObj
['end_time'] = proe
.queryKey
['t'].split('/')[1];
57 rObj
['stream_name'] = proe
.queryKey
['stream_name'];
59 //all metavid content is public domain:
60 rObj
['license'] = _this
.rsd
.getLicenceFromKey( 'pd' );
62 //transform the title into a wiki_safe title:
63 //rObj['titleKey'] = proe.queryKey['stream_name'] + '_' + rObj['start_time'].replace(/:/g,'.') + '_' + rObj['end_time'].replace(/:/g,'.') + '.ogg';
64 rObj
['titleKey'] = _this
.getTitleKey( rObj
);
66 //default width of metavid clips:
67 rObj
['target_width'] = 400;
73 getTitleKey:function( rObj
){
74 return rObj
['stream_name'] + '_start-' + rObj
['start_time'].replace(/:/g,'.') + '_end-' + rObj['end_time'].replace(/:/g
,'.') + '.ogg';
76 getTitle:function( rObj
){
77 var sn
= rObj
['stream_name'].replace(/_
/g
, ' ');
78 sn
= sn
.charAt(0).toUpperCase() + sn
.substr(1);
79 return gM('mwe-stream_title', [ sn
, rObj
.start_time
, rObj
.end_time
]);
81 //metavid descption tied to public domain license key (government produced content)
82 getPermissionWikiTag:function( rObj
){
83 return '{{PD-USGov}}';
85 getExtraResourceDescWiki:function( rObj
){
88 if( rObj
.person
&& rObj
.person
['label'])
89 o
+= '* featuring [[' + rObj
.person
['label'] + ']]' + "\n";
91 if( rObj
.parent_clip
)
92 o
+= '* part of longer [' + rObj
.parent_clip
+ ' video clip]'+ "\n";
94 if( rObj
.person
&& rObj
.person
['url'] && rObj
.person
['label'] )
95 o
+= '* also see speeches by [' + $j
.trim( rObj
.person
.url
) + ' ' + rObj
.person
['label'] + ']'+ "\n";
98 if( rObj
.bill
&& rObj
.bill
['label'] && rObj
.bill
['url'])
99 o
+= '* related to bill: [[' + rObj
.bill
['label'] + ']] more bill [' + rObj
.bill
['url'] + ' video clips]'+ "\n";
102 //format is "quote" followed by [[name of person]]
103 getInlineDescWiki:function( rObj
){
104 var o
= this.parent_getInlineDescWiki( rObj
);
105 //add in person if found
106 if( rObj
.person
&& rObj
.person
['label'] ){
107 o
= $j
.trim( o
.replace(rObj
.person
['label'], '') );
109 if(o
.substr(0,1)==':')
111 //add quotes and person at the end:
112 var d
= this.getDateFromLink( rObj
.link
);
113 o
='"' + o
+ '" [[' + rObj
.person
['label'] + ']] on ' + d
.toDateString();
115 //could do ref or direct link:
116 o
+= ' \'\'[' + $j
.trim( rObj
.link
) + ' source clip]\'\' ';
118 //var o= '"' + o + '" by [[' + rObj.person['label'] + ']] '+
119 // '<ref>[' + rObj.link + ' Metavid Source Page] for ' + rObj.title +'</ref>';
122 //give an updated start and end time updates the title and url
123 applyVideoAdj: function( rObj
){
124 js_log('mv ApplyVideoAdj::');
125 //update the titleKey:
126 rObj
['titleKey'] = this.getTitleKey( rObj
);
129 rObj
['title'] = this.getTitle( rObj
);
131 //update the interface:
132 js_log('update title to: ' + rObj
['title']);
133 $j('#rsd_resource_title').html( gM('rsd_resource_edit', rObj
['title'] ) );
135 //if the video is "roe" based select the ogg stream
136 if( rObj
.roe_url
&& rObj
.pSobj
.cp
.stream_import_key
){
137 var source
= $j('#embed_vid').get(0).media_element
.getSourceById( rObj
.pSobj
.cp
.stream_import_key
);
139 js_error('Error::could not find source: ' + rObj
.pSobj
.cp
.stream_import_key
);
141 rObj
['src'] = source
.getURI();
142 js_log("g src_key: " + rObj
.pSobj
.cp
.stream_import_key
+ ' src:' + rObj
['src']) ;
147 getEmbedHTML:function( rObj
, options
){
150 var id_attr
= (options
['id'])?' id = "' + options
['id'] +'" ': '';
151 var style_attr
= (options
['max_width'])?' style="width:'+options
['max_width']+'px;"':'';
152 //@@maybe check type here ?
153 if(options
['only_poster']){
154 return '<img ' + id_attr
+ ' src="' + rObj
['poster']+'" ' + style_attr
+ '>';
156 return '<video ' + id_attr
+ ' roe="' + rObj
['roe_url'] + '"></video>';
159 getImageTransform:function( rObj
, opt
){
160 if( opt
.width
<= 80 ){
161 return getURLParamReplace( rObj
.poster
, { 'size' : "icon" } )
162 }else if( opt
.width
<= 160 ){
163 return getURLParamReplace( rObj
.poster
, { 'size' : "small" } )
164 }else if( opt
.width
<= 320 ){
165 return getURLParamReplace( rObj
.poster
, { 'size' : 'medium' } )
166 }else if( opt
.width
<= 512 ){
167 return getURLParamReplace( rObj
.poster
, { 'size' : 'large' } )
169 return getURLParamReplace( rObj
.poster
, { 'size' : 'full' } )
172 getEmbedObjParsedInfo:function(rObj
, eb_id
){
173 var sources
= $j('#'+eb_id
).get(0).media_element
.getSources();
174 rObj
.other_versions
='*[' + rObj
['roe_url'] + ' XML of all Video Formats and Timed Text]'+"\n";
175 for(var i
in sources
){
176 var cur_source
= sources
[i
];
177 //rObj.other_versions += '*['+cur_source.getURI() +' ' + cur_source.title +']' + "\n";
178 if( cur_source
.id
== this.cp
.target_source_id
)
179 rObj
['url'] = cur_source
.getURI();
181 //js_log('set url to: ' + rObj['url']);
184 //update rObj for import:
185 updateDataForImport:function( rObj
){
186 rObj
['author']='US Government';
187 //convert data to UTC type date:
188 var d
= this.getDateFromLink( rObj
.link
);
189 rObj
['date'] = d
.toDateString();
190 rObj
['license_template_tag']='PD-USGov';
191 //update based on new start time:
192 js_log('url is: ' + rObj
.src
+ ' ns: ' + rObj
.start_time
+ ' ne:' + rObj
.end_time
);
196 getDateFromLink:function( link
){
197 var dateExp
= new RegExp(/_([0-9]+)\-([0-9]+)\-([0-9]+)/);
198 var dParts
= link
.match (dateExp
);
200 var year_full
= (dParts
[3].length
==2)?'20'+dParts
[3].toString():dParts
[3];
201 d
.setFullYear(year_full
, dParts
[1]-1, dParts
[2]);