Chromatic   -  Nov 04, 2013

How would you remove a file extension from a variable that had a file stored in it.

I've used
%variablename = $left(%variablename, -4)

And this works for most files.. but a few files it starts removing the last 4 characters before the . -- So it starts cutting off 4 characters of the part of the filename I want.

For example if the file were the movie Braveheart.mp4 -- Sometimes it would show Braveh

On most instances it will show just Braveheart

This may be due to VLC or something, but a work around / different way / or check would be immensely helpful.

Goal is to say take Braveheart.mp4 and have it store in a variable as just Braveheart.

Not sure why the method of code I am using on some files pulls more than just the .xxx file extension.

So, just curious if there were another way to go about it that would eliminate the "sometimes" removal of more than just the file extension of video files.

Thanks.

dronez4  -  Nov 04, 2013

what i usually do is i use $remove(%variablename,.mp4)

nox`  -  Nov 04, 2013
//var %variablename the.name_of.your.file.mp3 | echo -ag $gettok(%variablename,$+(1-,$calc($numtok(%variablename,46) -1)),46)
dronez4  -  Nov 04, 2013

Yeah, make things more complicated for him :p

nox`  -  Nov 04, 2013

Are you serious? In what this method is more complicated? he fills its variable and uses the continuation to return what he wishes
On the other hand your code example implies that there must write all possible extensions for his files while my example is generic and does't imply any work behind.

illhawkthat  -  Nov 04, 2013

@dronez4 that was my original thought to just do $remove(%var,.mp4,.flv,.avi,.mkv,etc)
@nox` I think I like this solution better. More reliable.

@Chromatic implement it using %vlcann1 = $gettok(%vlcann1,$+(1-,$calc($numtok(%vlcann1,46) -1)),46)
What this does is returns everything before last period (a period has an ascii value of 46).

Meta  -  Nov 04, 2013

Rather than the $calc($numtok()) stuff, it would be easier to just do:

$gettok(%file,1--2,46)

Or even more simply:

$deltok(%file,-1,46)

Where %file is the path of the file, of course.

Chromatic  -  Nov 04, 2013

@dronez4 and
@nox`

Thanks for the help. Really appreciate it.

@illhawkthat -- As always you are awesome.. Put the "fix" in the code.. no issues so far. It's so intermittent we'll see if it works properly, which I'm sure it will.

Thanks all of you.

Chromatic  -  Nov 04, 2013

@Meta -- Thanks, .. There is more than one way to skin a cat :) -- A 4th option of ways to parse/trim a filename.

Chromatic  -  Nov 05, 2013

@Meta As I look at your simple solution -- (I'm a noob with mSL) -- but... can you explain what the -2,46 and -1,46 are doing?

I can only guess that it's storing the file extension with the 1--2 (I have no idea how 1--2 would equal a 3 character file extension.. but it's a guess)

Then.. the $deltok obviously deletes something.. so does -1,46 mean delete everything until the period?
I'm guessing the 46 has something to do with the period in a filename? I only say that cause it's repeated.. and perhaps it's the ascii for period? shrug..

Ya.. you can see why I'm asking such simple questions.. Thanks!

As for the %file -- The path is just relative, or absolute if I did say..

%file = "c:/User/Chromatic/Desktop/Videos/"
$gettok(%file,1--2,46)
$deltok(%file,-1,46)

Maybe that's all wrong, cause %file wouldn't be the actual video file, just the path I set.. I guess it helps to know how the script is running.. it's something like this..

;VLC Trigger Script for Current Playing Streaming Video
on $*:text:/^[!](qinfo|info|now|nowplaying|whoisthis|tellmethepanel|whoaretheguests|qi)/Si:#: {
  sockclose vlc
  sockopen vlc 192.168.1.132 8080
}
on *:sockopen:vlc: {
  if $sockerr > 0 { echo -at vlc not running | sockclose vlc }
  sockwrite -n $sockname GET /requests/status.xml HTTP/1.1
  sockwrite -n $sockname Host: localhost
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname $crlf
}
on *:sockread:vlc: {
  if $sockerr > 0 { echo -a error | sockclose vlc }
  sockread %vlcx

  if (*name='filename'>* iswm %vlcx) {

    if ($regex(%vlcx,<info name='filename'>\s*\K(.+?)(?=\s*<\/info>)) == 1) {
      set %vlcann1 $regml(1)
 (Where The New Code Should Go)     
      ;%vlcann1 = $left(%vlcann1,-4) <-- Previous method I was using to remove .fileextension
    }
  }

 ;This pulls the people on the show, and lists it with the Video/Filename.
  if (*name='artist'>* iswm %vlcx) {

    if ($regex(%vlcx,<info name='artist'>\s*\K(.+?)(?=\s*<\/info>)) == 1) {
      set %vlcann4 $regml(1)
    }
  }

      .describe $chan Now Playing - [[ %vlcann1 ]:: With Panel/Guests::[ %vlcann4 ]] 
      unset %vlcann1
      unset %vlcann4
    }

Is the script -- I pointed out where I would put the changes... Perhaps that helps with the discussion.

By the way, this is an excellent way to show a "now playing" in a stream via trigger. :)

Meta  -  Nov 06, 2013

The 46 in both methods represents the code point for a . character, which in turn is the character used to delimit - or separate - each token. For a typical filename, say, some_video_I_made.mp4 - The tokens become "some_video_i_made" and "mp4".

The syntax of of all the $tok() identifiers is similar, (but I won't get into that now)... In the case of both $gettok() and $deltok(), The first parameter holds the sting you want to use, the second is a either a number or a range that represents which token(s) you want to apply the $tok()'s function to, and the 3rd holds the code point used to delimit each token as described above...

In the second parameter, a positive number N represents the Nth token from the left, while a negative number -N represents the Nth token from the right. A dash placed after N denotes a range starting from N, and ending either at the end of the string, or at another token represented by M (i.e. N-M). I hope this is not too confusing lol...

That being said, in my $gettok() example, 1--2 makes the identifier return a range of tokens starting from the first (leftmost) and ending at the second-rightmost... For example:

$gettok(this.is.some.video.mp4,1--2,46)

will return this.is.some.video

For my $deltok() example, -1 simply makes the identifier delete the rightmost token. For example:

$deltok(this.is.also.some.video.mp4,-1,46)

will return this.is.also.some.video

%file, btw, was just an example variable where the name of the file would be stored. Based on your code, it looks like you'll want to use the %vlcann1 variable, e.g. %vlcann1 = $deltok($regml(1),-1,46)

Chromatic  -  Nov 06, 2013

@Meta Thanks so much for explaining the $Token functions in your own words.. it really helps . This stuff isn't that difficult.. it's just a bunch of simple things all jammed together.. a ton of simple parts equals a complex machine until you learn what each part does and then you can really start to put the puzzle pieces together in different ways..

I understood you about 85-90% --

The $gettok(this.is.some.video.mp4,(1--2),46) Threw me off cause I see either a "--2" or at least a number then two - - then another number.. But.. it's saying, ..

(1--2) = 1 (Start at left side.. at the FIRST character.. and I assume the extra "-" before the "-2" is saying also take everything between. Then the "-2" Is saying, ok Take everything from the Right hand side.. but starting at the second character... (Now that makes me think .. wait a minute.. .mp4 that would miss the 4 on the mp4.. BUT.. the ",46" is the period.. So That being there.. in total:

"1--2,46)" = Start first character of string from left hand side.. take everything in the middle between it and the SECOND character on the right hand side.. but the ,46 says we are dealing with ONLY the range AFTER the period.

So "1" = Select . of .MP4, and the "-" says take everything else in the middle.. and the "-2" says select from the right side.. and it's essentially selecting a range of the "string" if you will.. and erasing it.

I'm still a little confused with the -2 part. Why Wouldn't you say $gettok(this.is.some.video.mp4,1--1,46) ? Would that not select starting from the first character on the left and on the right.. then all in the middle gets erased too -- effectively taking away the ".mp4" ?

I know I sound dense here..

I just did a /help $regml in mIRC and it's like a few sentences.. heh..

But the little bit I sort of get is maybe the $regml is working with the %vlcann1 instead of working with a string specifically..

I know $regml() calls what you previously did with $regex (which I'm still not familiar with..) -- But it holds onto what you did with your prior $regex and stores that into it.. Now you put $deltok($regml(1),-1,46) -- Which is what I would have thought to do to start with starting with first char on left, and 1st char on right and delete all between them... But instead with the $gettok you took (name.of.video.mp4,1--2,46) ...

Am I even sort of close to having this click? :)

I appreciate your time to type all that, maybe some other noobs can get some help from these back and forths over what I'm sure is ABC 123 to you and the other genius coders out there.

If you are banging your head on the desk right now.. It's ok.. You don't have to respond. ;)

Thanks

Meta  -  Nov 06, 2013

Think of the N-M in *$tok(...,N-M,...)** like the $N identifiers ($1, $2, $3, etc) with some extra capabilities.... I'm guessing you're already aware that $1 by default returns the 1st space-delimited token (or word, for simplicity), $2- returns a range of space delimited tokens from the 2nd to the end, $4-6 returns the 4th to 6th tokens... etc.

Note that I said "by default" in the above examples; a command exists that lets you change the character that delimits tokens -- /tokenize

If you type:

//tokenize 46 this is.just some.file name.mp4 | echo -ga $1-3

in mIRC, "this is just some file name" should be echoed in the active window. As I mentioned in my previous post, 46 is the code point for the . character, and thus each $N identifier is filled with anything before or after a . character... in this case, $1 becomes "this is", $2 becomes "just some", $3 becomes "file name", and $4 becomes "mp4". Based on how $N works, it should hopefully mostly make sense why $1-3 returns what it does... (As for why the .s are replaced by spaces, that's another question entirely, and honestly I'm not even sure...)

So getting back to the $*tok() identifiers...

One of the advantages that $*tok() identifiers have over the $N identifiers for things like this is that they allow for negative numbers to be used to represent tokens starting from the right. This is especially useful when you don't know how many tokens the string will consist of. In my $gettok(...,1--2,46) examples, 1- represents the first token (set of characters before/after a .), -2 represents the 2nd to last token... For example:

//echo -ga $gettok(keep in mind.that these.are simply.examples,1--2,46)

Entering this in mIRC should echo "keep in mind.that these.are simply" in the active window. 1 represents "keep in mind", -2 represents "are simply", and the - between them represents everything else in between. For comparison, the closest equivalent with $N, since they do not allow negative numbers, would be something rather awkward, like:

//tokenize 46 keep in mind.that these.are simply.examples | echo -ga $eval($+($!1-,$calc($0 -1)),2)

or...

//tokenize 46 keep in mind.that these.are simply.examples | echo -ga $1- [ $+ [ $calc($0 -1) ] ]

By the way, the reason -2 is used rather than -1 is because -1 represents the rightmost token; In other words, 1--1 is the same as 1-, because it represents everything between and including the leftmost and rightmost tokens. It is for this reason, also that -1 is used with my $deltok(...,-1,46) example: -1 represents the rightmost . delimited token - for your purposes, the file extension.


In case it's not clear at this point, the numbers in these identifiers do not represent individual characters, but rather a set of characters separated by the character numerically represented in the next parameter. (46, as I mentioned, being .) -- You seem to maybe be familiar with the identifiers for that DO behave this way though: $left(), $mid(), and $right().

Chromatic  -  Nov 06, 2013

@Meta Thanks again for explaining it again after I posed questions. I've been up far too long, and it's 3am or so,,.. I am going to go to bed and re-read all of this again tomorrow when I'm not so sleepy/tired/braindead. If I asked questions now they would be frustrating to us both.

You really are going above and beyond the call of duty here, and I do appreciate it. Between you and Illhawkthat I am getting some good help with mSL (IRC) coding.

Thanks so much, -- will give you my thoughts and questions on this tomorrow (well later today technically).

Take care,

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.