All pastes #517207 Raw Edit

Mine

public text v1 · immutable
#517207 ·published 2007-05-29 00:10 UTC
rendered paste body
;Youtube URL logger
;finds info about a youtube video and logs it to @YouTube and writes to youtube.txt
;info it finds about a single video: title, description, ratngs, view count, # of comments, times favorited

;youtube video search
;returns the first search result for your search terms

;triggers: !youtube @youtube !tube @tube
;syntax: @youtube 

; youtube URL logger
; finds info about a youtube video and logs it to @YouTube and writes to youtube.txt
; info it finds about a single video: title, description, ratngs, view count, # of comments, times favorited


on *:text:*youtube.com/watch?v=*:*:{
  %rating = 0
  %entry = $1-
  if %tube != on {
    window @YouTube
    set %tube on
    echo @YouTube •›› Info: YouTube window opened $day $+ , $date $+ , $time
  }
  if (http:// isin $1-) %ytpath = / $+ $gettok($gettok($1-,3,47),1,38)
  else %ytpath = / $+ $gettok($gettok($1-,2,47),1,38)
  %ytnick = $nick
  %ytchan = $chan
  sockclose yt
  sockopen yt youtube.com 80
}

on *:close:@YouTube:{
  set %tube off
}

on *:sockopen:yt:{
  if ($sockerr) {
    echo -a $chr(91) $+ $time $+ $chr(93) YouTube: socket error 
    if (%ytchan) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube ERROR: < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
      write yterror.txt < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
    }
    if (%ytchan == $null && %ytnick != $null) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube ERROR: < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
      write yterror.txt < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
    }
    halt
  }
  sockwrite -n $sockname GET %ytpath HTTP/1.1
  sockwrite -n $sockname Host: youtube.com
  sockwrite -n $sockname $crlf
}

on *:sockread:yt: {
  :read
  sockread -f %ytread


  if (Ratings have been disabled for this video isin %ytread) { set %ratingsdisabled yes }
  if (Adding comments have been disabled for this video isin %ytread) { set %commentsdisabled yes }
  if (<img class="rating" src="/img/star.gif" isin %ytread) { inc %rating }
  if (<div class="rating"> isin %ytread) { %numratings = $remove(%ytread,       ,<div class="rating">,ratings, ,</div>) }
  if (Views: <span class="statVal"> isin %ytread) { %views = $remove(%ytread,   ,<span class="statVal">,</span>,<div class="statDivider">,|</div>, ,Views:) }
  if (Comments: <span class="statVal"> isin %ytread) { %comments = $remove(%ytread,     ,<span class="statVal">,</span>,<div class="statDivider">,|</div>, ,Comments:) }
  if (Favorited: <span class="statVal"> isin %ytread) { %favorited = $remove(%ytread,   ,<span class="statVal">,</span>,<div class="statDivider">,|</div>, ,Favorited:) }
  if (<title> isin %ytread) %title = $remove(%ytread,   ,<title>YouTube - ,</title>)
  if (%found) { unset %found | %desc_be = $remove(%ytread,      ) }
  if (<span id="vidDescBegin"> isin %ytread) %found = k
  if (<span id="vidDescRemain"> isin %ytread) %desc_re = $replace($remove(%ytread,      ,<span id="vidDescRemain">,</span>),<br/>,$chr(32))
  if (<span class="smallLabel">Category&nbsp;</span> isin %ytread) %done = k

  if (%done) {
    sockclose yt
    unset %done

    :title
    if (%ytchan) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube 4&#8226;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250; 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4>  4< $network %ytchan $+ 4> 4< $+ %ytnick $+ 4> %entry
      echo @YouTube Title: %title

      write youtube.txt .....................................................................................................................................................................................................................................................................
      write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
      write youtube.txt Title: %title

      if (%ratingsdisabled == yes && %commentsdisabled == yes) {
        echo @YouTube Rating: %rating stars 4(Disabled). Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars (Disabled). Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      if (%commentsdisabled == yes && %ratingsdisabled = $null) {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      else {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        goto desc
      }
    }
    if (%ytchan == $null && %ytnick != $null) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube 4&#8226;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250; 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4> 4< $network PM $+ 4> 4< $+ %ytnick $+ 4> %entry
      echo @YouTube Title: %title

      write youtube.txt .....................................................................................................................................................................................................................................................................
      write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
      write youtube.txt Title: %title

      if (%ratingsdisabled == yes && %commentsdisabled == yes) {
        echo @YouTube Rating: %rating stars 4(Disabled). Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars (Disabled). Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      if (%commentsdisabled == yes && %ratingsdisabled = $null) {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      else {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        goto desc
      }
    }

    :desc
    if (%desc_re) { 
      echo @YouTube Description: %desc_re
      write youtube.txt Description: %desc_re
    }
    else {
      echo @YouTube Description: %desc_be
      write youtube.txt Description: %desc_be
    }

    unset %entry
    unset %ytpath
    unset %ytnick
    unset %ytchan
    unset %title
    unset %ytread
    unset %desc_be
    unset %desc_re
    unset %rating
    unset %views
    unset %comments
    unset %favorited
    unset %numratings
    unset %ratingsdisabled
    unset %commentsdisabled
  }
  if ($sockbr) goto read
}

; youtube video search
; returns the first search result for your search terms
;
; triggers: !youtube @youtube !tube @tube
; syntax: @youtube <search terms>.
; example: !tube charleston daft punk

on $*:TEXT:/^[!@](youtube|tube) */Si:#: { 
  %linenumber = 0
  set %chan.tube $chan
  set %tube.style /msg %chan.tube
  set %tube.search $replace($2-,$chr(32),+)

  if ($2 == $null) { %tube.style Search could not be completed | halt }
  sockopen ytsearch www.youtube.com 80
}


on *:sockopen:ytsearch:{
  sockwrite -nt $sockname GET /results?search_query= $+ %tube.search HTTP//1.1
  ;
  ; if you want to sort search by VIEW COUNT, use this instead of the line above
  ; sockwrite -nt $sockname GET /results?search_query= $+ %tube.search $+ &search_sort=video_view_count HTTP//1.1

  sockwrite -nt $sockname Host: youtube.com 
  sockwrite -nt $sockname $crlf $crlf 
}

on *:sockread:ytsearch:{
  var %temp
  sockread %temp

  if (%searchres == 1) {
    %searchtitle = $remove($regsubex(%temp,/<a [^>]+>(.+?)</a>/,\1),<br/>,<b>,</b>,      )
    set %tube.url $remove($gettok(%temp,2,32),href=",")

    if (/watch?v= isin %tube.url) {
      %tube.style %searchtitle $+ : http://www.youtube.com $+ %tube.url

      unset %linenumber
      unset %tube.search
      unset %searchtitle
      unset %chan.tube
      unset %tube.style
      unset %searchres      
      unset %tube.url

      sockclose ytsearch
      halt
    }
  }
  if ( *start search results* iswm %temp) { set %searchres 0 }  
  if (*<a href="/watch?v=* iswm %temp) { inc %searchres }
  if (*No Videos found* iswm %temp) {
    %tube.style No videos found for %tube.search
    unset %linenumber
    unset %tube.search
    unset %searchtitle
    unset %chan.tube
    unset %tube.style
    unset %searchres      
    unset %tube.url
    sockclose ytsearch
    halt
  }
  inc %linenumber
} 
Raw Content Download: http://pastebin.ca/raw/362191
Total Paste Views: 14
Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.


paste below
; &#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;
; Put your own scripts in here.
; &#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;

; youtube URL logger
; finds info about a youtube video and logs it to @YouTube and writes to youtube.txt
; info it finds about a single video: title, description, ratngs, view count, # of comments, times favorited


on *:text:*youtube.com/watch?v=*:*:{
  %rating = 0
  %entry = $1-
  if %tube != on {
    window @YouTube
    set %tube on
    echo @YouTube &#8226;&#8250;&#8250; Info: YouTube window opened $day $+ , $date $+ , $time
  }
  if (http:// isin $1-) %ytpath = / $+ $gettok($gettok($1-,3,47),1,38)
  else %ytpath = / $+ $gettok($gettok($1-,2,47),1,38)
  %ytnick = $nick
  %ytchan = $chan
  sockclose yt
  sockopen yt youtube.com 80
}

on *:close:@YouTube:{
  set %tube off
}

on *:sockopen:yt:{
  if ($sockerr) {
    echo -a $chr(91) $+ $time $+ $chr(93) YouTube: socket error 
    if (%ytchan) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube ERROR: < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
      write yterror.txt < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
    }
    if (%ytchan == $null && %ytnick != $null) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube ERROR: < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
      write yterror.txt < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
    }
    halt
  }
  sockwrite -n $sockname GET %ytpath HTTP/1.1
  sockwrite -n $sockname Host: youtube.com
  sockwrite -n $sockname $crlf
}

on *:sockread:yt: {
  :read
  sockread -f %ytread


  if (Ratings have been disabled for this video isin %ytread) { set %ratingsdisabled yes }
  if (Adding comments have been disabled for this video isin %ytread) { set %commentsdisabled yes }
  if (<img class="rating" src="/img/star.gif" isin %ytread) { inc %rating }
  if (<div class="rating"> isin %ytread) { %numratings = $remove(%ytread,	,<div class="rating">,ratings, ,</div>) }
  if (Views: <span class="statVal"> isin %ytread) { %views = $remove(%ytread,	,<span class="statVal">,</span>,<div class="statDivider">,|</div>, ,Views:) }
  if (Comments: <span class="statVal"> isin %ytread) { %comments = $remove(%ytread,	,<span class="statVal">,</span>,<div class="statDivider">,|</div>, ,Comments:) }
  if (Favorited: <span class="statVal"> isin %ytread) { %favorited = $remove(%ytread,	,<span class="statVal">,</span>,<div class="statDivider">,|</div>, ,Favorited:) }
  if (<title> isin %ytread) %title = $remove(%ytread,	,<title>YouTube - ,</title>)
  if (%found) { unset %found | %desc_be = $remove(%ytread,	) }
  if (<span id="vidDescBegin"> isin %ytread) %found = k
  if (<span id="vidDescRemain"> isin %ytread) %desc_re = $replace($remove(%ytread,	,<span id="vidDescRemain">,</span>),<br/>,$chr(32))
  if (<span class="smallLabel">Category&nbsp;</span> isin %ytread) %done = k

  if (%done) {
    sockclose yt
    unset %done

    :title
    if (%ytchan) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube 4&#8226;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250; 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4>  4< $network %ytchan $+ 4> 4< $+ %ytnick $+ 4> %entry
      echo @YouTube Title: %title

      write youtube.txt .....................................................................................................................................................................................................................................................................
      write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
      write youtube.txt Title: %title

      if (%ratingsdisabled == yes && %commentsdisabled == yes) {
        echo @YouTube Rating: %rating stars 4(Disabled). Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars (Disabled). Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      if (%commentsdisabled == yes && %ratingsdisabled = $null) {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      else {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        goto desc
      }
    }
    if (%ytchan == $null && %ytnick != $null) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube 4&#8226;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250;&#8250; 4< $asctime(mm:dd:yyyy-HH:nn:ss) $+ 4> 4< $network PM $+ 4> 4< $+ %ytnick $+ 4> %entry
      echo @YouTube Title: %title

      write youtube.txt .....................................................................................................................................................................................................................................................................
      write youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
      write youtube.txt Title: %title

      if (%ratingsdisabled == yes && %commentsdisabled == yes) {
        echo @YouTube Rating: %rating stars 4(Disabled). Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars (Disabled). Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      if (%commentsdisabled == yes && %ratingsdisabled = $null) {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments 4(Disabled). Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments (Disabled). Favorited: %favorited times.
        goto desc
      }
      else {
        echo @YouTube Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        write youtube.txt Rating: %rating stars. Rated: %numratings times. Views: %views $+ . Comments: %comments $+ . Favorited: %favorited times.
        goto desc
      }
    }

    :desc
    if (%desc_re) { 
      echo @YouTube Description: %desc_re
      write youtube.txt Description: %desc_re
    }
    else {
      echo @YouTube Description: %desc_be
      write youtube.txt Description: %desc_be
    }

    unset %entry
    unset %ytpath
    unset %ytnick
    unset %ytchan
    unset %title
    unset %ytread
    unset %desc_be
    unset %desc_re
    unset %rating
    unset %views
    unset %comments
    unset %favorited
    unset %numratings
    unset %ratingsdisabled
    unset %commentsdisabled
  }
  if ($sockbr) goto read
}




; youtube video search
; returns the first search result for your search terms
;
; triggers: !youtube @youtube !tube @tube
; syntax: @youtube <search terms.
; example: !tube charleston daft punk


; if you want to sort search by VIEW COUNT, use this line below
; sockwrite -nt $sockname GET /results?search_query=
;
; if you want the regular search, use this line below
; sockwrite -nt $sockname GET /results?search_query= $+ %tube.search HTTP//1.1
;
; you'd put either one of those on line 32 of this script
; that line number may be different when this script is put into a bigger script
; so the place im referring to is: under the heading on *:sockopen:ytsearch:{


on $*:TEXT:/^[!@](youtube|tube) */Si:#: { 
  %linenumber = 0
  set %chan.tube $chan
  set %tube.style /msg %chan.tube
  set %tube.search $replace($2-,$chr(32),+)

  if ($2 == $null) { %tube.style Search could not be completed | halt }
  sockopen ytsearch www.youtube.com 80
}


on *:sockopen:ytsearch:{
  sockwrite -nt $sockname GET /results?search_query= $+ %tube.search HTTP//1.1
  ;
  ; if you want to sort search by VIEW COUNT, use this instead of the line above
  ; sockwrite -nt $sockname GET /results?search_query= $+ %tube.search $+ &search_sort=video_view_count HTTP//1.1

  sockwrite -nt $sockname Host: youtube.com 
  sockwrite -nt $sockname $crlf $crlf 
}

on *:sockread:ytsearch:{
  var %temp
  sockread %temp

  if (%searchres == 1) {
    %searchtitle = $remove($regsubex(%temp,/<a [^>]+>(.+?)</a>/,\1),<br/>,	)
    set %tube.url $remove($gettok(%temp,2,32),href=",")

    if (/watch?v= isin %tube.url) {
      %tube.style %searchtitle $+ : http://www.youtube.com $+ %tube.url

      unset %linenumber
      unset %tube.search
      unset %searchtitle
      unset %chan.tube
      unset %tube.style
      unset %searchres      
      unset %tube.url

      sockclose ytsearch
      halt
    }
  }
  if ( *start search results* iswm %temp) { set %searchres 0 }  
  if (*<a href="/watch?v=* iswm %temp) { inc %searchres }
  if (*No Videos found* iswm %temp) {
    %tube.style No videos found for %tube.search
    unset %linenumber
    unset %tube.search
    unset %searchtitle
    unset %chan.tube
    unset %tube.style
    unset %searchres      
    unset %tube.url
    sockclose ytsearch
    halt
  }
  inc %linenumber
}