mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
hey guys i have a script to keep a database of tv shows
and which genres they have. but im having some problems
i am a novice mirc scripter to i have no clue how to make it look cleaner i would really appreciate if someone could clean up my code.
also the $read function doesnt seem to work
so if a tv shows episode is defined and written to tvlog.txt
and it catches it again then it will notice me again instead of disregarding it heres the code :

Code:
ON 1: TEXT:*:# {
  if ($nick isin %TESTNICK) {
    set %catchnick $nick
    set %catchmsg $strip($1-)
    set %source TEST

    set %TEST.tvshow1 trigger1
    set %TEST.tvshow2 trigger2
    set %TEST.tvshow3 trigger3

    ;[New TV]
    if ($eval(% $+ %source $+ .tvshow1,2) isin %catchmsg) && ($eval(% $+ %source $+ .tvshow2,2) isin %catchmsg) {
      if ($eval(% $+ %source $+ .tvshow3,2) isin %catchmsg) { 
        if ($read($shortfn($mircdirTXT\Dupes\tvlog.txt),w,$getstring(%catchmsg)) == $null) {
          if (XviD isin $getstring(%catchmsg)) || (divx isin $getstring(%catchmsg)) {
            set %tvshow $getstring(%catchmsg)
            if ($read($shortfn($mircdirTXT\TVCheck\us.scripted.txt),w,$allcut(%tvshow))) || ($us.scripted.hash.match(%tvshow)) {
              if (HDTV isin %tvshow) || (HD.XviD isin %tvshow) {
                if (HR. isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.HR.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                elseif (720p isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.720p.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              }             
              elseif (PDTV isin %tvshow) { 
                if (HR. isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.HR.PDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.PDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ <  }
              }
              elseif (DSR isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.DSR.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              elseif (DVDRip isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.DVDRiP.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.Non.Digital.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
            }
            if ($read($shortfn($mircdirTXT\TVCheck\us.reality.txt),w,$allcut(%tvshow))) || ($us.reality.hash.match(%tvshow)) {
              if (HDTV isin %tvshow) || (HD.XviD isin %tvshow) {
                if (HR. isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.HR.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                elseif (720p isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.720p.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              }             
              elseif (PDTV isin %tvshow) { 
                if (HR. isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.HR.PDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.PDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              }
              elseif (DSR isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.DSR.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              elseif (DVDRip isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.DVDRiP.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Reality.Non.Digital.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
            }
          }
        }
      }
    }

    unset %catchnick
    unset %catchmsg
  }
  else {
    halt
  }
}



functions used:

Code:
alias getstring return $regml(getstring,$regex(getstring,$1-,/([^\s\/]+?([._])(?:\S+?\2)+\S+?-[^\/\s]+)/))
alias echoall { scid -a _echoall $1- }
alias _echoall { var %i = 1 | while (%i <= $window(*,0)) { var %w = $window(*,%i) | if (%w == status window) { echo 9 -bflrst $1- } | elseif (@* !iswm %w) { echo 9 -bflrt %w $1- } | inc %i } }
alias maycut return $regex($1-,/\.(?:S\d+E\d+|\d+x\d+)\.|\.\d\d(\d\d)?\.\d\d\.\d\d\./)
alias allcut {
  var %a = $fixstr($1-)
  if ($maycut(%a)) { var %tmp = $regsub(%a,/\.S\d+E\d+\..+|\.\d\d(\d\d)?\.\d\d\.\d\d\.\S+/,,%a) | return %a }
  return $1-
}
alias scut {
  var %a = $fixstr($1-)
  if ($maycut(%a)) { var %tmp = $regsub(%a,/(?<=\.S\d\d).+/,,%a)) | return %a }
  return $1-
}
alias ecut {
  var %a = $fixstr($1-)
  if ($maycut(%a)) { var %tmp = $regsub(%a,/(?<=\.S\d\dE\d\d).+/,,%a)) | return %a }
  return $1-
}
alias fixstr {
  if ($regex(fixstr,$1,/(.+?)(\d+?)x(\d\d.+)/)) {
    return $replace($+($regml(fixstr,1),S,$base($regml(fixstr,2),10,10,2),E,$regml(fixstr,3)),_,.) 
  }
  if ($regex(fixstr,$1,/_\d\d(\d\d)?_\d\d_\d\d_/)) return $replace($1,_,.)
  return $1
}



hope someone has some time to look through it

/bwuser

Last edited by bwuser; 12/07/08 03:17 PM.
Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
the $read command seems to fail fully is there a typo in there
and also i see alot of people using iswm instead of isin
what is the main difference?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Regarding the $read, the only thing that I can see as a possibility is that your usage of $shortfn might be making the $read look for an incorrect file. Try your code without the $shortfn in the $read and the /write lines.

As to the difference between iswm and isin, sorry, but I'm not sure of the main difference myself.

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
so my code is as clean as it can be?
and i tried without $shortfn still no go

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
It's not as clean as it can be. Use aliases to minimize duplication of code. You're repeating yourself way too much.

Basically, if you use any command with the same (or similar) parameters more than once, it should be made an alias. Also, if you use any string literal more than once, it should be put in a variable or identifier.

For example, I see "$shortfn(hardcodedpath)" way too many times in your script. What happens if you change the filename in the future? You're going to get a headache, is what. Throw it in an identifier and use that. If you change the literal the identifier represents, you only need to do it in one place.

alias myfilename { return $qt(C:\path\to\dupefile.txt) }
write $myfilename ....

Finally, this is an efficiency thing, but be careful how many times you call $read on a file.. it's relatively slow. If you're $read'ing that many times, consider using /filter to pull all your data out of the file and then mess with it in memory. /help /filter. From a glance at your script it looks like what you want anyway, since /filter is a great way to match dupes without looping or $read's


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
"isin" is basically doing a wildcard search for "*word*" or "*word1 word2*" while "iswm" is a wildcard match that lets you be more precise, by using the "?" wildcard or having wildcards only at the front, such as the way the above code uses iswm to look for @* - windows that begin with "@". Your lack of response is probably due to the regex code, which i confess to not understanding well at all.

You say the read fails, it would help to see an error message to get a clue on why the read fails. In debugging code, I find it helps to insert an echo message right above the $read code, so you can get a visual example of what you're trying to read or write. Make sure to not have any commas/parenthesis/etc attached to $identifiers so you can see what those values are.

For example, if you think this read is failing:

$read($shortfn($mircdirTXT\TVCheck\us.scripted.txt),w,$allcut(%tvshow))

then insert a line above it:

echo -s DEBUG $script $scriptline read( $shortfn( $mircdirTXT\TVCheck\us.scripted.txt ) , w , $allcut( %tvshow) )

Note that i purposely removed the $ from read, because i want to see what the read is looking for, instead of seeing what the read is fetching. The $script and $scriptline is very important, as it helps verify which of your debug messages is showing, but more importantly makes it easier to remove later when you see stray debug messages. If the code executes too often, you might wish to "aline" it to a @custom_window.

You might also look at mirc-help to see if you want any more switches besides the "w". For example, the 'n' switch keeps a line containing "$version" from returning 6.32 or whatever your version number is. If the 1st line of the file can be a number that's NOT supposed to be the number of lines in your file, you want to use the "t" switch to keep the TV show 24 from being used as if it's the number of lines in your file. Note that if line#1 also contains normal text then this wouldn't be an issue now, but is safe to use "t" so that someone looking at the code knows what kind of .txt you have.

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
ok lets see i will add your stuff to my code now
and will post outcome asap

p.s. there is no way to make my code shorter etc?

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
DEBUG F:\Utils\mIRC-R\X\Universal\script4 32 read( F:\Utils\mIRC-R\TXT\Dupes\tvlog.txt , w , A.Shot.At.Test.With.Tila.Tequila.S02E12.DSR.XviD-OMiCRON )

is what the output gives
this is to debug the first $read i have reading tvlog.txt
in this file 'A.Shot.At.Test.With.Tila.Tequila.S02E12.DSR.XviD-OMiCRON' also gets added, nonetheless when it sights it again
it does run the same action again even though my script should halt if it already processed the exact entry

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
If you try his suggestion of using aliases, you'll be amazed how much clutter you thin out. Another example of repeated text he said to consolidate to an alias is:

/echoall $me >>> New°>> US.Reality.DVDRiP.XviD->> %tvshow First Sighted on >> $+ %source $+ < }

It looks like those are all identical except for the section right after "US.Reality.", so make an alias for it-

alias first.seen {
/echoall $me >>> New°>> US.Reality. $+ $1 $+ .XviD->> %tvshow First Sighted on >> $+ %source $+ < }
}

That you would call instead with: $first.seen(DVDRiP)

As for shortening your code, it looks to me like all your if/else/elseif's are sections of code doing the same thing, except for changing 1 portion of the message string. If this is correct, you can simplify by using the if/else/else to set the value of a variable, then have only 1 snippet doing the read/writes, and substituting the variable where needed within that shared section.

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
Quote:

As for shortening your code, it looks to me like all your if/else/elseif's are sections of code doing the same thing, except for changing 1 portion of the message string. If this is correct, you can simplify by using the if/else/else to set the value of a variable, then have only 1 snippet doing the read/writes, and substituting the variable where needed within that shared section.


im not sure what you mean there could you give me an example in code please?

also the outcome from the debug i posted earlier might have crossed with you new reply


Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
great got the $read now working
and also the $first.seen, its looking like less code now smile
can you elaborate on the other ideas you ahd to to trim down plz

Last edited by bwuser; 13/07/08 08:01 PM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You pass parameters separated by commas to an identifier.

$first.seen(value1,value2)

and value1 is passed as $1, and value2 as $2. You can pass text or $identifiers or %variables. Note that if you're using a local variable, you must pass it to the alias as a parameter, since the alias can only see previously existing global variables.

As for your read problem you just now mentioned, it seems like your problem has changed. At first you were saying the read had failed, now it just isn't recognizing dupes as dupes. This will be harder for someone besides yourself to debug. However, by consolidating everything into a single alias, you avoid the need for the $first.seen() alias since the command only appears once in the new section. Also, a single consolidated section is easier to debug, rather than fixing a bug and needing to repeat the fix half a dozen times.

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
i have solved that thanks to your help already now smile
the dupe/read thing
can you elaborate on how to trimdown the 'if' im using

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
i mean instead of having:

if (conditions = A) { do long list of stuff with string#1 }
elseif (conditions = B) { do long list of stuff with string#2 }
elseif (conditions = C) { do long list of stuff with string#3 }

etc...

do:

unset %type

if (conditions = A) { set %type string#1 }
elseif (conditions = B) { set %type string#2 }
elseif (conditions = C) { set %type string#3 }

if (%type) {
do long list of stuff with string %type
}

Joined: Jul 2006
Posts: 248
B
bwuser Offline OP
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Jul 2006
Posts: 248
i feel really stupid atm but i still dont understand what you mean could you maybe alter a piece of my code and use those conditions to get me to understand?

Joined: Jul 2008
Posts: 24
W
Ameglian cow
Offline
Ameglian cow
W
Joined: Jul 2008
Posts: 24
Originally Posted By: bwuser
Code:
if (HR. isin %tvshow) { /write $shortfn $mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.HR.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                elseif (720p isin %tvshow) { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.720p.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
                else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
              }


You could code this more like:
Code:
if (HR. isin %tvshow) { set %HDTV.tvlog HR. | HDTVWrite | unset %HDTV.tvlog }
elseif (720p isin %tvshow) { set %HDTV.tvlog 720p | HDTVWrite | unset %HDTV.tvlog }
else { /write $shortfn($mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ < }
} 

Alias HDTVWrite { write $shortfn $mircdirTXT\Dupes\dupelog.txt) %tvshow | /write $shortfn($mircdirTXT\Dupes\tvlog.txt) %tvshow | /echoall $me >>> New°>> US.Scripted.$+ %HDTV.tvlog $+ HDTV.XviD->> %tvshow First Sighted on >> $+ %source $+ <
halt
}


An alias to do all the /write business, and shorter if, elseif statements

Last edited by WhipLash; 15/07/08 10:50 PM.

=======================
Count WhipLash
Services Administrator
KnightNet
=======================

Link Copied to Clipboard