<commit_before>/**
 * VAST ad parser ( presently just works with VAST once there are more ad formats
 * we could abstract common parts of this parser process. 
 */
mw.VastAdParser = {
	/**
	 * VAST support
	 * Convert the vast ad display format into a display conf:
	 */	
	parse: function( xmlString ){
		var _this = this;
		var adConf = {};
		var $vast = $j( xmlString );
		// Get the basic set of sequences
		adConf.ads = [];
		$vast.find( 'ad' ).each( function( inx, node ){
			mw.log('kAds:: getVastAdDisplayConf: ' + node );
			var $ad = $j( node );
			
			// Set a local pointer to the current sequence: 
			var currentAd = { 'id' : $j( node ).attr('id') };
			
			// Set duration
			if( $ad.find('duration') ){
				currentAd.duration = mw.npt2seconds( $ad.find('duration').text() );
			}
			
			// Set impression urls
			currentAd.impressions = [];
			$ad.find( 'Impression' ).each( function(na, node){
				// Check if there is lots of impressions or just one: 
				if( $j(node).find('URL').length ){
					$ad.find('URL').each( function(na, urlNode){
						currentAd.impressions.push({
							'beaconUrl' : _this.getURLFromNode( urlNode ),
							'idtype' : $j( urlNode ).attr('id')
						})
					})
				} else {
					currentAd.impressions.push({
						'beaconUrl' : _this.getURLFromNode( node )
					})
				}
			});
			
			// Set Non Linear Ads
			currentAd.nonLinear = [];
			$ad.find( 'NonLinearAds NonLinear' ).each( function( na, nonLinearNode ){
				var staticResource = _this.getResourceObject( nonLinearNode );				
				if( staticResource ){
					// Add the staticResource to the ad config: 
					currentAd.nonLinear.push( staticResource );
				}
			});			
			
			// Set tracking events: 
			currentAd.trackingEvents = [];
			$ad.find('trackingEvents Tracking').each( function( na, trackingNode ){					
				currentAd.trackingEvents.push({
					'eventName' : $j( trackingNode ).attr('event'),  
					'beaconUrl' : _this.getURLFromNode( trackingNode )
				});
			});					
						
			currentAd.videoFiles = [];
			// Set the media file:
			$ad.find('MediaFiles MediaFile').each( function( na, mediaFile ){
				// Add the video source ( if an html5 compatible type ) 
				var type  = $j( mediaFile ).attr('type');
				// Normalize mp4 into h264 format: 
				if( type  == 'video/x-mp4' ){
					type = 'video/h264';
				}
				
				if(  type == 'video/h264' || type == 'video/ogg' || type == 'video/webm' ){			
					currentAd.videoFiles.push({ 
						'src' :_this.getURLFromNode( mediaFile ),
						'type' : type
					});
					mw.log( "VastAdParser::add MediaFile:" + currentAd.videoFile );
				}
			});
			
			// Look for video click through:
			$ad.find('VideoClicks ClickThrough').each( function(na, clickThrough){
				currentAd.clickThrough = _this.getURLFromNode( clickThrough );
			});
			
			// Set videoFile to default if not set: 
			if( currentAd.videoFiles.length == 0 ){
				mw.log( 'VastAdParser::MISSING videoFile set to missing html5 video urls: ');
				currentAd.videoFiles = mw.getConfig( 'Kaltura.MissingFlavorVideoUrls');
			}
			
			// Set the CompanionAds if present: 
			currentAd.companions = [];
			$ad.find('CompanionAds Companion').each( function( na, companionNode ){				
				var staticResource = _this.getResourceObject( companionNode );				
				if( staticResource ){
					// Add the staticResourceto the ad config: 
					currentAd.companions.push( staticResource )
				}
			});
			
			adConf.ads.push( currentAd );
			
		});
		return adConf;
	},
	
	// Return a static resource object
	getResourceObject: function( resourceNode ){
		var _this = this;<commit_msg>no video url removed for now ( should probably only be displayed in debug mode )<commit_after>/**
 * VAST ad parser ( presently just works with VAST once there are more ad formats
 * we could abstract common parts of this parser process. 
 */
mw.VastAdParser = {
	/**
	 * VAST support
	 * Convert the vast ad display format into a display conf:
	 */	
	parse: function( xmlString ){
		var _this = this;
		var adConf = {};
		var $vast = $j( xmlString );
		// Get the basic set of sequences
		adConf.ads = [];
		$vast.find( 'ad' ).each( function( inx, node ){
			mw.log('kAds:: getVastAdDisplayConf: ' + node );
			var $ad = $j( node );
			
			// Set a local pointer to the current sequence: 
			var currentAd = { 'id' : $j( node ).attr('id') };
			
			// Set duration
			if( $ad.find('duration') ){
				currentAd.duration = mw.npt2seconds( $ad.find('duration').text() );
			}
			
			// Set impression urls
			currentAd.impressions = [];
			$ad.find( 'Impression' ).each( function(na, node){
				// Check if there is lots of impressions or just one: 
				if( $j(node).find('URL').length ){
					$ad.find('URL').each( function(na, urlNode){
						currentAd.impressions.push({
							'beaconUrl' : _this.getURLFromNode( urlNode ),
							'idtype' : $j( urlNode ).attr('id')
						})
					})
				} else {
					currentAd.impressions.push({
						'beaconUrl' : _this.getURLFromNode( node )
					})
				}
			});
			
			// Set Non Linear Ads
			currentAd.nonLinear = [];
			$ad.find( 'NonLinearAds NonLinear' ).each( function( na, nonLinearNode ){
				var staticResource = _this.getResourceObject( nonLinearNode );				
				if( staticResource ){
					// Add the staticResource to the ad config: 
					currentAd.nonLinear.push( staticResource );
				}
			});			
			
			// Set tracking events: 
			currentAd.trackingEvents = [];
			$ad.find('trackingEvents Tracking').each( function( na, trackingNode ){					
				currentAd.trackingEvents.push({
					'eventName' : $j( trackingNode ).attr('event'),  
					'beaconUrl' : _this.getURLFromNode( trackingNode )
				});
			});					
						
			currentAd.videoFiles = [];
			// Set the media file:
			$ad.find('MediaFiles MediaFile').each( function( na, mediaFile ){
				// Add the video source ( if an html5 compatible type ) 
				var type  = $j( mediaFile ).attr('type');
				// Normalize mp4 into h264 format: 
				if( type  == 'video/x-mp4' ){
					type = 'video/h264';
				}
				
				if(  type == 'video/h264' || type == 'video/ogg' || type == 'video/webm' ){			
					currentAd.videoFiles.push({ 
						'src' :_this.getURLFromNode( mediaFile ),
						'type' : type
					});
					mw.log( "VastAdParser::add MediaFile:" + currentAd.videoFile );
				}
			});
			
			// Look for video click through:
			$ad.find('VideoClicks ClickThrough').each( function(na, clickThrough){
				currentAd.clickThrough = _this.getURLFromNode( clickThrough );
			});
			
			// Set videoFile to default if not set: 
			if( currentAd.videoFiles.length == 0 ){
				mw.log( 'VastAdParser::MISSING videoFile no video url: ');
				//currentAd.videoFiles = mw.getConfig( 'Kaltura.MissingFlavorVideoUrls');
			}
			
			// Set the CompanionAds if present: 
			currentAd.companions = [];
			$ad.find('CompanionAds Companion').each( function( na, companionNode ){				
				var staticResource = _this.getResourceObject( companionNode );				
				if( staticResource ){
					// Add the staticResourceto the ad config: 
					currentAd.companions.push( staticResource )
				}
			});
			
			adConf.ads.push( currentAd );
			
		});
		return adConf;
	},
	
	// Return a static resource object
	getResourceObject: function( resourceNode ){
		var _this = this;
{'fraction_non_alphanumeric': 0.14222590444628555, 'fraction_numerical': 0.0040044186688760015, 'mean_word_length': 2.716264751154438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7469798', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2308, 'n_words': 602}