egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IMDB script question

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Gordon
Voice


Joined: 04 Apr 2007
Posts: 33

PostPosted: Sun Sep 15, 2013 12:13 pm    Post subject: IMDB script question Reply with quote

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.
Back to top
View user's profile Send private message
CrazyCat
Master


Joined: 13 Jan 2002
Posts: 476
Location: France

PostPosted: Tue Sep 17, 2013 2:42 am    Post subject: Reply with quote

Well, it exists for youtube so I think you can do it easily.
_________________
http://www.eggdrop.fr - French speaking IRC network
Back to top
View user's profile Send private message Visit poster's website
Gordon
Voice


Joined: 04 Apr 2007
Posts: 33

PostPosted: Tue Sep 17, 2013 3:54 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3403
Location: Area 51

PostPosted: Tue Sep 17, 2013 9:36 am    Post subject: Reply with quote

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.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
Gordon
Voice


Joined: 04 Apr 2007
Posts: 33

PostPosted: Tue Sep 17, 2013 11:46 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
CrazyCat
Master


Joined: 13 Jan 2002
Posts: 476
Location: France

PostPosted: Wed Sep 18, 2013 8:46 am    Post subject: Reply with quote

I think you want something like (really simple):
Code:
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
}

_________________
http://www.eggdrop.fr - French speaking IRC network
Back to top
View user's profile Send private message Visit poster's website
Gordon
Voice


Joined: 04 Apr 2007
Posts: 33

PostPosted: Wed Jul 29, 2015 10:06 am    Post subject: Reply with quote

Can someone post complete script?

I cannot make it work (tcl knowledge less than limited).
Back to top
View user's profile Send private message
arkadio
Voice


Joined: 13 Dec 2013
Posts: 6

PostPosted: Tue Sep 01, 2015 6:20 pm    Post subject: Reply with quote

Code:

# 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 {
    &nbsp; \x20 &quot; \x22 &amp; \x26 &apos; \x27 &ndash; \x2D
    &lt; \x3C &gt; \x3E &tilde; \x7E &euro; \x80 &iexcl; \xA1
    &cent; \xA2 &pound; \xA3 &curren; \xA4 &yen; \xA5 &brvbar; \xA6
    &sect; \xA7 &uml; \xA8 &copy; \xA9 &ordf; \xAA &laquo; \xAB
    &not; \xAC &shy; \xAD &reg; \xAE &hibar; \xAF &deg; \xB0
    &plusmn; \xB1 &sup2; \xB2 &sup3; \xB3 &acute; \xB4 &micro; \xB5
    &para; \xB6 &middot; \xB7 &cedil; \xB8 &sup1; \xB9 &ordm; \xBA
    &raquo; \xBB &frac14; \xBC &frac12; \xBD &frac34; \xBE &iquest; \xBF
    &Agrave; \xC0 &Aacute; \xC1 &Acirc; \xC2 &Atilde; \xC3 &Auml; \xC4
    &Aring; \xC5 &AElig; \xC6 &Ccedil; \xC7 &Egrave; \xC8 &Eacute; \xC9
    &Ecirc; \xCA &Euml; \xCB &Igrave; \xCC &Iacute; \xCD &Icirc; \xCE
    &Iuml; \xCF &ETH; \xD0 &Ntilde; \xD1 &Ograve; \xD2 &Oacute; \xD3
    &Ocirc; \xD4 &Otilde; \xD5 &Ouml; \xD6 &times; \xD7 &Oslash; \xD8
    &Ugrave; \xD9 &Uacute; \xDA &Ucirc; \xDB &Uuml; \xDC &Yacute; \xDD
    &THORN; \xDE &szlig; \xDF &agrave; \xE0 &aacute; \xE1 &acirc; \xE2
    &atilde; \xE3 &auml; \xE4 &aring; \xE5 &aelig; \xE6 &ccedil; \xE7
    &egrave; \xE8 &eacute; \xE9 &ecirc; \xEA &euml; \xEB &igrave; \xEC
    &iacute; \xED &icirc; \xEE &iuml; \xEF &eth; \xF0 &ntilde; \xF1
    &ograve; \xF2 &oacute; \xF3 &ocirc; \xF4 &otilde; \xF5 &ouml; \xF6
    &divide; \xF7 &oslash; \xF8 &ugrave; \xF9 &uacute; \xFA &ucirc; \xFB
    &uuml; \xFC &yacute; \xFD &thorn; \xFE &yuml; \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"

Back to top
View user's profile Send private message
Votex
Voice


Joined: 21 Jun 2014
Posts: 23

PostPosted: Fri Sep 18, 2015 9:58 am    Post subject: Reply with quote

@arkadio the script you posted is not working
Back to top
View user's profile Send private message
Gordon
Voice


Joined: 04 Apr 2007
Posts: 33

PostPosted: Mon Feb 15, 2016 3:02 pm    Post subject: Reply with quote

Is there eggdrop script equivalent of this https://github.com/butterscotchstallion/limnoria-plugins/tree/master/SpiffyTitles ?

It handles more types of links but I am interested in this.
Quote:
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}}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber