<commit_before>string canonicalize(string fn)
{
	fn=lower_case(fn);
	if ((<"avi","mkv","mp4","mpg","mpeg">)[(fn/".")[-1]]) fn=(fn/".")[..<1]*"."; //Trim known file extensions
	sscanf(fn,"looney.tunes.%s.19",fn);
	fn=replace(fn," - "," ");
	sscanf(fn,"bugs bunny %s",fn);
	sscanf(fn,"%*d%s",fn);
	sscanf(String.trim_all_whites(fn),"the %s",fn);
	fn=replace(fn,":',?!-. "/1,"");
	return fn;
}

int main(int argc,array(string) argv)
{
	if (argc>1 && argv[1]=="index")
	{
		string url="http://looney.goldenagecartoons.com/WBchecklist.html";
		string data=replace(Protocols.HTTP.get_url_data(url),"\r","");
		sscanf(data,"%{%*s\n19%2d:\n%{____ %s\n%}%}",array years);
		Stdio.File out=Stdio.File("LooneyTunes.txt","wct");
		out->write("Looney Tunes checklist from %s\n\n",url);
		foreach (years,[int year,array(array(string)) titles])
			out->write("%{/19"+year+" - %s.mkv\n%}",titles);
		write("Index rebuilt.\n");
		return 0;
	}
	mapping(string:string) decanonicalize=([]);
	foreach (array_sscanf(Stdio.read_file("LooneyTunes.txt"),"%*s\n\n%{/%s\n%}")[0],[string fn])
	{
		string canon=canonicalize(fn);
		if (decanonicalize[canon]) exit(1,"Canonicalization collision on %O: %O and %O\n",canon,decanonicalize[canon],fn);
		decanonicalize[canon]=fn;
	}
	//Lift the modified sh_quote() from a similar script
	function sh_quote=((object)"rename.pike")->sh_quote;
	foreach (argv[1..],string fn)
	{
		if (string target=decanonicalize[canonicalize(explode_path(fn)[-1])])
		{
			if (file_stat("/video/LooneyTunes/"+target)) {/*werror("Target already exists: %O\n",target);*/ continue;}
			//write("Transform %O into %O\n",fn,target); continue;
			if (has_suffix(fn,".mkv"))
			{
				//Simple: directly copy or rename the file.<commit_msg>LooneyTunes: Defer collision reporting until it's actually an issue<commit_after>string canonicalize(string fn)
{
	fn=lower_case(fn);
	if ((<"avi","mkv","mp4","mpg","mpeg">)[(fn/".")[-1]]) fn=(fn/".")[..<1]*"."; //Trim known file extensions
	sscanf(fn,"looney.tunes.%s.19",fn);
	fn=replace(fn," - "," ");
	sscanf(fn,"bugs bunny %s",fn);
	sscanf(fn,"%*d%s",fn);
	sscanf(String.trim_all_whites(fn),"the %s",fn);
	fn=replace(fn,":',?!-. "/1,"");
	return fn;
}

int main(int argc,array(string) argv)
{
	if (argc>1 && argv[1]=="index")
	{
		string url="http://looney.goldenagecartoons.com/WBchecklist.html";
		string data=replace(Protocols.HTTP.get_url_data(url),"\r","");
		sscanf(data,"%{%*s\n19%2d:\n%{____ %s\n%}%}",array years);
		Stdio.File out=Stdio.File("LooneyTunes.txt","wct");
		out->write("Looney Tunes checklist from %s\n\n",url);
		foreach (years,[int year,array(array(string)) titles])
			out->write("%{/19"+year+" - %s.mkv\n%}",titles);
		write("Index rebuilt.\n");
		return 0;
	}
	mapping(string:string) decanonicalize=([]);
	foreach (array_sscanf(Stdio.read_file("LooneyTunes.txt"),"%*s\n\n%{/%s\n%}")[0],[string fn])
	{
		string canon=canonicalize(fn);
		//if (decanonicalize[canon]) exit(1,"Canonicalization collision on %O: %O and %O\n",canon,decanonicalize[canon],fn); //Raise immediate error on collision, or...
		if (decanonicalize[canon]) fn="! Collision !"; //... just record the problem (throw error only if we try to use this)
		decanonicalize[canon]=fn;
	}
	//Lift the modified sh_quote() from a similar script
	function sh_quote=((object)"rename.pike")->sh_quote;
	foreach (argv[1..],string fn)
	{
		if (string target=decanonicalize[canonicalize(explode_path(fn)[-1])])
		{
			if (target=="! Collision !") exit(1,"Ambiguous canonicalization on %O\n",fn);
			if (file_stat("/video/LooneyTunes/"+target)) {/*werror("Target already exists: %O\n",target);*/ continue;}
			//write("Transform %O into %O\n",fn,target); continue;
			if (has_suffix(fn,".mkv"))
			{
				//Simple: directly copy or rename the file.
{'fraction_non_alphanumeric': 0.23357275871242353, 'fraction_numerical': 0.009843043362596435, 'mean_word_length': 5.527777777777778, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 13, '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': '60915', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1486, 'n_words': 253}