Public feed #377184

Miscellany

public text v1 · immutable
Raw Edit
·published 2007-03-01 15:26 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

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($gettok($1-,3,47),1,38),1,32)
  else %ytpath = / $+ $gettok($gettok($gettok($1-,2,47),1,38),1,32)
  %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: $+($chr(3),04,<,$chr(15),$date,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$time,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$network %ytchan,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),%ytnick,$chr(3),04>,$chr(15)) %entry
      write yterror.txt < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
    }
    if (%ytchan == $null && %ytnick != $null) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube ERROR: $+($chr(3),04,<,$chr(15),$date,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$time,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$network PM,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),%ytnick,$chr(3),04>,$chr(15)) %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/icn_star_full_19x20.png" isin %ytread) { inc %rating }
  if (ratingComponent.drawStars isin %ytread) { %rating = $remove(%ytread,	,onLoadFunctionList.push) }
  if (<div class="rating ratingCount"> isin %ytread) { %numratings = $remove(%ytread,	,<div class="rating ratingCount">, 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

    if ($read(youtube.txt,w,* $+ %ytpath $+ *) != $null) { %record = noop }
    else { %record = write }

    :title
    if (%ytchan) {
      echo @YouTube ...................................................................................................................................................................................................................................................................................................
      echo @YouTube 4•›››››››› $+($chr(3),04,<,$chr(15),$date,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$time,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$network %ytchan,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),%ytnick,$chr(3),04>,$chr(15)) %entry
      echo @YouTube Title: %title

      %record youtube.txt .....................................................................................................................................................................................................................................................................
      %record youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network %ytchan $+ > < $+ %ytnick $+ > %entry
      %record 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.
        %record 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.
        %record 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.
        %record 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•›››››››› $+($chr(3),04,<,$chr(15),$date,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$time,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),$network PM,$chr(3),04>,$chr(15)) $+($chr(3),04,<,$chr(15),%ytnick,$chr(3),04>,$chr(15)) %entry
      echo @YouTube Title: %title

      %record youtube.txt .....................................................................................................................................................................................................................................................................
      %record youtube.txt < $+ $date $+ > < $+ $time $+ > < $+ $network PM $+ > < $+ %ytnick $+ > %entry
      %record 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.
        %record 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.
        %record 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.
        %record 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
      %record youtube.txt Description: %desc_re
    }
    else {
      echo @YouTube Description: %desc_be
      %record 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
}