| View previous topic :: View next topic |
| Author |
Message |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Sat Jun 16, 2012 12:05 pm Post subject: Save images to shell |
|
|
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 |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Sat Jun 16, 2012 3:47 pm Post subject: |
|
|
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
| 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/
 _________________ 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 |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Sun Jun 17, 2012 1:48 am Post subject: |
|
|
| Thanks doggo, works great! |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Tue Jun 26, 2012 7:43 am Post subject: |
|
|
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 |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Jun 27, 2012 1:01 am Post subject: |
|
|
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..  _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Wed Jun 27, 2012 4:48 am Post subject: |
|
|
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 |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Mon Jul 02, 2012 6:40 am Post subject: |
|
|
| How do I run that php script? |
|
| Back to top |
|
 |
|