on *:text:*youtube.com/watch*:*: {
%url = $*
; this variable is parsed by an external addon. The $urlparse(%url).path command returns the only the path
; in the whole url sent to it. for example: sent http://www.google.com/images/firefox/fox1.gif you will recieve
; /images/firefox/fox1.gif only. I think I do this so that later when i use SOCKOPEN, i can say:
; sockwrite -nt $sockname GET %youtubepathurl HTTP/1.1
;
%youtubepathurl = $urlparse(%url).path
; close before opening O_o
;
if ($sock(111111)) .sockclose 111111
sockopen 111111 youtube.com 80
; make the window if not existing, set the initial message shown in the window
;
if %tube != on {
window @YouTube
set %tube on
echo @YouTube Info: YouTube window opened $day $+ , $date $+ , $time
echo @YouTube .................................................................................................................................................
}
; this section is for queries. If a youtube video url is caught in a query it will show on the @YouTube
; window as a PM from $nick and will be written to youtube.txt as a PM from same $nick also
;
if ($chan == $null) {
echo @YouTube 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4> 4< $+ $network PM $+ 4> 4< $+ $nick $+ 4> $1- Title: %titles Description: %descs
write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network $chan $+ > < $+ $nick $+ > $1- Title: %titles Description: %descs
; just testing something here:
;
; echo @YouTube 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4> 4< $+ $network PM $+ 4> 4< $+ $nick $+ 4> %url Title: %titles Description: %descs
; write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network $chan $+ > < $+ $nick $+ > %url Title: %titles Description: %descs
; This is the problem site
;
unset %titles
unset %descs
; unset %youtubepathurl
; unset %url
}
; this is the section for channel related youtube url video matches. They will be listed
; with the channel info and network info instead of being labeled as a PM in the above section
;
else {
echo @YouTube 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4> 4< $+ $network $chan $+ 4> 4< $+ $nick $+ 4> $1- Title: %titles Description: %descs
write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network $chan $+ > < $+ $nick $+ > $1- Title: %titles Description: %descs
; echo @YouTube 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4> 4< $+ $network $chan $+ 4> 4< $+ $nick $+ 4> %url Title: %titles Description: %descs
; write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network $chan $+ > < $+ $nick $+ > %url Title: %titles Description: %descs
; another problem area
;
unset %titles
unset %descs
; unset %youtubepathurl
; unset %url
}
}
on *:close:@YouTube:{
set %tube off
}
on *:SOCKOPEN:111111: {
sockwrite -nt $sockname GET %youtubepathurl HTTP/1.1
sockwrite -nt $sockname Host: youtube.com
sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:111111: {
; if error, halt
;
if ($sockerr) {
msg %chan Socket Error: $sockname $+ . Error code: $sockerr Please inform $me of this error message.
halt
}
else {
var %sockreader
sockread %sockreader
; get the title of the video from the raw html by parsing it through some tested regex
;
if (*"video_title"* iswm %sockreader ) {
noop $regex(%sockreader,/<h1 id="video_title">(.*?)</h1>/Si)
set %titles = $remove($regml(1),<h1 id="video_title">,</h1>)
}
; get the description of the video from the raw html by parsing it through some tested regex
; interesting note: "vidDescRemain" is for descriptions that are large enough to have a "more..."
; link on youtube's page where you would click and see the rest of the description. On the other hand,
; if the description is short enough, it is listed only under vidDescBegin i think and there is no
; vidDescRemain section in a short description video. I chose to only use vidDescRemain because short
; descriptions would require me to put another if statement and confuse me. So only long descriptions
; are recorded. When a short video is passed through here, %descs is empty I believe. I'm fine with that.
;
if (*"vidDescRemain"* iswm %sockreader ) {
noop $regex(%sockreader,/<span id="vidDescRemain">(.*?)</span>/Si)
set %descs = $remove($regml(1), ,<span id="vidDescRemain">,<br/>,</span>)
sockclose 111111
}
}
}