<commit_before>var AudioPlayerManager;

(function(){
	var instance;

	AudioPlayerManager = function() {
		if(instance) {
			return instance;
		}

		instance = this;

		var audioPlayer;
		var episodeInfo;
		var playingTimeOutID;

		function getAudioTags(callback) {
			new jsmediatags.Reader(audioPlayer.src)
			.setTagsToRead(["PIC", "APIC"])
			.read({
				onSuccess: function(tag) {
					var tags = tag.tags;

					if( "picture" in tags ) {
						var image = tags.picture;
						var base64String = "";
						for (var i = 0; i < image.data.length; i++) {
								base64String += String.fromCharCode(image.data[i]);
						}

						tags.imageDataUrl = "data:" + image.format + ";base64," + window.btoa(base64String);

						callback(tags);
					}
				}
			});
		}

		function buildAudioInfo() {
			return {
				audio: {
					url: audioPlayer ? audioPlayer.src : '',
					imageUrl: episodeInfo && episodeInfo.audioTags ? episodeInfo.audioTags.imageDataUrl : '',
					currentTime: audioPlayer ? audioPlayer.currentTime : 0,
					duration: audioPlayer ? audioPlayer.duration : 0,
					playbackRate: audioPlayer ? audioPlayer.playbackRate : 1.0
				},
				episode: {
					title: episodeInfo ? episodeInfo.title : ''
				}
			}
		}

		function setEpisodeInProgress(podcastUrl, episodeId, currentTime) { 
			messageService.for('podcastManager').sendMessage('setEpisodeInProgress', {
				url: podcastUrl,
				episodeId: episodeId,
				currentTime: currentTime
			});
		}

		function playingTimeOut() {
			messageService.for('audioPlayer').sendMessage('playing', { episodePlayerInfo: buildAudioInfo() });

			// recursive timeout to be called 1/second
			playingTimeOutID = window.setTimeout(playingTimeOut, 1000);
		}

		function pauseTimeOut() {
			if(playingTimeOutID) {
				window.clearTimeout(playingTimeOutID);
				playingTimeOutID = undefined;
			}
		}

		function play(audioInfo) {
			if(audioInfo && audioInfo.episode && audioInfo.episode.url &&
				(!audioPlayer || audioInfo.episode.url !== audioPlayer.src)) {

				if(audioPlayer) {
					audioPlayer.pause( );

					if(audioPlayer.currentTime	!= audioPlayer.duration) {
						setEpisodeInProgress(episodeInfo.podcastUrl, episodeInfo.guid, audioPlayer.currentTime);
					}
				}

				audioPlayer = new Audio(audioInfo.episode.url);
				episodeInfo = audioInfo.episode;

				audioPlayer.onended = function() {<commit_msg>Set episodes in progress every 10 secods when playing<commit_after>var AudioPlayerManager;

(function(){
	var instance;

	AudioPlayerManager = function() {
		if(instance) {
			return instance;
		}

		instance = this;

		var audioPlayer;
		var episodeInfo;
		var playingTimeOutID;
		var timeOutCounter = 0;

		function getAudioTags(callback) {
			new jsmediatags.Reader(audioPlayer.src)
			.setTagsToRead(["PIC", "APIC"])
			.read({
				onSuccess: function(tag) {
					var tags = tag.tags;

					if( "picture" in tags ) {
						var image = tags.picture;
						var base64String = "";
						for (var i = 0; i < image.data.length; i++) {
								base64String += String.fromCharCode(image.data[i]);
						}

						tags.imageDataUrl = "data:" + image.format + ";base64," + window.btoa(base64String);

						callback(tags);
					}
				}
			});
		}

		function buildAudioInfo() {
			return {
				audio: {
					url: audioPlayer ? audioPlayer.src : '',
					imageUrl: episodeInfo && episodeInfo.audioTags ? episodeInfo.audioTags.imageDataUrl : '',
					currentTime: audioPlayer ? audioPlayer.currentTime : 0,
					duration: audioPlayer ? audioPlayer.duration : 0,
					playbackRate: audioPlayer ? audioPlayer.playbackRate : 1.0
				},
				episode: {
					title: episodeInfo ? episodeInfo.title : ''
				}
			}
		}

		function setEpisodeInProgress(podcastUrl, episodeId, currentTime) { 
			messageService.for('podcastManager').sendMessage('setEpisodeInProgress', {
				url: podcastUrl,
				episodeId: episodeId,
				currentTime: currentTime
			});
		}

		function playingTimeOut() {
			messageService.for('audioPlayer').sendMessage('playing', { episodePlayerInfo: buildAudioInfo() });

			timeOutCounter++;

			if(timeOutCounter === 10) {
				timeOutCounter = 0;
				setEpisodeInProgress(episodeInfo.podcastUrl, episodeInfo.guid, audioPlayer.currentTime);
			}

			// recursive timeout to be called 1/second
			playingTimeOutID = window.setTimeout(playingTimeOut, 1000);
		}

		function pauseTimeOut() {
			if(playingTimeOutID) {
				window.clearTimeout(playingTimeOutID);
				playingTimeOutID = undefined;
				timeOutCounter = 0;
			}
		}

		function play(audioInfo) {
			if(audioInfo && audioInfo.episode && audioInfo.episode.url &&
				(!audioPlayer || audioInfo.episode.url !== audioPlayer.src)) {

				if(audioPlayer) {
					audioPlayer.pause( );

					if(audioPlayer.currentTime	!= audioPlayer.duration) {
						setEpisodeInProgress(episodeInfo.podcastUrl, episodeInfo.guid, audioPlayer.currentTime);
					}
				}

				audioPlayer = new Audio(audioInfo.episode.url);
				episodeInfo = audioInfo.episode;

				audioPlayer.onended = function() {
{'fraction_non_alphanumeric': 0.12215568862275449, 'fraction_numerical': 0.008582834331337325, 'mean_word_length': 3.4110915492957745, 'pattern_counts': {'":': 0, '<': 5, '<?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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '319934', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1539, 'n_words': 289}