Jump to content
Sign in to follow this  
manit

automating load subtitle file in windows xp

Recommended Posts

manit

Hi ,

I recently wrote c program which autoloads subtitle file (srt type) , if only one or none found else asks user to select appropriate file from list .

Now I plan to write the same using autoit as it gives a gui look unlike DOS of c program binary.

First I did

I added an entry in registry

key : HKEY_CLASSES_ROOT\*\shell\autoload video with subtitles\command

default string : c:\turboc3\source\pass.exe %1

BTW my c code is

//printf("\nflag line 1"); used while debugging
#include<string.h> // for strcat,strcpy,strlen,memicmp,strrev
#include<stdio.h> // for fgets,fopen,fprintf,fclose
#include<stdlib.h> // for atoi,system
#include<conio.h> //for clrscr
//(3)currently we are using g:\log,list,a.bat files
char name[128],finalsf[128],sf[20][128],fp[128];//sf=subtitle file,name=only video file name
int sfnumber;//number of subtitle files found
 
int check(char d[128])
{ int len,cr;//cr=compare-result
char bkup[128];
len=strlen(d);
d[len-1]=0;//because last character in string received is \n then 0
strcpy(bkup,d);
strrev(d);
cr = memicmp(d, "trs", 3);
if (cr==0)
{ //printf("\n%d:%s is an srt file",len,bkup);
strcpy(sf[sfnumber],bkup);
return 1;
}
else
{ //printf("\n%s!=trs",d);
return 0;
}
}
 
int findsubtitlefile()
{ FILE *fr,*log;//fr=read g:\\list.txt,log=write to g:\\log.txt
char fn[128];//fn=file name
log=fopen("c:\\asf\\log.txt","a");
if(log==NULL)
printf ("\nCould not append g:\\log.txt in function findsubtitlefile");
fr=fopen("c:\\asf\\list.txt","r");
if(fr==NULL)
printf("\ncould not read g:\\list.txt");
fprintf(log,"\nwe have to search srt in following \"name-length:file-name\" pairs \n");
while ( fgets ( fn, 127, fr ) != NULL )
{ fprintf(log,"%d:%s\n",strlen(fn),fn);
if(check(fn))
{ fprintf(log,"found subtitle file : %s\n",strrev(fn));
sfnumber++;
}
}
fclose(fr);
fclose(log);
if(sfnumber>0)
return 1;
else
return 0;
}
void letuserdecide()
{ int i;
printf("\nPLEASE CHOOSE SUBTITLE FILE");
for(i=0;i<sfnumber;i++)
printf("\n%d)%s",i+1,sf[i]);
printf("\nEnter option:");
scanf("%d",&i);
strcpy(finalsf,sf[i-1]);
}
 
void main(int argc,char *argv[])
{ FILE *log,*action;
int i,j,len;
char dir[120],command[512];
clrscr();
log=fopen("c:\\asf\\log.txt","w");
if(log==NULL)
printf ("\nCould not open g:\\log.txt for writing ");
// fp=full path
for(i=1;i<argc;i++)
{
strcat(fp,argv[i]);
strcat(fp," ");//here sprintf will not work because we are appending to fp in each loop
}
fp[strlen(fp)-1]=0;
fprintf(log,"full path=%s\nnumber of words=%d",fp,argc-1);
//copying directory name to 'dir' variable
len=strlen(fp);
i=strlen(fp)-1;
while(fp[i]!='\\')
i=i-1;
for(j=0;j<i;j++)
dir[j]=fp[j];
dir[j]=0;
fprintf(log,"\ndirectory is %s",dir);
//copying file name to 'name' variable
for(j=0,i++;i<len;i++,j++)
name[j]=fp[i];
//printf("\nfile name:%s",name);
fprintf(log,"\nfile name : %s",name);
//executing 'dir' command to output all items in current folder to g:\list.txt
sprintf(command,"ls -1 \"%s\" > g:\\list.txt",dir);
system(command);
fprintf(log,"\nwe have executed : %s",command);
fclose(log);
command[0]=0;
//let us find the subtitle file
if (findsubtitlefile())
{ //run the file with subtitle
if(sfnumber>1)
letuserdecide();
else
strcpy(finalsf,sf[0]);
sprintf(command,"\nk -subfont-text-scale 3 -fs -vf screenshot,expand=0:-40:0:0 \"%s\" -sub \"%s\\%s\"",fp,dir,finalsf);
}
else
{ //run file without subtitle
sprintf(command,"\nk -fs \"%s\"",fp);
}
//printf("\nwe will run %s",command);
action=fopen("c:\\asf\\a.bat","w");
if(action==NULL)
printf("\nCould not open g:\\a.bat to write kovensky play command");
fputs(command,action);
fclose(action);
system("cmd /c g:\\a.bat");
//getchar(); while debugging to read output before exiting
}

$CmdLine will be useful to get file name passed

Edited by manit

Share this post


Link to post
Share on other sites
sleepydvdr

You didn't ask any questions, so I assume you are looking for some kind of starting point. Here's something to think about:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$fileCount = 0
$subtitleFile = FileFindFirstFile ("*.srt")

If $subtitleFile = 1 Then
    Dim $subtitleList[1]
    While 1
        $file = FileFindNextFile($subtitleFile)
        If @error Then
            ExitLoop
        Else
            ReDim $subtitleList[$fileCount + 1]
            $subtitleList[$fileCount] = $file
            $fileCount += 1
        EndIf
    WEnd

    FileClose($subtitleFile)
EndIf

If UBound($subtitleList) > 1 Then

    $Form1 = GUICreate("Select a subtitle", 284, 108)
    $Combo1 = GUICtrlCreateCombo("", 16, 32, 249, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
    For $i = 0 To UBound($subtitleList) - 1 Step 1
        GUICtrlSetData($Combo1, $subtitleList[$i])
    Next
    $Button1 = GUICtrlCreateButton("Load", 192, 64, 75, 25)
    $Label1 = GUICtrlCreateLabel("Choose A Subtitle:", 16, 8, 91, 17)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button1
                $subtitle = GUICtrlRead($Combo1)
                _RunYourCode()
        EndSwitch
    WEnd
Else
    $subtitle = $subtitleList[0]
    _RunYourCode()
EndIf

Func _RunYourCode()
    ; Insert your code to play the movie with the selected subtitle.
EndFunc

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
manit

sleepydvdr , you wrote the code so quickly.

(1) In _RunYourCode I want to run following command

k -subfont-text-scale 3 -fs -vf screenshot,expand=0:-40:0:0 <video_file> -sub <subtitle-file>

k.exe is a binary present in my system path

<video_file> is full path of video file that invoked my autoit program , so it should be $CmdLineRaw inside double quotes.

<subtitle-file> should be the file I selected in drop down list (ofcourse , with full path & inside double quotes)

I think I have to create a suitable string then use Run("string")

_RunYourCode can use $filecount to determine if video should be run with or without subtitle.

So , what should I write in Func _RunYourCode() ?

(2) Also , I get "error:variable used without being declared" if folder containing video file has no srt files.

I think $subtitleFile will be -1 if no srt file found .

Thank You.

Another thing , I noticed that functions in your code point to relevant autoit documentation.

Edited by manit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.