#include <Platform_Lib/SubtitleParser/SMIParser.h>
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include <string.h>
#include <ctype.h>
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <Platform_Lib/FontRenderer/render.h>
#include <Application/AppClass/SetupClass.h>
#include <Application/AppClass/setupdef.h>
#include <FlowEvent.h>
#include <Util.h>

#ifndef IS_SET
    #define IS_SET(x,y)     ((x) & (y))
    #define ClearFlag(x,y)  ((x) &= ~(y))
    #define SetFlag(x,y)    ((x) |= (y))
#endif

//#define DEBUGPRINT
#ifdef DEBUGPRINT
#define DBGPRINT(fmt,args...)  printf(fmt,## args)
#else 
#define DBGPRINT(fmt,args...) 
#endif

#define SUPPORT_TYPE HTML

char* SMIParser::simple_strchr(char* text,char find)
{
	int offset;
	assert(text!=0);
	//if(m_charset_encoding == SBCS){
	if(1){
		while(*text != '\0'){
			if(*text == find)
				return text;
			else {
				FontRenderer::get_char_code(text, UTF8, &offset);
				//printf("%d,%c\n",offset,*text);
				text+=offset;
				}
			}	
	}
	else{//BIG5 or GBK
		while(*text != '\0'){
			if(*text == find)
				return text;			
			if(*text < 0 ){//not single byte charset
				text += 2;
			}
			else
				text++;		
		}
	}
	return 0;//find nothing here
}

bool SMIParser :: Open(char *filename) {
	int AllLangExistFlag = 1;
	SMI_SUBTITLE_TYPE tmp_smi_subtitle[MAX_SMI_SUBTITLE_TYPE];
	int tmp_smi_subtitle_num = 0;
	off_t	previous_offset;
	fp = fopen(filename, "rb");
	if(fp == NULL) {
		SetFlag(m_state, SMI_PARSER_STATE_FAIL);
		return false;
	}

	switch((SetupClass::GetInstance())->GetTextSubtitleEncoding()){
		case TEXT_ENCODING_UTF8:
			DBGPRINT("Encoding:UTF8\n");
			m_file_encoding = UTF8;
			break;
		case TEXT_ENCODING_GBK:
			DBGPRINT("Encoding:GBK\n");
			m_file_encoding = DBCS_GBK;
			break;
		case TEXT_ENCODING_BIG5:
			DBGPRINT("Encoding:BIG5\n");
			m_file_encoding = DBCS_BIG5;
			break;
		default:
			m_file_encoding = UTF8;
	}
	
	unsigned char tmp[3];
	fread(tmp, 2, sizeof(char), fp);

	if((tmp[0] & 0xff) == 0xFF && (tmp[1] & 0xff) == 0xFE)
		m_charset_encoding = UTF16_LE;
	else if((tmp[0] & 0xff) == 0xFE && (tmp[1] & 0xff) == 0xFF)
		m_charset_encoding = UTF16_BE;
	else {
		rewind(fp);
		m_charset_encoding = SBCS;
	}
	
	int i;
	m_state = 0;
	bHasSMIHeader = true;
	smi_subtitle_num = 0;

	for(i=0;i<MAX_SMI_SUBTITLE_TYPE ;i++){
		smi_subtitle[i].index = -1;  //-1 means not used
		memset(smi_subtitle[i].type,0,32);
		memset(smi_subtitle[i].lang,0,32);
		smi_subtitle[i].filepos = 0;
	}
	
	char *tmpstr;
	char textBuffer[SMI_BUFFER_LENGTH];
	unsigned long long SyncStartPos;
	char in[SMI_BUFFER_LENGTH];
	do {
		previous_offset = ftell(fp);
		if(m_charset_encoding != SBCS){
			if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL){
				fclose(fp);
				return false;
			}
			FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
		}
		else{
			if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL){
				fclose(fp);
				return false;
			}
		}
	
		//fix bug: ingore the fisrt blank characters at every line
		tmpstr = textBuffer;
		while(isspace(*tmpstr))tmpstr++;
		if((!strncasecmp(tmpstr,"<BODY>",strlen("<BODY>")))||(!strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start")))){
			bHasSMIHeader = false;
			break;
		}
		if( (*tmpstr == '.') && simple_strchr(tmpstr,'{') && simple_strchr(tmpstr,'}')){
			char *p = simple_strchr(tmpstr,'.');
			if(sscanf(p+1,"%s",smi_subtitle[smi_subtitle_num].type) != 1)
				return false;
			p = strcasestr(tmpstr,"lang:");
			if(p != NULL){
				p=p+5;
				while(isspace(*p))p++;
				char *q = p;
				while(*q != ';')q++;
				strncpy(smi_subtitle[smi_subtitle_num].lang,p,q-p);
			}
			else
			{
				strcpy(smi_subtitle[smi_subtitle_num].lang,"unknown");
			}
			
			smi_subtitle[smi_subtitle_num].index = smi_subtitle_num;
			smi_subtitle_num++;
		}
	} while(strncasecmp(tmpstr,"</HEAD>",strlen("</HEAD>")));
	
	if(bHasSMIHeader == false){
			fseek(fp, previous_offset, SEEK_SET);
	}

	for(i=0;i<MAX_SMI_SUBTITLE_TYPE;i++){
		if(smi_subtitle[i].index != -1){
			DBGPRINT("type=%s lang =%s\n",smi_subtitle[i].type,smi_subtitle[i].lang);
		}
	}
	DBGPRINT("lang num=%d\n",smi_subtitle_num);

	//scan the file to get the <SyncStart fileposition of all language if lang num >= 2
	if(smi_subtitle_num >= 2)
	{
		while(!feof(fp)){

			do{
				SyncStartPos = ftell(fp);
				if(m_charset_encoding != SBCS){
					if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
						goto error_handling;
					FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
				}
				else{
					if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
						goto error_handling;
				}
					//fix bug: ingore the fisrt blank characters at every line
					tmpstr = textBuffer;
					while(isspace(*tmpstr))tmpstr++;
			} while(strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start")));

			//get subtitle text
			current_text[0] = '\0';
			char *tmp;
			tmp = simple_strchr(textBuffer,'>');
			if(strlen(tmp+1) + strlen(current_text) <= SMI_BUFFER_LENGTH)
				strcat(current_text, tmp+1);
			previous_offset = ftell(fp);
			if(m_charset_encoding != SBCS){
				if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
					goto error_handling;
				FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
			}
			else{
				if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
					goto error_handling;
			}
			//fix bug: ingore the fisrt blank characters at every line
			tmpstr = textBuffer;
			while(isspace(*tmpstr))tmpstr++;
				
			while(strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start"))){
				if(strlen(tmpstr) + strlen(current_text) <= SMI_BUFFER_LENGTH)
				strcat(current_text, tmpstr);
				previous_offset = ftell(fp);
				if(m_charset_encoding != SBCS){
					if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
						goto error_handling;
					FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
				}
				else{
					if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
						goto error_handling;
				}
				//fix bug: ingore the fisrt blank characters at every line
				tmpstr = textBuffer;
				while(isspace(*tmpstr))tmpstr++;
				
			}

			fseek(fp, previous_offset, SEEK_CUR);
			
			int flag = 1;
			for(int i= 0;i<(int)smi_subtitle_num;i++){
				if(!smi_subtitle[i].filepos){
					char tmpstr2[128];
					sprintf(tmpstr2,"<P Class=%s>",smi_subtitle[i].type);
					flag = 0;
					char *p = strcasestr(current_text,tmpstr2);
					if(p != NULL)
						smi_subtitle[i].filepos = SyncStartPos;
				}
			}

			if(flag == 1)
				goto lang_handling;
		}	
	}
	else
		goto lang_handling;

error_handling:
	AllLangExistFlag = 0;

lang_handling:	

	if(AllLangExistFlag){
		for(i= 0;i<(int)smi_subtitle_num;i++){
			DBGPRINT("AllLangExist ######### %ld ##############\n",smi_subtitle[i].filepos);
		}
	}
	else
	{
		for(i= 0;i<(int)smi_subtitle_num;i++){
			if(smi_subtitle[i].filepos != 0){
				tmp_smi_subtitle[tmp_smi_subtitle_num] = smi_subtitle[i];
				tmp_smi_subtitle_num++;
			}
		}
		smi_subtitle_num = tmp_smi_subtitle_num;
		for(i=0;i<tmp_smi_subtitle_num;i++){
			smi_subtitle[i] = tmp_smi_subtitle[i];
			DBGPRINT("NotAllLangExist ######### %ld ##############\n",smi_subtitle[i].filepos);
		}

		
	}


	default_lang_index = 0;
	lang_index = 0;
	fseek(fp,smi_subtitle[lang_index].filepos,SEEK_SET);
	startTimeMs = 0;
	stopTimeMs = 0;
	lastSeekTimeMs = -1;
	return true;
}

bool SMIParser :: Close() {
	if(fp != NULL)
		fclose(fp);
	return true;
}

int SMIParser :: GetSubtitle(int timeMs, SUBTITLE_STYLE_SHEET *stylesheet, char **text) {
	char textBuffer[SMI_BUFFER_LENGTH];
	char in[SMI_BUFFER_LENGTH];
	off_t previous_offset;
	lastSeekTimeMs = -1; // not seek but sequential read
	char *tmpstr;
	if(IS_SET(m_state, SMI_PARSER_STATE_FAIL))
		return -1;

	/* style sheet initialization */
	stylesheet->type = SUPPORT_TYPE;

	/* check current one */
		/* (1) [SUB_TIME START] <NAVTIME> [SUB_TIME STOP] */
	if(timeMs >= startTimeMs && timeMs < stopTimeMs) {
	//	*text = current_text;
	//	return(stopTimeMs - timeMs);
	  if(strncmp(current_text,"&nbsp",strlen("&nbsp")))
                {
                        DBGPRINT("1111111111111111");
                        *text = current_text;
                        DBGPRINT("%s",*text);
                        return(stopTimeMs - timeMs);

                }
                  else {
                        DBGPRINT("0000000000000");
                        *text = " ";
                        return -1;
                  }
	}
		/* (2) <NAVTIME> [SUB_TIME START] [SUB_TIME STOP] */
	else if(timeMs <= startTimeMs)
		return SubtitleSeek(timeMs, stylesheet, text);

		/* (3) [SUB_TIME START] [SUB_TIME STOP] <NAVTIME> */
	while(stopTimeMs == 0 || timeMs >= stopTimeMs) {
			//find First  <SYNC Start pattern To Get Start Time Code and text
			do {
				if(m_charset_encoding != SBCS){
					if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
						return -1;
					FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
				}
				else{
					if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
						return -1;
				}
				//fix bug: ingore the fisrt blank characters at every line
				tmpstr = textBuffer;
				while(isspace(*tmpstr))tmpstr++;
			} while(strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start")));

			//get Start time code
			if(sscanf(tmpstr+12, "%d>", &startTimeMs) != 1) {
			SetFlag(m_state, SMI_PARSER_STATE_ERROR);
			return -1;
			}
			
			//get subtitle text
			current_text[0] = '\0';
			char *tmp;
			tmp = simple_strchr(textBuffer,'>');
			if(tmp){
				if(strlen(tmp+1) + strlen(current_text) <= SMI_BUFFER_LENGTH)
					strcat(current_text, tmp+1);
			}
			previous_offset = ftell(fp);
			if(m_charset_encoding != SBCS){
				if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
						return -1;
				FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
			}
			else{
				if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
					return -1;
			}
			//fix bug: ingore the fisrt blank characters at every line
			tmpstr = textBuffer;
			while(isspace(*tmpstr))tmpstr++;

				
			while(strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start"))){
				if(strlen(tmpstr) + strlen(current_text) <= SMI_BUFFER_LENGTH)
				strcat(current_text, tmpstr);
				previous_offset = ftell(fp);
				if(m_charset_encoding != SBCS){
					if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
							return -1;
					FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
				}
				else{
					if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
						return -1;
				}
				//fix bug: ingore the fisrt blank characters at every line
				tmpstr = textBuffer;
				while(isspace(*tmpstr))tmpstr++;
				
			} 

			//Get Stop Time Code
			if(sscanf(tmpstr+12, "%d>", &stopTimeMs)!= 1) {
			SetFlag(m_state, SMI_PARSER_STATE_ERROR);
			return -1;
			}
			
			fseek(fp, previous_offset, SEEK_SET);
			
		}
	

		if((bHasSMIHeader == true) && (smi_subtitle_num >1)){ //multiple subtitles
			char tmpstr[128];
			sprintf(tmpstr,"<P Class=%s>",smi_subtitle[lang_index].type);
			char *p = strcasestr(current_text,tmpstr);

			if(p != NULL){
				p = p + strlen(tmpstr);
				char *q = strcasestr(p,"<P Class=");
				memset(textBuffer,0,SMI_BUFFER_LENGTH);
				if(q !=NULL){
						strncpy(textBuffer,p,q-p);
						strcpy(current_text,textBuffer);
				}
				else{
					strcpy(textBuffer,p);
					strcpy(current_text,textBuffer);
				}
			}
			else{
				//can not found this lang
				return -1;
			}
		
			
		}
		DBGPRINT("current text=%s",current_text);
		//format current_text		
		char *tmp,*tmp2;
		tmp = current_text;
		tmp2 = textBuffer;
		while(*tmp != '\0'){
			if((*tmp =='\r')||(*tmp =='\n')){
				tmp++;
				continue;
			}
			else if(*tmp == '<'){
				char *p = simple_strchr(tmp,'>');
				if(p == NULL){
					*text = NULL;
					return -1;
				}
				char text1[1024];
				memset(text1,0,1024);
				strncpy(text1,tmp,p-tmp+1);
				if(!strcasecmp(text1,"<br>")){
					*tmp2 = '\r';
					tmp2++;
					*tmp2 = '\n';
					tmp2++;
				}
				else if(strncasecmp(text1, "<p class=", strlen("<p class="))) {
					*tmp2++ =*tmp++;
					continue;
				}
				tmp=p+1;
				continue;
			}
			else
				*tmp2++ =*tmp++;
		}
		*tmp2 = '\r';
		tmp2++;
		*tmp2 = '\n';
		tmp2++;
		*tmp2 = '\0';
		strcpy(current_text,textBuffer);	

		if(timeMs >= startTimeMs && timeMs <= stopTimeMs) {
                if(strncmp(current_text,"&nbsp",strlen("&nbsp")))
                {     
					DBGPRINT("1111111111111111");        
					*text = current_text;
	                DBGPRINT("%s",*text);
                	return(stopTimeMs - timeMs);
                        
                }
				else {
					DBGPRINT("0000000000000");
					*text = " ";
					return -1;
				}
		}	
		else
			return -1;
}


int SMIParser :: SubtitleSeek(int timeMs, SUBTITLE_STYLE_SHEET *stylesheet, char **text) {
	char textBuffer[SMI_BUFFER_LENGTH];
	char in[SMI_BUFFER_LENGTH];
	off_t previous_offset;
	char *tmpstr;
	int errorcount=0;
	ClearFlag(m_state, SMI_PARSER_STATE_ERROR);

	/* redundant seek eliminiation */
		/* [last seek] [target] [stopTimeMs] */
	#if 0
	if(lastSeekTimeMs != -1 && timeMs > lastSeekTimeMs && timeMs < stopTimeMs) {
		lastSeekTimeMs = timeMs;
		return -1;
	}

	lastSeekTimeMs = timeMs;
	#endif
	/* style sheet initialization */
	stylesheet->type = SUPPORT_TYPE;

	/* rewind */
	rewind(fp);
	fseek(fp,smi_subtitle[lang_index].filepos,SEEK_SET);

	//DBGPRINT("aaaaaaaaaaaaaaaaaaaaa pos=%d\n",smi_subtitle[lang_index].filepos);
	
	startTimeMs = 0;
	stopTimeMs = 0;
	
	while(stopTimeMs == 0 || timeMs >= stopTimeMs || timeMs <= startTimeMs) {
			//find <SYNC Start pattern To Get Time Code and text
			do {
				if(m_charset_encoding != SBCS){
					if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
							return -1;
					FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
				}
				else{
					if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
						return -1;
				}
				//fix bug: ingore the fisrt blank characters at every line
				tmpstr = textBuffer;
				while(isspace(*tmpstr))tmpstr++;

				
			} while(strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start")));

			
			//get Start time code
			if(sscanf(tmpstr+12, "%d>", &startTimeMs) != 1) {
			SetFlag(m_state, SMI_PARSER_STATE_ERROR);
			return -1;
			}

			if(timeMs <= startTimeMs)
				errorcount += 1;
			if(errorcount >5)
				return -1;

			
			//get subtitle text
			current_text[0] = '\0';
			char *tmp;
			tmp = simple_strchr(textBuffer,'>');
			if(tmp){
			if(strlen(tmp+1) + strlen(current_text) <= SMI_BUFFER_LENGTH)
				strcat(current_text, tmp+1);
			}

			previous_offset = ftell(fp);
			if(m_charset_encoding != SBCS){
				if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
						return -1;
				FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
			}
			else{
				if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
					return -1;
			}
			//fix bug: ingore the fisrt blank characters at every line
			tmpstr = textBuffer;
			while(isspace(*tmpstr))tmpstr++;

			while(strncasecmp(tmpstr,"<SYNC Start",strlen("<SYNC Start"))){
				if(strlen(tmpstr) + strlen(current_text) <= SMI_BUFFER_LENGTH)
				strcat(current_text, tmpstr);
				previous_offset = ftell(fp);
				if(m_charset_encoding != SBCS){
					if(ufgets(in, SMI_BUFFER_LENGTH, fp, m_charset_encoding)==NULL)
							return -1;
					FontRenderer::charset_convert(m_charset_encoding, UTF8,in , textBuffer, SMI_BUFFER_LENGTH);
				}
				else{
					if(fgets(textBuffer,SMI_BUFFER_LENGTH,fp)==NULL)
						return -1;
				}
				//fix bug: ingore the fisrt blank characters at every line
				tmpstr = textBuffer;
				while(isspace(*tmpstr))tmpstr++;
			} 

			//Get Stop Time Code
			if(sscanf(tmpstr+12, "%d>", &stopTimeMs)!= 1) {
			SetFlag(m_state, SMI_PARSER_STATE_ERROR);
			return -1;
			}
		
			
			fseek(fp,previous_offset,SEEK_SET);
			
				

		}	

		if((bHasSMIHeader == true) && (smi_subtitle_num >1)){ //multiple subtitles
			char tmpstr[128];
			sprintf(tmpstr,"<P Class=%s>",smi_subtitle[lang_index].type);
			char *p = strcasestr(current_text,tmpstr);
			if(p !=NULL){
				p = p + strlen(tmpstr);
				char *q = strstr(p,"<P Class=");
				memset(textBuffer,0,SMI_BUFFER_LENGTH);
				if(q !=NULL){
						strncpy(textBuffer,p,q-p);
						strcpy(current_text,textBuffer);
				}
				else{
					strcpy(textBuffer,p);
					strcpy(current_text,textBuffer);
				}
			}
			else{
				//can not found this lang
				DBGPRINT("can not found this lang\n");
				return -1;
			}
		}
		DBGPRINT("current text=%s\n",current_text);
		//format current_text		
		char *tmp,*tmp2;
		tmp = current_text;
		tmp2 = textBuffer;
		while(*tmp != '\0'){
			if((*tmp =='\r')||(*tmp =='\n')){
				tmp++;
				continue;
			}
			else if(*tmp == '<'){
				char *p = simple_strchr(tmp,'>');
				if(p == NULL){
					*text = NULL;
					return -1;
				}
				char text1[1024];
				memset(text1,0,1024);
				strncpy(text1,tmp,p-tmp+1);
				if(!strcasecmp(text1,"<br>")){
					*tmp2 = '\r';
					tmp2++;
					*tmp2 = '\n';
					tmp2++;
				}
				else if(strncasecmp(text1, "<p class=", strlen("<p class="))) {
					*tmp2++ =*tmp++;
					continue;
				}
				tmp=p+1;
				continue;
			}
			else
				*tmp2++ =*tmp++;
		}
		*tmp2 = '\r';
		tmp2++;
		*tmp2 = '\n';
		tmp2++;
		*tmp2 = '\0';
		strcpy(current_text,textBuffer);	

		if(timeMs >= startTimeMs && timeMs <= stopTimeMs) {
                if(strncmp(current_text,"&nbsp",strlen("&nbsp")))
                {     
					DBGPRINT("1111111111111111");        
					*text = current_text;
	                DBGPRINT("%s",*text);
                	return(stopTimeMs - timeMs);
                        
                }
				else {
					DBGPRINT("0000000000000");
					*text = " ";
					return -1;
				}
		}	
		else
			return -1;
	
}

int SMIParser ::SwitchLang(char *LangName)
{

	do{
		lang_index++;
		if(lang_index >= MAX_SMI_SUBTITLE_TYPE)
		{
			lang_index = 0;
			fseek(fp,smi_subtitle[lang_index].filepos,SEEK_SET);
			DBGPRINT("LangIdx===%d\n",lang_index);	
			return -1;
		}
		if(smi_subtitle[lang_index].index != -1){
			fseek(fp,smi_subtitle[lang_index].filepos,SEEK_SET);
			strcpy(LangName,smi_subtitle[lang_index].lang);
			DBGPRINT("LangIdx=%d,LangName=%s\n",lang_index,LangName);	
			return 0;
		}
	}
	while(1);
}

int SMIParser ::GetDefaultLang(char *LangName){
	lang_index = default_lang_index;
	strcpy(LangName,smi_subtitle[lang_index].lang);
	DBGPRINT("Default LangIdx=%d,Default LangName=%s\n",lang_index,LangName);
	return 0;
}

int SMIParser ::GetLangNum(){
	return smi_subtitle_num;
}
