alias youtube {
if (https://www.youtube.com isin $1-) {
set %linked $remove($wildtok($1-,$ifmatch $+ *,1,32),https://)
set %apikey = X
sockopen -e ytube www.googleapis.com 80
}
}
on *:sockopen:ytube:{
if (!$sockerr) {
sockwrite -n $sockname GET $+(/youtube/v3/videos?id=,$remove($gettok(%linked,2-,47),watch?v=),&key=,%apikey,&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics) HTTP/1.1
sockwrite -n $sockname Host: www.googleapis.com
sockwrite -n $sockname $crlf
}
else {
echo -a $sockerr
sockclose $sockname
halt
}
}
on *:sockread:ytube:{
if ($sockerr) { echo -a $sockerr | sockclose $sockname | return }
else {
var %check | sockread %check
while ($sockbr) {
echo -a %check
sockread %check
}
}
}