PDA

View Full Version : Big Challenge


tombot18
10-19-2007, 04:27 PM
OK, I'm new here I have a problem which I'll do my best to explain.
I figured that this would be quickest way to get the information I need.

Basically, I have some scripts exported from Windows Media ASF Indexer that look like this:

;Properties
Title:
Author:
Copyright:
Description:
Rating:
;Script Commands
start_script_table
00:00:02.0 TEXT SLIDE Slide23
00:01:29:2 TEXT SLIDE Slide24
end_script_table

Of course not many of them are this short, but I think you get the point, simple text, consistent formatting of timecode and slide numbers.

Now, I've been editing these by hand in order to conform them to the format required by our player, which is as follows:

;Properties
Title:
Author:
Copyright:
Description:
Rating:

;Markers
start_marker_table
00:00:00.0 1
00:01:27:2 2
end_marker_table

;Script Commands
start_script_table
00:00:01.0 TEXT SLIDE Slide1
00:01:28:2 TEXT SLIDE Slide2
end_script_table

As you can see, not only is the original duplicated and changed to markers but the slide numbers are changed (so that they all start sequentially from one) and the marker timings are offset by -1 second.

(This is because we split the code from a live broadcast into multiple files for posting as separate on-demand streams)

Ok, that's the explanation out of the way, now on to my main reason for me posting here.

This process is arduous at best, and as far as I see it could be made much more simple and efficient if I were to write a small applet which recognises the text and automatically generates the new script.

After asking around, the general consensus was that the easiest way to do this would be to build it using actionscript, especially as it is the only form of coding that I have any experience with.

First thing is, are they right? Is it actually possible, and if so, is it within my grasp, and how could I quickly learn the various bits of code I would need to build such a thing?

I look forward to someone getting back to me.

Noct
10-19-2007, 04:46 PM
Well, the conversion process would be relatively simple to script, but you realize that Flash doesn't natively export/save files.
So, you couldn't like, input a text file and have it spit out a new one...

You could input a text file and have it return the results to you in a textField within the applet or even email it to yourself, but without some outside architechture, you aren't going to be able to actually make changes to any documents using Flash...

tombot18
10-19-2007, 04:51 PM
Well, having it in a text field would be fine, how would I script it to make the changes in the first place though? That's more of the stumbling block for me.

(Also, thanks so much for replying!)

Noct
10-19-2007, 06:51 PM
Well, it would obviously need to be written more dynamically if you had different data sets then the ones you are showing, but I think this should get you started at least:

//on Button press:
this.processBtn.onRelease = function() {
var outPutTxt:TextField = this._parent.outpData_txt;
//Create Array from inputText field - split at line break
var inpArray:Array = this._parent.inpData_txt.text.split("\r");
//The first 5 lines display the same in the output:
//Clear the output field to add the first item + a line break
outPutTxt.text = inpArray[0]+"\r";
//Loop through the remaining items adding one at a time:
for (i=1; i<6; i++) {
outPutTxt.text += inpArray[i]+"\r";
}
//Add an extra line break:
outPutTxt.text += "\r";
//Add next three line you have shown as the output:
outPutTxt.text += ";Markers"+"\r";
outPutTxt.text += "start_marker_table"+"\r";
outPutTxt.text += "00:00:00.0 1"+"\r";
//Retrieve time code sets from input array (10th item)
//Skip the ":"s by calling charAt, and split the timecode up
var timeCode_s1:String = inpArray[9].charAt(0)+inpArray[9].charAt(1);
var timeCode_s2:String = inpArray[9].charAt(3)+inpArray[9].charAt(4);
var timeCode_s3:String = inpArray[9].charAt(6)+inpArray[9].charAt(7);
//perform equasion on results:
var editedTime1:String = editTimeCode(timeCode_s1, timeCode_s2, timeCode_s3);
function editTimeCode(digSet1:String, digSet2:String, digSet3:String):String {
//If the last set of digits is greater then 1
if (parseInt(digSet3)>1) {
//Subtract the 2
digSet3 = String(parseInt(digSet3)-2);
//Else its less then 1
} else {
//If the second set of digits is greater then 1:
if (parseInt(digSet2)>0) {
//Subtract 1 from this and 2 from the other:
digSet2 = String(parseInt(digSet2)-1);
//If the code 3 had a 1 in it, remove 1 from 60 seconds:
if (digSet3 == "01") {
digSet3 == "59";
//Else remove 2
} else {
digSet2 == "58";
}
}
}
return digSet1+":"+digSet2+":"+digSet3;
}
//Add new timecode to output:
outPutTxt.text += editedTime1+":2 2"+"\r";
//Continue adding the items you showed:
outPutTxt.text += "end_marker_table"+"\r";
//Add an extra line break:
outPutTxt.text += "\r";
//Continue adding the items you showed:
outPutTxt.text += inpArray[6]+"\r";
outPutTxt.text += inpArray[7]+"\r";
//
//Retrieve time code sets from input array (8th item)
//Skip the ":"s by calling charAt, and split the timecode up
var timeCode_s4:String = inpArray[8].charAt(0)+inpArray[8].charAt(1);
var timeCode_s5:String = inpArray[8].charAt(3)+inpArray[8].charAt(4);
var timeCode_s6:String = inpArray[8].charAt(6)+inpArray[8].charAt(7);
//perform equasion on second timecode:
var editedTime2:String = editTimeCode2(timeCode_s4, timeCode_s5, timeCode_s6);
function editTimeCode2(digSet1:String, digSet2:String, digSet3:String):String {
//If the last set of digits is greater then 1
if (parseInt(digSet3)>1) {
//Subtract the 1
digSet3 = String(parseInt(digSet3)-1);
} else {
//If the second set of digits is greater then 1:
if (parseInt(digSet2)>0) {
//Subtract 1 from this and 1 from the other:
digSet2 = String(parseInt(digSet2)-1);
//remove 1 from 60 seconds:
digSet3 == "59";
}
}
//If these numbers are less then 2 characters, add a zero in front
if (digSet2.length<2) {
digSet2 = "0"+digSet2;
}
if (digSet3.length<2) {
digSet3 = "0"+digSet3;
}
return digSet1+":"+digSet2+":"+digSet3;
}
//This set uses the same timecode as above
var editedTime3:String = editTimeCode2(timeCode_s1, timeCode_s2, timeCode_s3);
//Add new timecodes to output:
outPutTxt.text += editedTime2+".0 TEXT SLIDE Slide 1"+"\r";
outPutTxt.text += editedTime3+":2 TEXT SLIDE Slide 2"+"\r";
//Add The final line:
outPutTxt.text += inpArray[10];
};

If you look at the file you'll see I have it reading the data from an input field (I have it in there when it starts, but you could paste a new set in) and then outputting a processed version of it to a dynamic field. This is a bit more procedural and less OOP then I would normally do for something like this, but it should be easier to follow this way...

tombot18
10-20-2007, 11:25 PM
Well, I certainly wasn't expecting that!

Thanks so much, that's really something I can work with, amazing!

One more quick question (I'm really not so good at this):
How would I go about dynamically updating the number of lines, for instance one of the files I had to process looked like this:

;Properties
Title: V2Encoder2
Author:
Copyright:
Description:
Rating:
;Script Commands
start_script_table
00:00:03.6 TEXT SLIDE Slide2
00:03:49.1 TEXT SLIDE Slide3
00:04:39.1 TEXT SLIDE Slide4
00:05:49.1 TEXT SLIDE Slide5
00:05:57.6 TEXT SLIDE Slide6
00:06:26.1 TEXT SLIDE Slide7
00:07:03.6 TEXT SLIDE Slide8
00:07:44.1 TEXT SLIDE Slide9
00:08:54.1 TEXT SLIDE Slide10
00:10:29.1 TEXT SLIDE Slide11
00:11:19.6 TEXT SLIDE Slide12
00:12:04.1 TEXT SLIDE Slide13
00:12:24.1 TEXT SLIDE Slide14
00:13:09.1 TEXT SLIDE Slide15
00:13:23.1 TEXT SLIDE Slide16
00:14:19.1 TEXT SLIDE Slide17
00:15:23.6 TEXT SLIDE Slide18
00:18:09.6 TEXT SLIDE Slide19
00:20:29.5 TEXT SLIDE Slide20
00:22:25.0 TEXT SLIDE Slide21
00:23:35.0 TEXT SLIDE Slide22
00:23:49.0 TEXT SLIDE Slide24
00:24:25.5 TEXT SLIDE Slide23
00:25:45.0 TEXT SLIDE Slide24
00:27:00.0 TEXT SLIDE Slide25
00:27:39.0 TEXT SLIDE Slide26
00:28:11.5 TEXT SLIDE Slide27
00:29:29.5 TEXT SLIDE Slide28
00:31:39.5 TEXT SLIDE Slide29
00:33:34.5 TEXT SLIDE Slide30
00:35:10.0 TEXT SLIDE Slide31
00:52:30.5 TEXT SLIDE Slide32
00:55:00.0 TEXT SLIDE Slide33
00:57:34.5 TEXT SLIDE Slide34
00:59:15.0 TEXT SLIDE Slide35
00:59:37.0 TEXT SLIDE Slide36
00:59:42.0 TEXT SLIDE Slide37
00:59:46.5 TEXT SLIDE Slide38
01:00:35.5 TEXT SLIDE Slide39
01:01:30.5 TEXT SLIDE Slide40
01:02:01.5 TEXT SLIDE Slide41
01:03:40.0 TEXT SLIDE Slide42
01:04:12.5 TEXT SLIDE Slide43
01:05:36.0 TEXT SLIDE Slide44
01:06:50.5 TEXT SLIDE Slide45
01:07:31.5 TEXT SLIDE Slide46
01:09:32.5 TEXT SLIDE Slide48
01:09:47.5 TEXT SLIDE Slide449
01:10:01.0 TEXT SLIDE Slide50
01:10:08.0 TEXT SLIDE Slide51
01:10:12.5 TEXT SLIDE Slide52
01:11:05.0 TEXT SLIDE Slide53
01:11:09.0 TEXT SLIDE Slide54
01:15:00.5 TEXT SLIDE Slide55
01:15:05.0 TEXT SLIDE Slide56
01:18:36.7 TEXT SLIDE Slide57
01:18:39.7 TEXT SLIDE Slide58
01:18:44.2 TEXT SLIDE Slide59
01:19:20.7 TEXT SLIDE Slide60
01:19:39.7 TEXT SLIDE Slide61
01:19:50.7 TEXT SLIDE Slide62
01:20:08.7 TEXT SLIDE Slide63
01:20:14.2 TEXT SLIDE Slide64
01:26:47.9 TEXT SLIDE Slide65
01:27:26.9 TEXT SLIDE Slide66
01:27:46.4 TEXT SLIDE Slide67
01:28:43.4 TEXT SLIDE Slide68
01:28:58.4 TEXT SLIDE Slide69
01:44:05.3 TEXT SLIDE Slide70
01:45:41.8 TEXT SLIDE Slide71
01:45:52.3 TEXT SLIDE Slide72
01:48:31.3 TEXT SLIDE Slide73
01:49:21.3 TEXT SLIDE Slide74
01:52:42.3 TEXT SLIDE Slide75
01:54:22.3 TEXT SLIDE Slide76
01:55:34.3 TEXT SLIDE Slide77
01:57:01.3 TEXT SLIDE Slide78
01:58:16.3 TEXT SLIDE Slide79
02:01:06.8 TEXT SLIDE Slide80
02:02:43.3 TEXT SLIDE Slide81
02:06:12.8 TEXT SLIDE Slide82
02:09:22.3 TEXT SLIDE Slide83
02:10:33.8 TEXT SLIDE Slide84
02:11:18.3 TEXT SLIDE Slide85
02:25:17.9 TEXT SLIDE Slide86
02:27:17.4 TEXT SLIDE Slide87
02:27:32.9 TEXT SLIDE Slide88
02:28:32.4 TEXT SLIDE Slide89
02:29:03.4 TEXT SLIDE Slide90
02:30:06.9 TEXT SLIDE Slide91
02:32:16.4 TEXT SLIDE Slide92
02:35:06.9 TEXT SLIDE Slide93
02:36:51.9 TEXT SLIDE Slide94
02:39:29.4 TEXT SLIDE Slide95
02:42:17.9 TEXT SLIDE Slide96
02:44:18.4 TEXT SLIDE Slide97
02:46:44.9 TEXT SLIDE Slide98
02:47:23.9 TEXT SLIDE Slide99
02:49:38.4 TEXT SLIDE Slide100
02:51:59.4 TEXT SLIDE Slide101
02:53:59.9 TEXT SLIDE Slide102
02:54:49.9 TEXT SLIDE Slide103
02:55:13.4 TEXT SLIDE Slide104
02:55:30.9 TEXT SLIDE Slide105
02:56:54.9 TEXT SLIDE Slide106
02:57:26.4 TEXT SLIDE Slide107
02:57:51.4 TEXT SLIDE Slide108
02:58:14.4 TEXT SLIDE Slide109
02:58:30.9 TEXT SLIDE Slide110
02:58:39.9 TEXT SLIDE Slide111
02:59:11.4 TEXT SLIDE Slide112
02:59:30.5 TEXT SLIDE Slide113
02:59:36.6 TEXT SLIDE Slide114
02:59:49.6 TEXT SLIDE Slide115
02:59:54.6 TEXT SLIDE Slide116
03:00:06.1 TEXT SLIDE Slide117
03:00:13.1 TEXT SLIDE Slide118
03:01:15.1 TEXT SLIDE Slide119
03:01:25.1 TEXT SLIDE Slide120
03:01:50.1 TEXT SLIDE Slide121
03:07:04.6 TEXT SLIDE Slide122
end_script_table

As you can see, much longer than my original example, but again, some are longer, some are shorter... what would be the best way to alter this?

Sorry to keep asking, and thanks again, so much, for all your help!

Noct
10-22-2007, 03:46 PM
Well, this line is creating an array for each line of your input text:

//Create Array from inputText field - split at line break
var inpArray:Array = this._parent.inpData_txt.text.split("\r");

So, the length of that array could be used to determine how many time codes were given. Like, the one you have pasted above has 9 lines of text that aren't time codes. Supposing that is the standard, you could just take the length of the whole array minus the 9 lines that aren't timecodes:

var tCodes:Number = inpArray.length-9


If the number of other data items itself is not going to be constant then you could always just search for items with a timecode appearing in them with something like this:

var tcCount:Number = 0;
for (i=0; i<inpArray.length; i++) {
if (inpArray[i].indexOf("SLIDE") != -1) {
tcCount++;
}
}
trace(tcCount)

That would loop through the whole input array, and increment the counter each time it found a line that had the word "SLIDE" in it.

So then once you had that number of lines you could re-write the process to be a bit more dynamic and run the nested editTimeCode function as many times as it needs to before displaying the results.

tombot18
10-23-2007, 04:27 PM
Wow, thanks again so much for your help, just
-one- more thing, I can't seem to get it to do the right
thing with that second bit of code, and my usual
actionscript buddy is off work :S

I know it's a real pain, but is there any way you could
show me how to slot that in... if not don't worry, i'll just wait
for him to get back.

Next time i'm in NY, I owe you a beer!

tombot18
10-25-2007, 01:19 PM
Hi there people,
I'm really desperate to get this problem fixed and to be honest I'm completely lost, I would be really very grateful if someone could show me how to fix this so that dynamically knows how many lines of timecode to process.... is there anyone that can help with this?

Noct
10-25-2007, 03:10 PM
tombot18, no offense, but it's starting to sound like you have no intentions to learn actionscript, you just want someone to create this script for you, and that's really not what this forum is about man...

I will help you all day, but I would need to know what you are confused about, not just a generic "can someone help me" which comes across as, "can someone just write this script for me as I need it".

I can't just "slot it in" as you mentioned because all I typed out was a method of determining how many timecodes the user inputs. You would still have to actually do something with that number.

If you would like me to simply write it for you, I'm available on an hourly basis and I'd need a lot more information about the project and what the output requirements are, otherwise explain where you are getting confused and how I can help.
:)

tombot18
10-25-2007, 03:44 PM
Noct - sorry if it came across like that, I can see how it would, sorry, I'm just getting frustrated with myself and how much i've forgotten about actionscript!

:S

I wish I had more time to devote to this, as it's something I really do enjoy, I just feel like I got in a bit over my depth trying to make this tool!

Basically, I'm assuming that this section:

var timeCode_s1:String = inpArray[9].charAt(0)+inpArray[9].charAt(1);
var timeCode_s2:String = inpArray[9].charAt(3)+inpArray[9].charAt(4);
var timeCode_s3:String = inpArray[9].charAt(6)+inpArray[9].charAt(7);

is what I need to change, we've generated a number of lines, as you've said,
now i need to tell flash to process that number of lines... which is where I'm stuck, I've got my old actionscript book here, so if you could just give me a general pointer, i'm sure i'll be able to muddle my way through.

Sorry to go on, I honestly wasn't expecting anyone to write so much as a line of code, let alone the whole lot that you did, so thank you SO much!

-t

Noct
10-26-2007, 03:34 PM
Ok, I sincerely doubt this is flawless as I didn't really test it, but it appears to be functioning...

It runs the loop I typed out above to count the number of timecodes and then loops that number to create the output. Again, this is still not a perfect applet, I never went about coding the changes you would need if one timecode is smaller then the amount you wish to remove from it. As in, if you have 01:01, you would need to write a function to make that 00:59 if you removed two seconds from it, I believe right now it owuld just make it 00:00.

Anyways, this is the loop in action:
It creates three new timecode sections by taking the first timecodes position in the array (8) and adding one to that until it hits the total we derived from the other loop. The incrementing numbers in the text are derived from just adding 1 (the first timecodes number) to the current value of the loop, and then the final closing line is taken by getting the length of the array -1, which gives you the last pplace in the array:

//Run loop to set other timecodes based on number found above:
for (tC:Number = 1;tC<tcCount;tC++){;
var timeCodeX1:String = inpArray[8+tC].charAt(0)+inpArray[8+tC].charAt(1);
var timeCodeX2:String = inpArray[8+tC].charAt(3)+inpArray[8+tC].charAt(4);
var timeCodeX3:String = inpArray[8+tC].charAt(6)+inpArray[8+tC].charAt(7);
var editedTimeX:String = editTimeCode2(timeCodeX1, timeCodeX2, timeCodeX3);
outPutTxt.text += editedTimeX+":"+(1+tC)+" TEXT SLIDE Slide "+(1+tC)+"\r";
}
//Add The final line:
outPutTxt.text += inpArray[inpArray.length-1];


This is it placed in the script:

//on Button press:
this.processBtn.onRelease = function() {
var outPutTxt:TextField = this._parent.outpData_txt;
//Create Array from inputText field - split at line break
var inpArray:Array = this._parent.inpData_txt.text.split("\r");
//Count number of timeCodes in the file:
var tcCount:Number = 0;
for (i=0; i<inpArray.length; i++) {
if (inpArray[i].indexOf("SLIDE") != -1) {
tcCount++;
}
}
//
//The first 5 lines display the same in the output:
//Clear the output field to add the first item + a line break
outPutTxt.text = inpArray[0]+"\r";
//Loop through the remaining items adding one at a time:
for (i=1; i<6; i++) {
outPutTxt.text += inpArray[i]+"\r";
}
//Add an extra line break:
outPutTxt.text += "\r";
//Add next three line you have shown as the output:
outPutTxt.text += ";Markers"+"\r";
outPutTxt.text += "start_marker_table"+"\r";
outPutTxt.text += "00:00:00.0 1"+"\r";
//Retrieve time code sets from input array (10th item)
//Skip the ":"s by calling charAt, and split the timecode up
var timeCode_s1:String = inpArray[9].charAt(0)+inpArray[9].charAt(1);
var timeCode_s2:String = inpArray[9].charAt(3)+inpArray[9].charAt(4);
var timeCode_s3:String = inpArray[9].charAt(6)+inpArray[9].charAt(7);
//perform equasion on results:
var editedTime1:String = editTimeCode(timeCode_s1, timeCode_s2, timeCode_s3);
function editTimeCode(digSet1:String, digSet2:String, digSet3:String):String {
//If the last set of digits is greater then 1
if (parseInt(digSet3)>1) {
//Subtract the 2
digSet3 = String(parseInt(digSet3)-2);
//Else its less then 1
} else {
//If the second set of digits is greater then 1:
if (parseInt(digSet2)>0) {
//Subtract 1 from this and 2 from the other:
digSet2 = String(parseInt(digSet2)-1);
//If the code 3 had a 1 in it, remove 1 from 60 seconds:
if (digSet3 == "01") {
digSet3 == "59";
//Else remove 2
} else {
digSet2 == "58";
}
}
}
return digSet1+":"+digSet2+":"+digSet3;
}
//Add new timecode to output:
outPutTxt.text += editedTime1+":2 2"+"\r";
//Continue adding the items you showed:
outPutTxt.text += "end_marker_table"+"\r";
//Add an extra line break:
outPutTxt.text += "\r";
//Continue adding the items you showed:
outPutTxt.text += inpArray[6]+"\r";
outPutTxt.text += inpArray[7]+"\r";
//
//Retrieve time code sets from input array (8th item)
//Skip the ":"s by calling charAt, and split the timecode up
var timeCode_s4:String = inpArray[8].charAt(0)+inpArray[8].charAt(1);
var timeCode_s5:String = inpArray[8].charAt(3)+inpArray[8].charAt(4);
var timeCode_s6:String = inpArray[8].charAt(6)+inpArray[8].charAt(7);
//perform equasion on second timecode:
var editedTime2:String = editTimeCode2(timeCode_s4, timeCode_s5, timeCode_s6);
function editTimeCode2(digSet1:String, digSet2:String, digSet3:String):String {
//If the last set of digits is greater then 1
if (parseInt(digSet3)>1) {
//Subtract the 1
digSet3 = String(parseInt(digSet3)-1);
} else {
//If the second set of digits is greater then 1:
if (parseInt(digSet2)>0) {
//Subtract 1 from this and 1 from the other:
digSet2 = String(parseInt(digSet2)-1);
//remove 1 from 60 seconds:
digSet3 == "59";
}
}
//If these numbers are less then 2 characters, add a zero in front
if (digSet2.length<2) {
digSet2 = "0"+digSet2;
}
if (digSet3.length<2) {
digSet3 = "0"+digSet3;
}
return digSet1+":"+digSet2+":"+digSet3;
}
//Add new timecodes to output:
outPutTxt.text += editedTime2+".0 TEXT SLIDE Slide 1"+"\r";
//
//Run loop to set other timecodes based on number found above:
for (tC:Number = 1;tC<tcCount;tC++){;
var timeCodeX1:String = inpArray[8+tC].charAt(0)+inpArray[8+tC].charAt(1);
var timeCodeX2:String = inpArray[8+tC].charAt(3)+inpArray[8+tC].charAt(4);
var timeCodeX3:String = inpArray[8+tC].charAt(6)+inpArray[8+tC].charAt(7);
var editedTimeX:String = editTimeCode2(timeCodeX1, timeCodeX2, timeCodeX3);
outPutTxt.text += editedTimeX+":"+(1+tC)+" TEXT SLIDE Slide "+(1+tC)+"\r";
}
//Add The final line:
outPutTxt.text += inpArray[inpArray.length-1];
};

tombot18
10-29-2007, 12:54 AM
Thanks so so much for all your help,
after a few hours slaving over some hot actionscript, I finally
tweaked it enough to make it do exactly what I wanted,
couldn't have done it without you mate, I owe you one, seriously!