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 

Save images to shell

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


Joined: 30 Dec 2010
Posts: 99

PostPosted: Sat Jun 16, 2012 12:05 pm    Post subject: Save images to shell Reply with quote

Hi all,

I was wondering if someone could write a script that once a .jpg / .bmp file is pasted in a chat room the eggdrop is on, the eggdrop will download that image and store it in a folder called 'images' please?
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Sat Jun 16, 2012 3:47 pm    Post subject: Reply with quote

with a few bits borrowed from http://forum.egghelp.org/viewtopic.php?t=18765

i came up with this, tested it a little and it seems to do what you want Very Happy

Code:
# 16/06/2012
# by doggo #omgwtfnzbs @ EFNET
# curl_image.tcl
#
# curl is required on the shell to use this script
# available @ http://curl.haxx.se/
#########################################################


bind pubm -|- {*://*.jpg*} curl:image
bind pubm -|- {*://*.jpe*} curl:image
bind pubm -|- {*://*.jpeg*} curl:image
bind pubm -|- {*://*.gif*} curl:image
bind pubm -|- {*://*.png*} curl:image
bind pubm -|- {*://*.bmp*} curl:image


set save_folder "/var/www/images"
set dupe_links  "/var/www/images/dupes.db"
set your_site "http://your.website.url"

proc curl:image {nick userhost handle channel str} {
global save_folder dupe_links your_site

set urlcheck(ext) {
       jpg
       jpe
       jpeg
       gif
       png
       bmp
}

if {![regexp {((?:http://|www\.)+[^ ]+)} $str str]} { return }
set extension ""
       set wlink $str
       if { [string match -nocase "*$your_site*" "$wlink"] == 1 } { return }
       regsub -all -- {(http://)+} $str "" str
       regexp {(www.)?[A-z|0-9|\-|\.|\_]*\.[A-z]{2,3}} $str host
       regexp {[/]+(.)*} $str url
       regexp {[A-z]{3,4}$} $str extension
       set ispic 0
       foreach i $urlcheck(ext) {
               if {[string match -nocase $extension $i]} {
                       set ispic 1
               }
       }

       if {$ispic != 1} { return }

       set file_name [md5 $wlink]

       set file [open $dupe_links r]
       set data [read $file]
       close $file
       set isdupe 0
       foreach line [split $data \n] {
           if { [string match -nocase "*$file_name*" "$line"] == 1 } {
               catch {unset data}
             set isdupe 1
           }
       }

       if {$isdupe == 1} { return }

       catch {exec curl $wlink -o $save_folder/$file_name.$extension}

       if {![file exists $save_folder/$file_name.$extension]} {
       return
       } else {
       set fp [open $dupe_links "a"]
       puts $fp $file_name.$extension
       close $fp
 
    }
}

putlog "curl_image.tcl loaded"


enjoy

**edit**

i like this script so i made a php script to show the images can be found at, http://pastebin.com/AP0W0YMj

results can be seen here http://doggo.is-a-geek.com/images/

Very Happy
_________________
NON geeky!! http://gotcode4u.com/


Last edited by doggo on Wed Jun 27, 2012 4:50 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Sun Jun 17, 2012 1:48 am    Post subject: Reply with quote

Thanks doggo, works great!
Back to top
View user's profile Send private message
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Tue Jun 26, 2012 7:43 am    Post subject: Reply with quote

hey doggo,

I have a problem

the bot seems to overwrite images or not save all images

I`ll show you what I mean, I have images saved in these names:

images.4chan.org.gif
images.4chan.org.jpg
images.4chan.org.png

So I suppose a better way to name the images the script is saving is using a unique name each time, or even naming the images with a counter starting from 1 so it won't repeat itself, any chance that can be changed?
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed Jun 27, 2012 1:01 am    Post subject: Reply with quote

http://forum.egghelp.org/viewtopic.php?t=16819&start=12

You might be interested in this, albeit this does not do it automatically. But this doesn't mean it cannot easily be automated, for example see "durby" (maintained by lee8oi) which is basically an automated webby as well as adding even more features. Expect the --file feature to make into "durby" shortly. Until then experiment with the --file feature webby now offers initially.. Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Wed Jun 27, 2012 4:48 am    Post subject: Reply with quote

edited the code above to use a md5 hash of the url as the filenme, should fix yr problem..
also i have added

Code:
set your_site "http://your.website.url"


to prevent duplicate images being saved when users paste the image urls from the php script i included in the bots channels
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Mon Jul 02, 2012 6:40 am    Post subject: Reply with quote

How do I run that php script?
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