mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
So this is for my songrequest script, and uses my browser to open up the youtube video. Using sockets I have retrieved and documented the length of the video and the link to the video. For the system to work the %y_t value must decrease in seconds to follow the video length but it runs too fast! Why is this happening?

Code:
on *:TEXT:!play &:#: {
  if ($2 == start) {
    set %y_ss $ini(songrequest.ini,0)
    while (%y_ss) {
      var %y_s $ini(songrequest.ini,1)
      var %y_t 0
      if (%y_t == 0) {
        url -a www.youtube.com/watch?v= $+ %y_s
        set %y_t $ini(songrequest.ini,%y_s,1)
        while (%y_t) {
          dec -z %y_t
          echo -a %y_t
        }
        remini songrequest.ini %y_s
        dec %y_ss 
      } 
    }
  }
}




For reference here is my video length retrieval link.
Code:
on *:TEXT:!yt &:#: { 
  if ($sock(YTube)) .sockclose YTube
  if (*www.youtube.com* iswm $2) {
    set %y_l $right($2,11)
  }
  else {
    set %y_l $2
  }
  if ($ini(songrequest.ini,%y_l,0) == 1) {
    msg # This song is already in my playlist. 
    unset %y_l
  }
  else {
    set %y_d 1
    set %y_n $nick
    set %y_newb $chan
    sockopen -e YTube gdata.youtube.com 443
  }
}

on *:SOCKOPEN:YTube: {
  sockwrite -nt $sockname GET /feeds/api/videos/ $+ %y_l HTTP/1.1
  sockwrite -nt $sockname Host: gdata.youtube.com $+ $str($crlf,2)
}

on *:SOCKREAD:YTube: {
  if (!$sockerr) {
    var %sockreader | sockread %sockreader
    if (*duration='*'* iswm %sockreader) {
      set %y_len $gettok(%sockreader,46,39)
      if (%y_len > 240) { 
        msg %y_newb Videos cannot be longer than 4 minutes. 
        unset %y_*
      }
      else {
        writeini -n Dinocoins.ini $+(%y_newb,.,%y_n) dinocoins $calc($readini(Dinocoins.ini,$+(%y_newb,.,%y_n),dinocoins) - %y_d)
        writeini songrequest.ini %y_l %y_len %y_n
        msg %y_newb Your song has been added, you now have $readini(Dinocoins.ini,$+(%y_newb,.,%y_n),dinocoins) $+ . 
        unset %y_*
      }
    }
  }
  else {
    msg %y_newb There was an error
    unset y_*
  }
}

Last edited by Newbie; 01/02/15 09:23 PM.
Joined: Aug 2013
Posts: 81
I
Babel fish
Online
Babel fish
I
Joined: Aug 2013
Posts: 81
The reason it counts down so quickly is that you placed the /dec within a while loop, which execute the commands within them repeatedly and without (intentional) delay until the condition is met. Simply omit the while loop (-z will continue automatically), and it should work. If you want to see the value of the variable every time it decreases, you can use the -s switch. (Although keep in mind that it will appear in the status window rather than the active window)

By the way, /set can also use the -z switch, so you can omit the /dec entirely as well.

Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Really? Would you mind showing me an example?

Also not to ask for more than I started with, why does the /url command open a second window when the -a is supposed to open in the active browser window?

Joined: Aug 2013
Posts: 81
I
Babel fish
Online
Babel fish
I
Joined: Aug 2013
Posts: 81
Quick example you can run directly from the editbox (typing area) in mIRC: /set -sz %iirevar 10

The /url -a causing the browser to open a new window rather than a new tab might be the fault of the browser's handling of this task rather than a fault of mIRC. What browser do you use?

Oh, I didn't notice, but you should also remove the var %y_t (and the related if statement) from your code, else the variable will be made local and deleted as soon as the script finishes.

Last edited by Iire; 01/02/15 10:11 PM.
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
I use google chrome as my main browser.

Btw I'm trying to change the code but can't find a way to alter the code but can't find something that works.

Using this
Code:
on *:TEXT:!play &:#: {
  if ($2 == start) {
    set %y_ss $ini(songrequest.ini,0)
    while (%y_ss) {
      var %y_s $ini(songrequest.ini,1)
      set -sz %y_t $ini(songrequest.ini,%y_s,1)
      url -a www.youtube.com/watch?v= $+ %y_s
      remini songrequest.ini %y_s
      dec %y_ss  
    }
  }
}


Makes the counter tick by seconds but the first while loop still continues. The other combinations of code either crashed the program or created so many new tabs it almost broke google chrome.

Thanks again and I understand if you're done helping, but any advice will do.

Joined: Aug 2013
Posts: 81
I
Babel fish
Online
Babel fish
I
Joined: Aug 2013
Posts: 81
Can I ask what you're attempting to do with the outer while loop? I'm guessing trying to go through a queue of songs within the ini file but I want to check to be sure.

Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Yup, the second script I wrote will fill up a list of songs, which when I type play will continue to play until the list is finished.

Joined: Aug 2013
Posts: 81
I
Babel fish
Online
Babel fish
I
Joined: Aug 2013
Posts: 81
Alright

So first, I apologize for missing all these things before. I have quite a bit of a headache so my focus isn't as good as it could be.

That said, I'd assume that you would want each song to play once the previous is finished, rather than all at once like the while loop will do... If so, you can create an alias which uses a timer that calls itself after a certain number of seconds (say, the length of the song) if there are any more songs to play, and then just call that alias from the on TEXT event... Based on your current code for example:

Code:
alias -l playYT {
  var %file = songrequest.ini
  if (!$ini(%file, 0)) return
  ; -----------------------------------------
  var %song = $ini(%file, 1)
  url -a www.youtube.com/watch?v= $+ %song
  remini %file %song
  .timerplayYT 1 $ini(%file, %song, 1) playYT
}

on *:TEXT:!play &:#:{
  if ($2 == start) playYT
}


The alias above will first check if there are no songs left in the file (via $ini(songrequest.ini, 0)), and, if so, return and do nothing, otherwise, open the youtube video in browser for the first song, remove that song from the file, then start a timer that (hopefully) takes the song's play time as a delay and repeats the whole process again while applicable. As a bonus, this timer method eliminates the need for a global variable and -z switch for your script.

Though I am curious... how exactly is the ini file structured? because $ini(%file, %song, 1) will return the first item name (part left of the =) rather than its value... So this appears wrong to me but maybe you've written it that way for some reason.

Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Dude! You are awesome! Thanks for all your help! Quick thing, I had to add a variable %timer the song information would get deleted from the remini. Also you can't call an alias inside of itself so I just made a playYTcont alias. Here's the final script. You are great thanks again!

Code:
alias -l playYT {
  var %file songrequest.ini
  if (!$ini(%file,0)) return
  ; -----------------------------------------
  var %song $ini(%file,1)
  url -a www.youtube.com/watch?v= $+ %song
  var %timer $ini(%file,%song,1)
  remini %file %song
  .timerplayYTcont 1 %timer playYTcont
}
alias -l playYTcont {
  var %file = songrequest.ini
  if (!$ini(%file,0)) return
  : -----------------------------------------
  var %song = $ini(%file,1)
  echo -a $ini(%file,%song,1)
  url -a www.youtube.com/watch?v= $+ %song
  var %timer $ini(%file,%song,1)
  remini %file %song
  .timerplayYT 1 %timer playYT 
}

on *:TEXT:!play &:#:{
  if ($2 == start) playYT
}

Joined: Aug 2013
Posts: 81
I
Babel fish
Online
Babel fish
I
Joined: Aug 2013
Posts: 81
Originally Posted By: Newbie
Also you can't call an alias inside of itself so I just made a playYTcont alias.


This is indeed usually correct, however calling an alias from within itself through a timer is allowed; one of the few exceptions to the rule.


Link Copied to Clipboard