<commit_before>
var fs = require('fs');
var os = require('os');
var url = require('url');
var util = require('util');
var http = require('follow-redirects').http;

var id3Reader = require('../../bin/TsId3Reader.node');

var kaltura = module.exports = require('../KalturaManager');
kaltura.mediaInfo = require('../media/KalturaMediaInfo');
kaltura.ffmpegParams = require('../media/KalturaFfmpegParams');


/**
 * Stream watcher, instantiated per rendition manifest
 * 
 * @param manager KalturaStreamManager
 * @param params {url, entryId, masterUrl}
 * @param finishCallback called when watching is not required anymore
 */
var KalturaStreamWatcher = function(manager, params, finishCallback){
	this.manager = manager;
	this.finishCallback = finishCallback;

	this.renditionId = KalturaCache.getManifestId(params.url);
	this.trackerOutputKeyWithAds = KalturaCache.getManifestContent(this.renditionId) + '_' + this.manager.MANIFEST_ADS_EXTENSION;
	this.trackerOutputKeyWithoutAds = KalturaCache.getManifestContent(this.renditionId) + '_' + this.manager.MANIFEST_NO_ADS_EXTENSION;
	this.entryRequiredKey = KalturaCache.getEntryRequired(params.entryId);
	this.cuePointsKey = KalturaCache.getCuePoints(params.entryId);
	this.elapsedTimeKey = KalturaCache.getElapsedTime(params.entryId);
	this.oldestSegmentTimeKey = KalturaCache.getOldestSegmentTime(params.entryId);
	this.elapsedTime = {};
	this.cuePoints = {};
	this.segmentsHistoryLimit = KalturaConfig.config.cloud.segmentsHistoryLimit;
	this.segmentsHistory = {};
	this.urlTranslations = {};

	this.firstTime = true;
	this.startTime = new Date().getTime();
	this.trackerRequired = false;

	this.renditionManifestHandledKey = KalturaCache.getRenditionManifestHandled(params.url);
	this.latency = KalturaConfig.config.stream.latency / 10; // assuming each segment is of 10 seconds
	
	this.url = params.url;
	this.lowestBitrate = params.lowestBitrate;
	this.entryId = params.entryId;
	this.partnerId = params.partnerId;
	this.masterUrl = params.masterUrl;
	this.shouldSaveNoAdsManifest = false;
	this.shouldSaveAdsManifest = false;
	
	var This = this;
	
	var doGetManifest = function() {
		// if the process crashed and restored, the cache key might exist although no one is watching this manifest
		if(params.restored){
			this.getManifest();
		}
		else{
			KalturaCache.get(this.renditionManifestHandledKey, function(data){
				if(!data){
					This.getManifest();
				}<commit_msg>Change this to This<commit_after>
var fs = require('fs');
var os = require('os');
var url = require('url');
var util = require('util');
var http = require('follow-redirects').http;

var id3Reader = require('../../bin/TsId3Reader.node');

var kaltura = module.exports = require('../KalturaManager');
kaltura.mediaInfo = require('../media/KalturaMediaInfo');
kaltura.ffmpegParams = require('../media/KalturaFfmpegParams');


/**
 * Stream watcher, instantiated per rendition manifest
 * 
 * @param manager KalturaStreamManager
 * @param params {url, entryId, masterUrl}
 * @param finishCallback called when watching is not required anymore
 */
var KalturaStreamWatcher = function(manager, params, finishCallback){
	this.manager = manager;
	this.finishCallback = finishCallback;

	this.renditionId = KalturaCache.getManifestId(params.url);
	this.trackerOutputKeyWithAds = KalturaCache.getManifestContent(this.renditionId) + '_' + this.manager.MANIFEST_ADS_EXTENSION;
	this.trackerOutputKeyWithoutAds = KalturaCache.getManifestContent(this.renditionId) + '_' + this.manager.MANIFEST_NO_ADS_EXTENSION;
	this.entryRequiredKey = KalturaCache.getEntryRequired(params.entryId);
	this.cuePointsKey = KalturaCache.getCuePoints(params.entryId);
	this.elapsedTimeKey = KalturaCache.getElapsedTime(params.entryId);
	this.oldestSegmentTimeKey = KalturaCache.getOldestSegmentTime(params.entryId);
	this.elapsedTime = {};
	this.cuePoints = {};
	this.segmentsHistoryLimit = KalturaConfig.config.cloud.segmentsHistoryLimit;
	this.segmentsHistory = {};
	this.urlTranslations = {};

	this.firstTime = true;
	this.startTime = new Date().getTime();
	this.trackerRequired = false;

	this.renditionManifestHandledKey = KalturaCache.getRenditionManifestHandled(params.url);
	this.latency = KalturaConfig.config.stream.latency / 10; // assuming each segment is of 10 seconds
	
	this.url = params.url;
	this.lowestBitrate = params.lowestBitrate;
	this.entryId = params.entryId;
	this.partnerId = params.partnerId;
	this.masterUrl = params.masterUrl;
	this.shouldSaveNoAdsManifest = false;
	this.shouldSaveAdsManifest = false;
	
	var This = this;
	
	var doGetManifest = function() {
		// if the process crashed and restored, the cache key might exist although no one is watching this manifest
		if(params.restored){
			This.getManifest();
		}
		else{
			KalturaCache.get(this.renditionManifestHandledKey, function(data){
				if(!data){
					This.getManifest();
				}
{'fraction_non_alphanumeric': 0.11914543960558752, 'fraction_numerical': 0.0024650780608052587, 'mean_word_length': 5.457559681697613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2347710', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1562, 'n_words': 293}