This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

IMDB script question

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

IMDB script question

Post by Gordon »

Hi, I see there is few imdb lookup scripts but is there some script that will display movie info automatically when is the imdb url sent to channel?
Thanks.
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Well, it exists for youtube so I think you can do it easily.
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Post by Gordon »

What youtube script you specifically refer to?

I'm not sure I could do it by myself, I was thinking it could use this API http://www.omdbapi.com and imdbId to identify movie from url. For example http://www.omdbapi.com/?i=tt1285016 With that it should be somewhat easy to parse and modify output by anyones choice. I suppose quite easy job for someone speaking tcl.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The API you are referring to isn't as good as you would hope would cos it will return only one title if matches multiple, for example search "batman" and you will see what I'm talking about.

You could use this (but you'll have to look at what's the latest working version) as starting point and have a pubm regexp to trigger the proc that fetches the results from IMDB itself and outputs the result to the channel. It's not that hard to do, so let us know if you get stuck or need help on what needs to be done.
Once the game is over, the king and the pawn go back in the same box.
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Post by Gordon »

caesar wrote:The API you are referring to isn't as good as you would hope would cos it will return only one title if matches multiple, for example search "batman" and you will see what I'm talking about.
True but what I want is not intended to be some manual title info search, but something that simply outputs info when triggered by imdb url with imdbId of a title in it. I have close to none tcl experience but I will try to find and look on scripts that provide similar function if no one else steps in.
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I think you want something like (really simple):

Code: Select all

bind pubm - * checkimdb
proc checkimdb {user host handle chan text} {
   set url "http://www.omdbapi.com"
   set watch [regexp -nocase -- {\/\?i\=([^\s]{11})} $text imdbid]
   if { $imdbid } {
      set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"     
      set t [::http::config -useragent $agent]
      set t [::http::geturl "$url/?i=$imdbid" -timeout 30000]
      set data [::http::data $t]
      ::http::cleanup $t
# parse $t to get all infos...
# And display (look at script given by caesar)
   }
   return 0
}
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Post by Gordon »

Can someone post complete script?

I cannot make it work (tcl knowledge less than limited).
a
arkadio
Voice
Posts: 6
Joined: Fri Dec 13, 2013 7:36 am

Post by arkadio »

Code: Select all

# IMDb query v1.17 (updated by username@egghelp.org forums)
# Copyright (C) 2007-2009 perpleXa
# http://perplexa.ugug.org / #perpleXa on QuakeNet
#
# Redistribution, with or without modification, are permitted provided
# that redistributions retain the above copyright notice, this condition
# and the following disclaimer.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Usage:
#  !movie <title>

package require http 2.7; # TCL 8.5

namespace eval imdb {
  variable version 1.17;

  # Headers color
  variable color1 \00301
  # Information color
  variable color2 \00304
  # flood protection (seconds)
  variable antiflood "10";
  # character encoding
  variable encoding "utf-8";
  # user agent
  variable agent "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) Gecko/2006101023 Firefox/2.0";

  # internal
  bind pub -|- "!imdb" [namespace current]::public;
  bind msg -|- "!imdb" [namespace current]::private;
  variable flood;
  namespace export *;
}

proc imdb::public {nick host hand chan argv} {
  imdb::main $nick $host $hand $chan $argv
}

proc imdb::private {nick host hand argv} {
  imdb::main $nick $host $hand $nick $argv
}

proc imdb::main {nick host hand chan argv} {
  variable flood; variable antiflood;
  variable color1; variable color2;
  if {![info exists flood($chan)]} { set flood($chan) 0; }
  if {[unixtime] - $flood($chan) <= $antiflood} { return 0; }
  set flood($chan) [unixtime];

  set argv [string trim $argv];
  if {$argv == ""} {
    puthelp "NOTICE $nick :\002${color1}Syntax\002: ${color2}$::lastbind <title>\003";
    return 0;
  }

  set id [id $argv];
  if {$id == ""} {
    chanmsg $chan "${color1}Filme não encontrado: ${color2}$argv";
    return 0;
  }

  set info [getinfo $id];
  if {![llength $info]} {
    chanmsg $chan "${color1}Não foi possível ler as informações para ${color2}$id${color1}.\003";
    return 0;
  }

  for {set i 0} {$i < [llength $info]} {incr i} {
    set info [lreplace $info $i $i [decode [lindex $info $i]]];
  }

  set name     [lindex $info 0];   set year      [lindex $info 1];
  set desc     [lindex $info 2];   set dir       [lindex $info 3];
  set rel      [lindex $info 4];   set storyline [lindex $info 5];
  set keywords [lindex $info 6];   set country   [lindex $info 7];
  set genre    [lindex $info 8];   set language  [lindex $info 9];
  set aka      [lindex $info 10];  set runtime   [lindex $info 11];
  set rating   [lindex $info 12];  set votes     [lindex $info 13];
  set top5000   [lindex $info 14]; set stars   [lindex $info 15];
  set alsoliked [lindex $info 16]; set budget [lindex $info 17];

  if {$name == ""} {
    chanmsg $chan "${color1}Couldn't get information for movie id ${color2}$id${color1}.\003";
    return 0;
  }

  if {$rating == "-"} {
      set rating_ 0
  } else {
      set rating_ $rating
  }
  chanmsg $chan "\002${color2}$name\002${color1}. \002Nota:\002 [bar $rating_] $color2$rating${color1}/10\003${color1}; \002${color1}Diretor\002: ${color2}$dir${color1}; ${color1}\002Lançamento\002: ${color2}$rel\003; \002${color1}Atores\002: ${color2}$stars${color1}; \002${color1}Link\002: \00312\037http://imdb.com/title/$id\037\003"
  chanmsg $chan "\002${color1}Descrição: \002${color2}$desc\003";
  #chanmsg $chan "\002${color1}Top 5000\002 ${color2}$top5000\003";
  #chanmsg $chan "\002${color1}Stars\002: ${color2}$stars \002${color1}Director\002: ${color2}$dir ${color1}\002Release date\002: ${color2}$rel\003";
  #chanmsg $chan "\002${color1}Storyline\002: ${color2}$storyline\003 ...";
  #chanmsg $chan "\002${color1}Plot keywords\002: ${color2}$keywords ${color1}\002Genre\002: ${color2}$genre\003";
  #chanmsg $chan "\002${color1}Language\002: ${color2}$language ${color1}\002Country\002: ${color2}$country ${color1}\002Runtime\002: ${color2}$runtime ${color1}\002Budget\002: ${color2}$budget ${color1}\002Link\002: \00312\037http://imdb.com/title/$id\037\003";
  #chanmsg $chan "\002${color1}People who liked this also liked\002: ${color2}$alsoliked\003";
}

proc imdb::bar {float} {
  set stars [format "%1.0f" $float];
  return "\00312\[\00307[string repeat "*" $stars]\00314[string repeat "-" [expr 10-$stars]]\00312\]\003";
}

proc imdb::chanmsg {chan text} {
  if {[validchan $chan]} {
    if {[string first "c" [lindex [split [getchanmode $chan]] 0]] >= 0} {
      regsub -all {(?:\002|\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\026|\037)} $text "" text;
    }
  }
  putquick "PRIVMSG $chan :$text";
}

proc imdb::id {movie} {
  variable agent;
  http::config -useragent $agent;
  if {[catch {http::geturl "http://www.imdb.com/find?q=[urlencode $movie]&s=all" -timeout 20000} token]} {
    return;
  }
  set data [http::data $token];
  set code [http::ncode $token];
  set meta [http::meta $token];
  http::cleanup $token;
  if {$code == 200} {
    set id "";
    regexp -nocase -- {<a href="/title/(tt[0-9]+)/\?ref_=fn_al_tt_[0-9]" ><img src="http://ia.media-imdb.com/images/M.*?} $data -> id;
    return $id;
  } else {
    foreach {var val} $meta {
      if {![string compare -nocase "Location" $var]} {
        regexp -nocase {tt\d+} $val val;
        return $val;
      }
    }
  }
}

proc imdb::getinfo {id} {
  variable agent; 
  variable color1;
  variable color2;
  http::config -useragent $agent;
  if {[catch {http::geturl "http://www.imdb.com/title/$id/" -timeout 20000} token]} {
    return;
  }
  set data [http::data $token];
  set data [encoding convertfrom utf-8 $data]
  regsub -all -- {\r|\n} $data "" data;
  http::cleanup $token;

  set name ""; set year ""; set desc ""; set dir ""; set rel ""; set genre ""; set country ""; set plot "";
  set rating 0; set votes ""; set runtime ""; set language ""; set storyline ""; set keywords ""; set aka "";
  set top5000 ""; set stars ""; set alsoliked ""; set budget "";

  ### Main.
  regexp -nocase -- {<a href="/year/.*?" >(.*?)</a>.*?<span class="title-extra" itemprop="name">(.*?)<i>} $data -> year name;

  if {$name == ""} {
      regexp -nocase -- {<h1 class="header"> <span class="itemprop" itemprop="name">(.*?)</span} $data -> name;
  }
  if {$year == ""} {
      regexp -nocase -- {<a href="/year/.*?" >(.*?)</a>} $data -> year;
  }

  regexp -nocase -- {<p itemprop="description">(.*?)</p>} $data -> desc;
  regexp -nocase -- {Director:(.*?)</a>} $data -> dir;
  regsub -all "<.*?>" $dir "" dir
  regexp -- {Release Date:</h4>(.*?)<span class="see-more inline">} $data -> rel;
  regsub -all "<.*?>" $rel "" rel

  ### Stars.
  regexp -nocase -- {Stars:</h4>(.*?)</div>} $data -> stars_;
  foreach {null star} [regexp -all -nocase -inline -- {<span class="itemprop" itemprop="name">(.*?)</span>} $stars_] {
    lappend stars [string trim $star]
  }

  ### Storyline.
  if {$storyline == ""} {
      regexp -nocase -- {h2>Storyline</h2>(.*?)<em class="nobr">} $data -> storyline;
      regsub -all "<p>" $storyline "" storyline
      regsub -all "<.*?>" $storyline "" storyline
  }

  ### Keywords.
  foreach {null plkw} [regexp -all -nocase -inline -- {<span class="itemprop" itemprop="keywords">(.*?)</span>} $data] {
    lappend keywords [string trim $plkw]
  }
  
  ### Genre.
  foreach {null gen} [regexp -all -nocase -inline -- {<a href="/genre/.*?\?ref_=tt_stry_gnr" >(.*?)</a>} $data] {
    lappend genre [string trim $gen]
  }

  ### Language.
  foreach {null lang} [regexp -all -nocase -inline -- {<a href="/language/.*?>(.*?)</a>} $data] {
    lappend language [string trim $lang];
  }
  
  ### Country.
  foreach {null coun} [regexp -all -nocase -inline -- {<a href="/country/.*?>(.*?)</a>} $data] {
    lappend country [string trim $coun];
  }

  ### AKA.
  regexp -nocase -- {<h4 class="inline">Also Known As:</h4>(.*?)<} $data -> aka;
  regsub -all "<.*?>" $aka "" aka

  ### Technical Specs.
  regexp -- {Runtime:</h4>(.*?)</div>} $data -> runtime;
  regsub -all "<.*?>" $runtime "" runtime
  regsub -all {\s+} $runtime " " runtime
  regexp -nocase -- {<span itemprop="ratingValue">(.*?)</span>} $data -> rating;
  regexp -nocase -- {href="ratings".*?>(.*?) votes</a>\)} $data -> votes;
  regsub -all "<.*?>" $votes "" votes

  ### Top 5000
  regexp -nocase -- {<div id="meterChangeRow" class="meterToggleOnHover">(.*?)</div>} $data -> top5000;
  regsub -all "<.*?>" $top5000 "" top5000
  regsub -all "\n" $top5000 "" top5000
  regsub -all {\s+} $top5000 " " top5000

  ### Also.
  regexp -nocase -- {People who liked this also liked(.*?)<div class="rec_nav">} $data -> also_;
  if {[info exists also_] && $also_ != ""} {
      foreach {null alsol} [regexp -all -nocase -inline -- {<img height="113" width="76" alt="(.*?)"} $also_] {
            lappend alsoliked [string trim $alsol]
      }
  }
  
  ### Budget.
  regexp -nocase -- {<h4 class="inline">Budget:</h4>(.*?)<span} $data -> budget;
  regsub -all "<.*?>" $budget "" budget
  regsub -all "\n" $budget "" budget
  regsub -all {\s+} $budget " " budget

  return [list [string trim $name] $year [string trim $desc] [string trim $dir] [string trim $rel] [string range [string trim $storyline] 0 200] [join $keywords "$color1/$color2"] [join $country "$color1/$color2"] [join $genre "$color1/$color2"] [join $language "$color1/$color2"] [string trim $aka] [string trim $runtime] $rating $votes [string trim $top5000] [join $stars "$color1/$color2"] [join [lrange $alsoliked 0 5] "$color1/$color2"] [string trim $budget]];
}

proc imdb::urlencode {i} {
  variable encoding
  set index 0;
  set i [encoding convertto $encoding $i]
  set length [string length $i]
  set n ""
  while {$index < $length} {
    set activechar [string index $i $index]
    incr index 1
    if {![regexp {^[a-zA-Z0-9]$} $activechar]} {
      append n %[format "%02X" [scan $activechar %c]]
    } else {
      append n $activechar
    }
  }
  return $n
}

proc imdb::decode {content} {
  if {$content == ""} {
    return "n/a";
  }
  if {![string match *&* $content]} {
    return $content;
  }
  set escapes {
      \x20 " \x22 & \x26 &apos; \x27 – \x2D
    < \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
    ¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6
    § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
    ¬ \xAC ­ \xAD ® \xAE &hibar; \xAF ° \xB0
    ± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
    ¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA
    » \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
    À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4
    Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
    Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
    Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
    Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \xD8
    Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD
    Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2
    ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
    è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC
    í \xED î \xEE ï \xEF ð \xF0 ñ \xF1
    ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6
    ÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
    ü \xFC ý \xFD þ \xFE ÿ \xFF
  };
  set content [string map $escapes $content];
  set content [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $content];
  regsub -all -- {&#([[:digit:]]{1,5});} $content {[format %c [string trimleft "\1" "0"]]} content;
  regsub -all -- {&#x([[:xdigit:]]{1,4});} $content {[format %c [scan "\1" %x]]} content;
  regsub -all -- {&#?[[:alnum:]]{2,7};} $content "?" content;
  return [subst $content];
}

putlog "*IMDb v$imdb::version* Loaded"

V
Votex
Voice
Posts: 23
Joined: Sat Jun 21, 2014 6:52 pm

Post by Votex »

@arkadio the script you posted is not working
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Post by Gordon »

Is there eggdrop script equivalent of this https://github.com/butterscotchstallion ... iffyTitles ?

It handles more types of links but I am interested in this.
imdb handler

Queries the OMDB API to get additional information about IMDB links

imdbHandlerEnabled - Whether to show additional information about IMDB links

imdbTemplate - This is the template used for IMDB links

Default value: ^ {{Title}} ({{Year}}, {{Country}}) - Rating: {{imdbRating}} :: {{Plot}}
Post Reply