Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
23rd November 2011, 01:01 | #21 | Link | |
Registered User
Join Date: Aug 2008
Posts: 233
|
Quote:
How about others here: do you have a preference as to whether the attempt at 2.6's native ScriptName() is tried in the .avs or the function? |
|
23rd November 2011, 11:19 | #22 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
- it uses one try/catch instead of two; - it does not depend on '_' being previously undefined (and so can be used more than once in a script); - it makes the function more self-contained - its job is then simply to extract the file name from a specified error message, so it could in principle be used in other contexts. |
|
23rd November 2011, 17:06 | #23 | Link | |
Registered User
Join Date: Aug 2008
Posts: 233
|
Quote:
Code:
# in .avs script Try {_ = ScriptName()} Catch(_) {_=_ScriptName(_)} AVSfilename = _ # in .avsi file function _ScriptName(string _) { _ = MidStr(_, FindStr(_, "(") + 1) LeftStr(_, StrLen(_) - FindStr(RevStr(_), ",")) } |
|
6th September 2012, 21:21 | #24 | Link |
Registered User
Join Date: Dec 2009
Posts: 6
|
if you put theses function in the top of your avs file you will get the same effect of ScriptName(), and ScriptDir() in version 2.58
Code:
Function ScriptName(){try{_}catch(err_msg){return Chr(34)+RevStr(MidStr(RevStr(MidStr(err_msg,Findstr(err_msg,"(")+1)),FindStr(RevStr(MidStr(err_msg,Findstr(err_msg,"("))),",")+1))+Chr(34)}} Function ScriptFile(){try{_}catch(err_msg){return Chr(34)+MidStr(RevStr(MidStr(RevStr(MidStr(err_msg,Findstr(err_msg,"(")+1)),FindStr(RevStr(MidStr(err_msg,Findstr(err_msg,"("))),",")+1)),StrLen(RevStr(MidStr(RevStr(MidStr(err_msg,Findstr(err_msg,"(")+1)),FindStr(RevStr(MidStr(err_msg,Findstr(err_msg,"("))),",")+1)))-FindStr(MidStr(RevStr(MidStr(err_msg,Findstr(err_msg,"(")+1)),FindStr(RevStr(MidStr(err_msg,Findstr(err_msg,"("))),",")+1),"\")+2)+Chr(34)}} Function ScriptDir(){try{_}catch(err_msg){return Chr(34)+RevStr(MidStr(MidStr(RevStr(MidStr(err_msg,Findstr(err_msg,"(")+1)),FindStr(RevStr(MidStr(err_msg,Findstr(err_msg,"("))),",")+1),FindStr(MidStr(RevStr(MidStr(err_msg,Findstr(err_msg,"(")+1)),FindStr(RevStr(MidStr(err_msg,Findstr(err_msg,"("))),",")+1),"\")))+Chr(34)}} |
6th September 2012, 22:04 | #25 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
You need to remove the CHR(34)'s
EDIT: They are already strings, it's good to enclose in quotes before you give a filename to eg a DOS command, but not before eg concatenating file name node to a directory, you would need to remove the quotes, concatenate and then put them back again, not good. EDIT: Name changes might be good too, eg ScriptDir25 or whatever. EDIT: this might be handy, Code:
ver = VersionNumber() # Float, Implemented v2.07
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 13th September 2012 at 23:04. |
6th September 2012, 23:37 | #26 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Thought it might be an idea to point out somewhere in these simulated ScriptName etc threads that
SMPlayer (built on MPlayer)) returns returns paths with a '/' separator instead of DOS '\' causing the simulated functions to fail, 2.6 functions cope just fine. EDIT: Perhaps it dont, see next post.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 13th September 2012 at 23:04. |
7th September 2012, 00:13 | #27 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Correction on previous post, v2.6 may not cope just fine when called via eg smplayer with Unix style '/' path separators.
Code:
# 2.6, Windows Media Player 2 Scriptname= C:\z\26.avs ScriptDir= C:\z\ Scriptfile= 26.avs simulated scriptdir= C:\z\ # 2.6 smplayer Scriptname= C:/z/26.avs ScriptDir= C:\z\ Scriptfile= 26.avs simulated scriptdir= C:/z/26.avs, line 10)
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 8th September 2012 at 04:49. |
7th September 2012, 23:17 | #28 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Code:
# _GetWorkingDir(), Get Current Working Directory as used by Avisynth for easy importing of scripts:- By StainlessS # Unaffected by problems suffered by either 2.6a3 Script??? functions or synthetic versions, eg AVSPMod (null paths) # or smplayer (unix style slash). # Can live anywhere, unaffected by location of the function, can avsi autoload or import. # Any script using "SetWorkingDir()" will of course change the return value, but assuming working dir not changed, # then should return the location of your main AVS script. May have advantage over eg ScriptDir as can deliberately # use SetWorkingDir to something other than the main script directory. Function _GetWorkingDir(){Try{Import("?\")}Catch(_){s=FindStr(_,Chr(34))_=MidStr(_,s+1,FindStr(_,"?")-s-1)}_} Function GetFullPathName(String Path,String n) { # Convert relative path name to full path name. By StainlessS # If n (path or filename) starts with eg "C:" or "\\" then returns n. # Otherwise, appends n to the Path arg ("" defaults Current WorkingDir) and returns the result. # Result may be either a filename or directory converted from relative to explicit, dependant upon n. n=StrReplace(n,"/","\")(FindStr(n,":")!=2 && FindStr(n,"\\") != 1)? Eval(""" Path=(Path=="")?_GetWorkingDir():StrReplace(Path,"/","\") Path=(FindStr(RevStr(Path),"\")==1)?Path:Path+"\" n=(FindStr(n,"\")==1)?MidStr(n,2):n n=Path+n"""): NOP n } Function StrReplace(string s,string find,string replace) # Repeated, string replacements # Original:- http://forum.doom9.org/showthread.php?p=1540504#post1540504 By Vampiredom, Gavino, IanB #{i=s.FindStr(find)return(i==0?s: s.LeftStr(i-1)+replace+s.MidStr(Strlen(find)+i).StrReplace(find,replace))} # Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:- {i=s.FindStr(find) return(i==0?s:RT_StrAddStr(s.LeftStr(i-1),replace,s.MidStr(Strlen(find)+i).StrReplace(find,replace)))} Function StrReplaceDeep(string s,string find,string replace) # DEEP Repeated, string replacements # When replacing eg pairs of SPACE characters by single SPACE, StrReplace can leave some pairs non replaced. # Assumes that you want to rescan where replaced string could constitute part of a new find substring, # Length of replace must be shorter than length of find, else will call StrReplace instead. # Based On:- http://forum.doom9.org/showthread.php?p=1540504#post1540504 By Vampiredom, Gavino, IanB # {i=s.FindStr(find)return i==0?s:s.LeftStr(i-1)+( strlen(replace)<strlen(find)? \ # StrReplaceDeep(replace+s.MidStr(Strlen(find)+i),find,replace) : replace+StrReplace(s.MidStr(Strlen(find)+i),find,replace))} # Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:- {i=s.FindStr(find)return i==0?s:RT_StrAddStr(s.LeftStr(i-1),( strlen(replace)<strlen(find)? \ StrReplaceDeep(RT_StrAddStr(replace,s.MidStr(Strlen(find)+i)),find,replace) : \ RT_StrAddStr(replace,StrReplace(s.MidStr(Strlen(find)+i),find,replace))))}
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 29th December 2012 at 02:17. |
29th September 2012, 15:08 | #29 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
@all,
after mf/stickboy's help, I made myself an .avs file template in 2009. I can create this template by using shortcuts in various file commanders, or dragging a video file onto a vbs icon, or using windows' "new" context menu command ... In my case, the template contains the try ... function, but I gave that function the name Me(). Thus: Code:
function Me() { 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), ",") - 4) return filename }} Code:
Show(Me+"") #object oriented people say: Me.Show Show() is another function that I put together over the years. It checks for existence various extensions to Me, so it can work the same, whether Me is the basename of an .avi, a .mp4, a .mpg, a .flv ... and it uses totally different source filters, depending on the found extension, of course. It automatically Audiodub()s two sources for demuxed media etc. Show() also automatically splices up to about 20 media files together. I.e. the script 01+02.avs will find the sources 01.avi and 02.avi, and present them as one. And I made Show() also parse the string Me not only for the file name, but in fact that string can contain AviSynth commands. I decided to separate the part of the Me string that comes in front of the first pair of semicolons, and to use the rest of the script name as space that is executed by Eval(): Code:
pos = findstr(name, ";;") args = pos > 0 ? MidStr(name, pos+2) : "" name = pos > 0 ? LeftStr(name, pos-1) : name ... GEval( Replace( Replace( args, ";;", chr(13) ), "''", chr(34) ) ) The reason for adding an empty string +"" to Me for Show() is, of course, that I can also add script commands to a file that is open in the editor, instead of changing the file name in this case. Why am I writing all this in the forum? First, because it is one possible answer on how to modify the script behaviour easily, without opening an editor - by a different variable definition in the name of two scripts (e.g: two template files myfile;;preview=true.avs and myfile;;preview=false.avs provide the variable preview inside your script, so it can react on it. Show() reacts on a set of variables I need often. Second, to point out the importance of having the base name, in contrast to the complete file name, of the .avs script. Of course, that can easily be derived from ScriptName. But that again needs one user function to be written (many of us will have to do so, or one does it and many copy it), so it would be less effort in total - and reasonable - if AviSynth provided ScriptBaseName right away. Last edited by martin53; 29th September 2012 at 16:48. |
15th October 2012, 22:42 | #30 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Problem in StrReplace() script function: 2 posts earlier, and here:
http://forum.doom9.org/showthread.ph...04#post1540504 Code:
Q="[10] 9 -0.13 0.16 0.004 0.99927" RT_Debug("Source_string ='",Q+"'") x=StrReplace(Q," "," ") # Repeated replace pairs of SPACE's with single SPACE, ie SPACE compact. RT_Debug("StrReplace ='",x+"'") y=StrReplaceDeep(Q," "," ") # Repeated replace pairs of SPACE's with single SPACE, ie SPACE compact. RT_Debug("StrReplaceDeep='",y+"'") return colorbars() Function StrReplace(string s,string find,string replace) # Repeated, string replacements # Original:- http://forum.doom9.org/showthread.php?p=1540504#post1540504 By Vampiredom, Gavino, IanB #{i=s.FindStr(find)return(i==0?s: s.LeftStr(i-1)+replace+s.MidStr(Strlen(find)+i).StrReplace(find,replace))} # Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:- {i=s.FindStr(find) return(i==0?s:RT_StrAddStr(s.LeftStr(i-1),replace,s.MidStr(Strlen(find)+i).StrReplace(find,replace)))} Function StrReplaceDeep(string s,string find,string replace) # DEEP Repeated, string replacements # When replacing eg pairs of SPACE characters by single SPACE, StrReplace can leave some pairs non replaced. # Assumes that you want to rescan where replaced string could constitute part of a new find substring, # Length of replace must be shorter than length of find, else will call StrReplace instead. # Based On:- http://forum.doom9.org/showthread.php?p=1540504#post1540504 By Vampiredom, Gavino, IanB # {i=s.FindStr(find)return i==0?s:s.LeftStr(i-1)+( strlen(replace)<strlen(find)? \ # StrReplaceDeep(replace+s.MidStr(Strlen(find)+i),find,replace) : replace+StrReplace(s.MidStr(Strlen(find)+i),find,replace))} # Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:- {i=s.FindStr(find)return i==0?s:RT_StrAddStr(s.LeftStr(i-1),( strlen(replace)<strlen(find)? \ StrReplaceDeep(RT_StrAddStr(replace,s.MidStr(Strlen(find)+i)),find,replace) : \ RT_StrAddStr(replace,StrReplace(s.MidStr(Strlen(find)+i),find,replace))))} Code:
00000006 18.30790710 [2872] RT_Debug: Source_string =' [10] 9 -0.13 0.16 0.004 0.99927' 00000007 18.32215691 [2872] RT_Debug: StrReplace =' [10] 9 -0.13 0.16 0.004 0.99927' 00000008 18.34622955 [2872] RT_Debug: StrReplaceDeep=' [10] 9 -0.13 0.16 0.004 0.99927' EDIT: Have edited to implement as a new separate function, StrReplaceDeep (alternative name suggestions ?).
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 29th December 2012 at 02:16. |
2nd December 2012, 22:24 | #32 | Link |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
And what error might that be? What does it say?
__________________
Roelofs Coaching |
3rd December 2012, 16:48 | #33 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
And also, from whence did you obtain Aug 2012 executable.
(ScriptName is builtin to 2.6) EDIT: Although it will (I think) be using script version instead, if supplied.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 3rd December 2012 at 17:10. |
3rd December 2012, 18:54 | #34 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
Yep, sorry. I really forgot to be more specific.
Version.Subtitle(foo) says I don't know what "foo" means as expected. Version.Subtitle(ScriptName) says Script error: Invalid Arguments to function "Subtitle" Version.Subtitle(ScriptName()) says the same, also Version.Subtitle(ScriptDir), Version.Subtitle(Scriptfile) with and without additional function brackets. Version.Subtitle("<"+string(Scriptname)+">") produces the version clip with <> subtitle. assert(false,IsString(Scriptname)?"true":"false") returns false, likewise IsBool, IsClip, IsFloat, IsInt and Defined. While assert(false,IsString(foo)?"true":"false") returns I don't know... ScriptName seems to be existent but of no type somehow. I cannot remember where I downloaded the package from. Its file name is avisynth_2.60MTalpha_SEt_120828. The dll properties reveal version 2.6.0.3, 1.65MB from 08/28/2012 16:45 |
4th December 2012, 10:59 | #35 | Link |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
Here it works.
Code:
Version.Subtitle(ScriptName) Don't remember where I got this from, but it is an MT-version. It's still in my dowload-archive as a 7z-file. If you want you can download it at: http://roelofs-coaching.nl/downloads/avisynth.7z
__________________
Roelofs Coaching |
4th December 2012, 11:16 | #36 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Judging from the date, that is the previous version of SEt's 2.60 MT build, while martin53 appears to be using the latest one.
Looks like a bug has been introduced in the latest version - I don't know if SEt reads all the threads here, so I suggest you report it on the 2.60 MT thread. |
4th December 2012, 16:25 | #37 | Link |
Registered User
Join Date: Dec 2011
Posts: 192
|
So the ScriptName function you're using is the included in AviSynth 2.6 or one of the script functions posted in this thread? If it's the former your problem must be that the program you're using to load the script doesn't support the v2.6 interface.
There's two ways to load an AviSynth script, using the VFW interface and loading AviSynth directly as a library and then calling env->Invoke + Eval. The ScriptName, ScriptDir and ScriptFile functions just return the string saved in a global variable of the same name that is set by AviSynth when using the VFW approach. On the second case the variables are still declared by AviSynth when creating the environment but as the script file is not opened by AviSynth itself they are left uninitialized. This is called in the AviSynth language a variable of type void. Void variables can't be created by scripting, I figure that that's why there isn't a IsVoid function. So the caller application is responsible for setting those variables before creating the clip. I don't know how many programs currently do this. AvsPmod only started doing it in the recent 2.4.0 version. Edit:there seems to be a mismatch between the AviSynth source code files and the wiki, as the later refers to not declared variables also as void. Last edited by vdcrim; 4th December 2012 at 16:53. |
4th December 2012, 18:06 | #38 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
vdcrim,
thanks for the helpful info. I was using the included, not a script function, and I was using AvsPmod 2.3.0 The reason I appreciate the builtin function is that you cannot use script functions from included .avsi files - they return the name of that script instead of the calling one. So when you provide a filter script to others that needs to write files and you want to prevent collisions if the user opens more than one clip at a time... you need something unique, and the calling script name is good for that. I verified that indeed opening the same script in VDub shows the string correctly. However, between VDub (1.10.1 portable) and AvsPmod (2.4.0), there is an annoying difference: in VDub, ScriptName shows the filename with path, while in AvsPmod, it shows only the filename without path. In VDub, ScriptFile shows only the filename without path, while in AvsPmod, it shows the complete filename with path. Now which one is intended and which is wrong? The terms 'name' and 'file' are not very unmistakable. Edit: according to the prior usage of the function names in this thread, AvsPmod is wrong. Solution is in pyavs.py lines 126/127, but I cannot build AvsPmod. I kindly ask the AviSynth developer team to please clarify the intention of the variable names and initiate the solution. Should I help to forward the issue somehow? Edit: posted the issue in the AvsPmod thread Last edited by martin53; 4th December 2012 at 18:34. |
4th December 2012, 18:14 | #39 | Link | |||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
It's the Import() function (not the VfW interface per se) that sets the global variables, so ScriptName() should still work with this approach. AvsP[Mod] is different as it already has the text in a buffer, so uses Eval instead of Import. Quote:
Quote:
|
|||
4th December 2012, 18:28 | #40 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
ScriptDir and ScriptFile are the full path of the containing folder, and the basic filename part, respectively. See this post by IanB. |
|
|
|