2 use vars qw($VERSION %IRSSI);
8 command_bind settings_get_str settings_add_str timeout_add server_find_chatnet
13 authors => 'Tuomas Kulve',
14 contact => 'tuomas@kulve.fi',
15 name => 'Print URLs for new photos',
16 description => 'This script polls for new images' .
17 'and prints their URLs and meta information' .
19 license => 'Public Domain',
24 my ($dir_in, $dir_public, $file) = @_;
26 if (!rename("$dir_in/$file", "$dir_public/$file")) {
27 print "Failed to rename $dir_in/$file to $dir_public/$file: $!";
31 my $filename = "$dir_public/$file";
33 if (! -f "/usr/bin/exiftool") {
34 print "No exiftool, cannot get image details";
38 my $cmd = "exiftool -f -s -s -s -t -c %.6f -ObjectName -Description -GPSPosition -Subject $filename";
43 # Add EXIF info to IRC message
44 if (!open(EXIF, "$cmd |")) {
45 print "Failed to run exiftool: $!";
53 my @data = split("\t", $exifout);
57 if ($data[0] ne "-") {
58 $exifmsg .= "$data[0]: "
62 if ($data[1] ne "-") {
63 $exifmsg .= "$data[1]. "
67 if ($data[3] ne "-") {
68 $exifmsg .= "\[$data[3]\] "
72 if ($data[2] ne "-") {
73 $exifmsg .= "($data[2]) "
79 # Append public http URL
80 my $url_prefix = settings_get_str('photos_url_prefix');
81 $msg .= "$url_prefix/$file";
83 # Send IRC message to appropriate channel
84 my $networkname = settings_get_str('photos_notify_server_name');
85 my $ircserver = server_find_chatnet($networkname);
86 if (defined $ircserver) {
87 my $channel = settings_get_str('photos_notify_channel');
88 $ircserver->command("/msg -channel $channel $msg");
90 print "Failed to find server '$ircserver' in network '$network'";
98 my $dir_in = settings_get_str('photos_dir_incoming');
99 my $dir_public = settings_get_str('photos_dir_public');
102 print "Invalid incoming photos dir: $dir_in";
106 if (! -d $dir_public) {
107 print "Invalid public photos dir: $dir_public";
111 if (!opendir(DIR, $dir_in)) {
112 print "Can't opendir $dir_in: $!";
117 while (defined ($file = readdir(DIR))) {
118 my $filename = "$dir_in/$file";
120 # TODO: what about videos? Or other non-image files.
121 if (-f "$filename") {
123 my $date_string = stat($filename)->mtime;
124 my $diff = $now - $date_string;
126 # Try to ensure that the whole image is there instead of moving
127 # a file that's still being copied.
129 handle_photo($dir_in, $dir_public, $file);
138 # Edit this to match your command line in the sharing-cli plugin
139 settings_add_str('photos', 'photos_dir_incoming',
140 "$ENV{HOME}/photos_incoming");
141 # Edit this to be your public www-directory name
142 settings_add_str('photos', 'photos_dir_public',
143 '$ENV{HOME}/~public_html/');
144 # Edit this to match your IRC network name
145 settings_add_str('photos', 'photos_notify_server_name',
146 'NAME_OF_YOUR_IRC_NETWORK');
147 # Edit this to match your IRC channel
148 settings_add_str('photos', 'photos_notify_channel',
149 '#CHANNEL_NAME_HERE');
150 # Edit this to match your www address
151 settings_add_str('photos', 'photos_url_prefix',
152 "http://WWW.DOMAIN.COM/~$ENV{USER}/");
154 # Let's poll for new images every 30 secs
155 timeout_add(30 * 1000, "timeouttest", "");