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.

Save images to shell

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Save images to shell

Post by BigToe »

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?
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

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 :D

Code: Select all

# 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/

:D
Last edited by doggo on Wed Jun 27, 2012 4:50 am, edited 1 time in total.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thanks doggo, works great!
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

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?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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.. ;)
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

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

Code: Select all

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
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

How do I run that php script?
Post Reply