mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Working on a songrequest script and I need the length to be stored so that I can make the autoplay alias repeat after the song is over and move to the next song.

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
To alias?
You mean the alias returns a value that you store?

You'll have to use an alias to open a socket, get the info from youtube.com, store it somewhere, then use another alias to return what you stored.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Here's what I have so far. It's kind of altered after seeing a few ideas from people I decided to see what I could do. I have a few things ready to (obviously this is broken, I don't suggest trying it... It'll open a ridiculous amount of tabs of youtube videos if you use "playYT"

Code:
on *:TEXT:!songrequest &:#:{
  echo Trying stuff!
  noop $regex($2,/(youtube\.com)\/.*v=([^&]+)|(youtu\.be)\/(.+)/Si)
  if $read(songrequest.txt,nw,$+(*,$2)) { 
    msg # The Song $gettok($v1,2-,32) is already on my list
  }
  elseif !$regml(2) {
    msg # $nick --> You typed invalid youtube url.
  }
  else {
    youtube $2 $chan $nick
  }
}

alias -l sockopenmark { sockopen -e $1-3 | sockmark $1 $4- }
alias -l youtube {
  noop $regex($1,/(youtube\.com)\/.*v=([^&]+)|(youtu\.be)\/(.+)/Si)
  sockopenmark $+(yt.,$calc($ticks + $rand(1,99))) www.youtube.com 443 $regml(2) msg $2- 
}
on *:sockopen:yt.*:{
  tokenize 32 $sock($sockname).mark
  sockwrite -n $sockname GET /watch?v= $+ $1 HTTP/1.0 
  sockwrite -n $sockname HOST: www.youtube.com $+ $str($crlf,2)
}
on *:sockread:yt.*:{
  tokenize 32 $sock($sockname).mark
  var %v | sockread %v
  if ($regex(%v,/"name" content="(.+)"/)) { 
    var %songname $replace($regml(1),&,$chr(38),',$chr(39),',$chr(39),",$chr(34),",$chr(34),&,$chr(38)) $5-
    $2-3 The Song %songname has been added to my playlist 
    write songrequest.txt $1
    sockclose $sockname
  }
  elseif *</html> iswm %v { $2-3 The Song ( https://www.youtube.com/watch?v= $+ $1 ) is not exists. }
}

alias -l playYT {
  var %songid $read(songrequest.txt,1)
  run -n www.youtube.com/watch?v= $+ %songid
  var %timer $calc(%songlength + 5)
  /write -dl1 songrequest.txt
  .timerplayYTcont 1 %timer playYT
}

menu channel {
  SongRequests ON : /playYT
}


Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Lol, this is exactly the script I've been working on the past couple of weeks. This first part of the script looks up the song and writes it down on the ini file. I did update this but since I'm typing it on my laptop I can't access my new script. I'll post it once I get home.

Code:
on *:TEXT:!songrequest &:#: { 
  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_*
  }
}


Note: In my stream I use dinocoins in order for people to ask for a song. Feel free to remove it!

This script looks up the songrequest by typing !songrequest. You can type in the full look E.G. https://www.youtube.com/watch?v=xxxxxxxxxxx or you can just type the ending bit of the link xxxxxxxxxxxx. You will have to accept a little notice that comes up since this uses g.data.youtube.com instead of the regular youtube html.

Here's the second part of the script I've been using.

Code:

alias -l playYT {
if (%playing == 1)
  var %file songrequest.ini
  if (!$ini(%file,0)) {
     var %number $rand(1,N)
     var %song $ini(newbieplaylist.ini,%number)
     run -n www.youtube.com/watch?v= $+ %song
     var %timer $calc($ini(newbieplaylist.ini,%song,1) + 7)
    .timerplayYT 1 %timer playYT
  }
  ; -----------------------------------------
  var %song $ini(%file,1)
  run -n www.youtube.com/watch?v= $+ %song
  var %timer $calc($ini(%file,%song,1) + 5)
  remini %file %song
  .timerplayYT 1 %timer playYT
}

on *:TEXT:!play &:#: {
  if ($2 == start) {
    set %play 1
    playYT
  }
  elseif ($2 == stop) {
    unset %playing
  }
}


Note: This will open up new tabs so it will be up to you to close the tabs.

When a mod or the channel owner types !play start it starts playing a song from a list of songrequest which you will get from the previous script. To stop the script simply type !play stop. It will finish the currently running song and then stop. Now this is something that can be removed but this script runs a seperate playlist in case there is no songs in the songrequest list. So if no one puts a song down then it will go to newbieplaylist.ini which you can remove. If you want to keep it, change N to the number of songs you have on your personal playlist.

Oh and also this will make the browse window the main window so if you're playing a game just click back on it. Trying to get this fixed.

Last edited by Newbie; 11/02/15 02:30 PM.
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Wow Newbie, thank you for this man. I've been attempting to wrap my head around this for awhile. I got the "playYT" alias from your "/run -n" thread on here. Just altered it to work with my .txt files but using an ini is probably a bit better anyway :P

Thanks again man, appreciate it.

Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
No problem, again there's a better way of finding the length of the video which I will post once I get home. Other than that test it out and see if it works for you.

Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
So, tested it out. Keeps returning a problem on the "writeini songrequest.ini" line... insufficient parameters. No rush on anything man, I appreciate that you're helping me smile

Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Did you check if the ini file had anything written on it? Like did you go to the mirc files and clicked on the songrequest.ini file?

Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Sorry I think I see the issue

where it says songrequest.ini do

Code:
writeini -n songrequest.ini %y_l %y_len %y_n


If that doesn't work add a one to the end of it

Code:
writeini -n songrequest.ini %y_l %y_len %y_n 1

Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Alright, got that sorted out. But now for some reason it's opening 2 tabs (if I have 2 songs in the playlist before doing !play start)

edit:
Tried starting it with only one song and adding more after starting. It ended up opening the correct tab first, then it just opened a ridiculous amount of tab going to just youtube.com

Last edited by Bramzee; 11/02/15 09:25 PM.
Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Mind if I see your playlist code?

Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Sorry about this, this is the problem with being unable to test the code out for yourself. I made a few mistakes when typing out my previous script.

Code:
alias -l playYT {
if (%playing == 1)
  var %file songrequest.ini
  if (!$ini(%file,0)) {
     var %number $rand(1,N)
     var %song $ini(newbieplaylist.ini,%number)
     run -n www.youtube.com/watch?v= $+ %song
     var %timer $calc($ini(newbieplaylist.ini,%song,1) + 7)
    .timerplayYT 1 %timer playYT
  }
  ; -----------------------------------------
  else {
    var %song $ini(%file,1)
    run -n www.youtube.com/watch?v= $+ %song
    var %timer $calc($ini(%file,%song,1) + 5)
    remini %file %song
    .timerplayYT 1 %timer playYT
  }
}

on *:TEXT:!play &:#: {
  if ($2 == start) {
    set %playing 1
    playYT
  }
  elseif ($2 == stop) {
    unset %playing
  }
}


Hopefully this will fix it. I forgot to add the else on the playYT alias and also had set %play originally which meant there was no way of stopping it.

Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Not sure if you're still not able to test, if not it's fine. There's really no rush at all on this. I've got nightbot set up right now for songrequests as well. But... Some songs aren't using the right "duration" when they're requested. Resulting in more than one tab opening... For example my ini file looks like this:

Code:
[song1IDxxxx]
287=nick 1

[song2IDxxxx]
duration==nick 1

[song3IDxxxx]
334=nick 1


This makes it so that the first song plays correctly. Then, after it's over, it pulls up a tab with song2 AND song3.

It may have something to do with certain songs/videos because no matter what, certain ones won't show the correct length. They show "duration"

Also, I altered the %y_len to be set at > 360 (6 mins, since a lot of the songs I like are more than 4 minutes)

Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Yup, I actually ran into this same issue and got it fixed by using binary so here are the two scripts as they are on my mirc.

Code:
on *:TEXT:!yt &:#: { 
  if ($sock(YTube)) .sockclose YTube
  if (*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) {
    sockread &sockreader
    if ($bfind(&sockreader,1,duration=')) { 
      var %y_len $bvar(&sockreader,$bfind(&sockreader,1,duration='),$calc($bfind(&sockreader,1,' yt) - $bfind(&sockreader,1,duration='))).text
      set %y_tlen $remove(%y_len,duration=')
      if (%y_tlen > 360) {
        msg %y_newb Videos longer than 6 minutes are not allowed. 
      }
      else {
        var %dinocoins $readini(Dinocoins.ini,$+(%y_newb,.,%y_n),dinocoins)
        if ($calc(%dinocoins - %y_d) > 0) {
          writeini -n Dinocoins.ini $+(%y_newb,.,%y_n) dinocoins $calc(%dinocoins - %y_d)
          writeini songrequest.ini %y_l %y_tlen %y_n 1
          unset %y_*
        }
        else {
          msg %y_newb You do not have enough dinocoins!
          unset %y_*
        }
      }
    }
  }
  else {
    msg %y_newb Video could not be found. 
    unset y_*
  }
}

alias -l playYT {
  if (%playing == 1) {
    var %file songrequest.ini
    if (!$ini(%file,0)) {
      var %number $rand(1,50)
      var %song $ini(newbieplaylist.ini,%number)
      run -n www.youtube.com/watch?v= $+ %song
      var %timer $calc($ini(newbieplaylist.ini,%song,1) + 7)
      .timerplayYT 1 %timer playYT
    }
    ; -----------------------------------------
    else { 
      var %song $ini(%file,1)
      run -n www.youtube.com/watch?v= $+ %song
      var %timer $calc($ini(%file,%song,1) + 7)
      remini %file %song
      .timerplayYT 1 %timer playYT
    }
  }
}

on *:TEXT:!play &:#:{
  if ($2 == start) { 
    if ($nick !isop #) {
      msg # This is a command for mods only!
    }
    else {
      set %Playing 1
      playYT
    }
  }
  elseif ($2 == stop) {
    unset %Playing
  }
}

Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Thank you Newbie. I added a "!song" command to display the current song and who it was requested by. I have "!skip" working (but obviously it's more of a pain than anything without having a way to auto close the tabs... Leads to some weird combos of multiple songs playing lol.

I'll share what I added tomorrow after I've fixed them up a little. They're super sloppy right now and I'm too tired to go in and clean up. But, thank you again for this. It's been a ridiculous help.

Joined: Nov 2014
Posts: 79
N
Babel fish
Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Yeah, either that or find a way of making it load on the same tab instead of making a new one


Link Copied to Clipboard