PDA

View Full Version : Get the current script filename


jcsston
12th December 2003, 04:52
Is it possible to get the filename of the current AVS script file inside a filter?
I want to make a Audio Normalizing filter that caches the the peak levels to an external file so that it only has to scan it once. :)

WarpEnterprises
14th December 2003, 22:23
Is seems that this is not exposed in the API.

mf
15th December 2003, 19:15
function GetScriptName() {
Try { NonExistantfiltername() }
Catch(err_msg) {
err_msg2 = MidStr(err_msg, 67)
filename = LeftStr(err_msg2, (FindStr(err_msg2, ", line")-1))
return filename
} }

Bidoche
15th December 2003, 19:48
Whaouh, mf saves the day !

jcsston
15th December 2003, 20:00
:D
I went ahead and made the filter but it takes the peak value file as an argument.
Normalize2 (http://webjory.tripod.com/avisynth/normalize2.htm)

Now with mf's function I can get similar results to what I wanted.

function GetScriptName() {
Try { NonExistantfiltername() }
Catch(err_msg) {
err_msg2 = MidStr(err_msg, 67)
filename = LeftStr(err_msg2, (FindStr(err_msg2, ", line")-1))
return filename
} }
...
Normalize2(GetScriptName()+".norm")

:)

mf
15th December 2003, 20:10
Glad I could be of help :).

stickboy
15th December 2003, 21:37
Originally posted by mf
function GetScriptName() {
Try { NonExistantfiltername() }
Catch(err_msg) {
err_msg2 = MidStr(err_msg, 67)
filename = LeftStr(err_msg2, (FindStr(err_msg2, ", line")-1))
return filename
} }That's sick. :)

But it won't work for the contrived case where the filename has ", line" in it. Here's a modified version (and that also isn't dependent on NonExistentFilterName):
function GetScriptName()
{
Try
{
assert(false)
}
Catch(err_msg)
{
err_msg = MidStr(err_msg, FindStr(err_msg, "(") + 1)
filename = LeftStr(err_msg, StrLen(err_msg) - FindStr(RevStr(err_msg), ","))
return filename
}
}

mf
15th December 2003, 22:17
Well, you know I like to write dirty code :D.

WarpEnterprises
16th December 2003, 21:00
you are VERY creative !

mf
16th December 2003, 21:49
Originally posted by WarpEnterprises
you are VERY creative !
Me, Pamel or stickboy?

WarpEnterprises
16th December 2003, 22:42
who is Pamel??

doesn't matter, it fits to all of you :)

Atamido
17th December 2003, 07:01
Originally posted by WarpEnterprises
who is Pamel?? Yo, did somebody call?

mf
17th December 2003, 10:00
Whoops! I meant jcsston. Both matroska monkeys :D.

Si
18th December 2003, 10:22
I'm a bit confused as usual :o

I understand the GetScriptName function (hats off to mf) but I don't understand what Normalise2 is doing with it and what is meant by caching so it only has to scan the file once :confused:

I'm sure its simple but the usage has got me stumped :o

regards
Simon

Bidoche
18th December 2003, 11:28
I guess it uses the script filename to create another one and save into it the audio peak value.
So if that second file exists, no need to scan anymore.