<commit_before>//
//  SubImport.m
//  SSARender2
//
//  Created by <NAME> on 7/24/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#include <QuickTime/QuickTime.h>
#include "CommonUtils.h"
#include "Codecprintf.h"
#include "CodecIDs.h"
#import "SubImport.h"
#import "SubParsing.h"
#import "SubUtilities.h"

//#define SS_DEBUG

#pragma mark C

// if the subtitle filename is something like title.en.srt or movie.fre.srt
// this function detects it and returns the subtitle language
short GetFilenameLanguage(CFStringRef filename)
{
	CFRange findResult;
	CFStringRef baseName = NULL;
	CFStringRef langStr = NULL;
	short lang = langUnspecified;
	
	// find and strip the extension
	findResult = CFStringFind(filename, CFSTR("."), kCFCompareBackwards);
	findResult.length = findResult.location;
	findResult.location = 0;
	baseName = CFStringCreateWithSubstring(NULL, filename, findResult);
	
	// then find the previous period
	findResult = CFStringFind(baseName, CFSTR("."), kCFCompareBackwards);
	findResult.location++;
	findResult.length = CFStringGetLength(baseName) - findResult.location;
	
	// check for 3 char language code
	if (findResult.length == 3) {
		char langCStr[4] = "";
		
		langStr = CFStringCreateWithSubstring(NULL, baseName, findResult);
		CFStringGetCString(langStr, langCStr, 4, kCFStringEncodingASCII);
		lang = ISO639_2ToQTLangCode(langCStr);
		
		CFRelease(langStr);
		
		// and for a 2 char language code
	} else if (findResult.length == 2) {
		char langCStr[3] = "";
		
		langStr = CFStringCreateWithSubstring(NULL, baseName, findResult);
		CFStringGetCString(langStr, langCStr, 3, kCFStringEncodingASCII);
		lang = ISO639_1ToQTLangCode(langCStr);
		
		CFRelease(langStr);
	}
	
	CFRelease(baseName);
	return lang;
}

static bool ShouldEngageFrontRowHack(void)
{
	bool ret;
	Boolean isSet;
	
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	NSString *applicationName = [[NSProcessInfo processInfo] processName];
	long minorVersion;
	Gestalt(gestaltSystemVersionMinor, &minorVersion);
	CFPreferencesGetAppBooleanValue(CFSTR("PerianFrontRowSubtitleHack"),CFSTR("org.perian.Perian"),&isSet);
	
	ret = (minorVersion == 5) && [applicationName isEqualToString:@"Front Row"] && isSet;
	[pool release];
	
	return ret;<commit_msg>Commit by astrange: Enable the Front Row hack by default.<commit_after>//
//  SubImport.m
//  SSARender2
//
//  Created by <NAME> on 7/24/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#include <QuickTime/QuickTime.h>
#include "CommonUtils.h"
#include "Codecprintf.h"
#include "CodecIDs.h"
#import "SubImport.h"
#import "SubParsing.h"
#import "SubUtilities.h"

//#define SS_DEBUG

#pragma mark C

// if the subtitle filename is something like title.en.srt or movie.fre.srt
// this function detects it and returns the subtitle language
short GetFilenameLanguage(CFStringRef filename)
{
	CFRange findResult;
	CFStringRef baseName = NULL;
	CFStringRef langStr = NULL;
	short lang = langUnspecified;
	
	// find and strip the extension
	findResult = CFStringFind(filename, CFSTR("."), kCFCompareBackwards);
	findResult.length = findResult.location;
	findResult.location = 0;
	baseName = CFStringCreateWithSubstring(NULL, filename, findResult);
	
	// then find the previous period
	findResult = CFStringFind(baseName, CFSTR("."), kCFCompareBackwards);
	findResult.location++;
	findResult.length = CFStringGetLength(baseName) - findResult.location;
	
	// check for 3 char language code
	if (findResult.length == 3) {
		char langCStr[4] = "";
		
		langStr = CFStringCreateWithSubstring(NULL, baseName, findResult);
		CFStringGetCString(langStr, langCStr, 4, kCFStringEncodingASCII);
		lang = ISO639_2ToQTLangCode(langCStr);
		
		CFRelease(langStr);
		
		// and for a 2 char language code
	} else if (findResult.length == 2) {
		char langCStr[3] = "";
		
		langStr = CFStringCreateWithSubstring(NULL, baseName, findResult);
		CFStringGetCString(langStr, langCStr, 3, kCFStringEncodingASCII);
		lang = ISO639_1ToQTLangCode(langCStr);
		
		CFRelease(langStr);
	}
	
	CFRelease(baseName);
	return lang;
}

//Use ugly transparency ("transparent" blend mode) for files imported in Front Row 
//At the moment it doesn't support graphicsModePreBlackAlpha static bool ShouldEngageFrontRowHack(void)
{
	bool ret;
	Boolean isSet;
	
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	NSString *applicationName = [[NSProcessInfo processInfo] processName];
	long minorVersion;
	Gestalt(gestaltSystemVersionMinor, &minorVersion);
	if (!CFPreferencesGetAppBooleanValue(CFSTR("PerianFrontRowSubtitleHack"),CFSTR("org.perian.Perian"),&isSet)) 
		isSet = 1; 
		
	ret = (minorVersion == 5) && [applicationName isEqualToString:@"Front Row"] && isSet;
	[pool release];
	
	return ret;
{'fraction_non_alphanumeric': 0.11248948696383515, 'fraction_numerical': 0.011984861227922625, 'mean_word_length': 5.067602040816326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4189057', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1542, 'n_words': 386}