<commit_before>

Fairywren.torrentTab.extension.mediainfo = {
	displayName : 'Media Info',
	attach : function(data,div)
	{
		var files = $("<ul />");
		
		for(filename in data.files)
		{
			var trackList = $("<ul />");
			var file = data.files[filename];
			var tracks = file.tracks;
			for(var i = 0; i != tracks.length; ++i)
			{
				var track = tracks[i];
				var trackKvs = $("<ul />");
				for( k in track )
				{
					var v = $("<span />").text(track[k]);
					var k = $("<span />").text(k);
					trackKvs.append($("<li />").append(k,$("<span />").text(': '),v));
				}
				trackList.append($("<li />").append($("<span />").text(track.type),trackKvs));
			}
			
			var fileItem = $("<li />");
			fileItem.append($("<span />").text(filename));
			fileItem.append(trackList);
			files.append(fileItem);
		}
		div.append(files);
	}
};<commit_msg>came up with a JS pattern to clean up the media info<commit_after>

Fairywren.torrentTab.extension.mediainfo = {
	displayName : 'Media Info',
	attach : function(data,div)
	{
		var files = $("<ul />");
		var hidden = [];
		for(filename in data.files)
		{
			var trackList = $("<ul />");
			var file = data.files[filename];
			var tracks = file.tracks;
			for(var i = 0; i != tracks.length; ++i)
			{
				var track = tracks[i];
				
				var showTrack = track.type in Fairywren.torrentTab.extension.mediainfo.allowedTracks;
				
				var trackKvs = $("<ul />");
				for( k in track )
				{
					var v = $("<span />").text(track[k]);
					
					var kText = k;
					
					var showKey = false;
					if(showTrack)
					{
						showKey = k in Fairywren.torrentTab.extension.mediainfo.allowedTracks[track.type];
					}
					
					if(showKey)
					{
						kText = Fairywren.torrentTab.extension.mediainfo.allowedTracks[track.type][k]||kText;
					}
					
					var k = $("<span />").text(kText);
					
					var kvElement = $("<li />").append(k,$("<span />").text(': '),v);
					
					if(!showKey)
					{
						kvElement.hide();
						hidden.push(kvElement);
					}
					
					trackKvs.append(kvElement);
				}
				
				var trackElements = $("<li />").append($("<span />").text(track.type),trackKvs);

				if(!showTrack)
				{
					trackElements.hide();
					hidden.push(trackElements);
				}

				trackList.append(trackElements);
				
			}
			
			var fileItem = $("<li />");
			fileItem.append($("<span />").text(filename));
			fileItem.append(trackList);
			files.append(fileItem);
		}
		
		var showAllButton = $("<span />");
		showAllButton.text('Show All');
		showAllButton.addClass('torrentLink');
		showAllButton.click(function()
		{
			for(var i = 0 ; i != hidden.length; ++i)
			{
				hidden[i].show();
			}
			$(this).remove();
		})
		
		div.append($("<div />").append(showAllButton));
		div.append(files);
	}
};

Fairywren.torrentTab.extension.mediainfo.allowedTracks = {
	'General' : {
		'Format' : null,
		'Duration' : null,
		'File_size' : 'File Size',
		'Stream_size' : 'Stream Size'
	},
	
	'Video' : {
		'Width':null,
		'Height':null,
		'Frame_rate' : 'Frame Rate',
		'Bit_rate' : 'Bit Rate',
		'Stream_size' : 'Stream Size'
		},
	
	'Audio' : {
		'Compression_mode' : 'Compression Mode',
		'Language' : null,
		'Bit_rate' : 'Bit Rate',
		'Channel_s_' : 'Channels',
		'Format' : null,
		'Stream_size' : 'Stream Size',
		'Duration' : null,
		'Sampling_rate' : 'Sampling rate'
	},
	
	'Text': {
		'Language' : null
		}
	
};
{'fraction_non_alphanumeric': 0.20089020771513352, 'fraction_numerical': 0.0008902077151335311, 'mean_word_length': 2.783389450056117, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1338394', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1212, 'n_words': 231}