Initial working commit
Stripped sensitiv information
This commit is contained in:
153
piwigo_refresh.pl
Executable file
153
piwigo_refresh.pl
Executable file
@@ -0,0 +1,153 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
# author: Sebastian P.
|
||||||
|
# version: 1.0
|
||||||
|
#
|
||||||
|
# usage:
|
||||||
|
# perl piwigo_import_tree.pl
|
||||||
|
# --base_url=http://address/of/your/piwigo
|
||||||
|
# --site=site_index (default galleries=1)
|
||||||
|
# --user=your_username
|
||||||
|
# --password=your_password
|
||||||
|
# --directory=absolute path to your photos
|
||||||
|
# [--caddie=0 or 1]
|
||||||
|
# [--privacy_level=4 or 8]
|
||||||
|
# [--cat=categorie_id]
|
||||||
|
# [--subcat=0 or 1]
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
# make it compatible with Windows, but breaks Linux
|
||||||
|
#use utf8;
|
||||||
|
|
||||||
|
use File::Find;
|
||||||
|
use Data::Dumper;
|
||||||
|
use File::Basename;
|
||||||
|
use LWP::UserAgent;
|
||||||
|
use JSON;
|
||||||
|
use Getopt::Long;
|
||||||
|
use Encode qw/is_utf8 decode/;
|
||||||
|
use Time::HiRes qw/gettimeofday tv_interval/;
|
||||||
|
use Digest::MD5 qw/md5 md5_hex/;
|
||||||
|
|
||||||
|
my %opt = ();
|
||||||
|
GetOptions(
|
||||||
|
\%opt,
|
||||||
|
qw/
|
||||||
|
base_url=s
|
||||||
|
site=s
|
||||||
|
username=s
|
||||||
|
password=s
|
||||||
|
directory=s
|
||||||
|
caddie=s
|
||||||
|
privacy_level=s
|
||||||
|
cat=s
|
||||||
|
subcat=s
|
||||||
|
/
|
||||||
|
);
|
||||||
|
|
||||||
|
my $album_dir = $opt{directory};
|
||||||
|
$album_dir =~ s{^\./*}{};
|
||||||
|
|
||||||
|
our $ua = LWP::UserAgent->new;
|
||||||
|
$ua->agent('Mozilla/piwigo_refresh.pl 1.00');
|
||||||
|
$ua->cookie_jar({});
|
||||||
|
|
||||||
|
my %conf;
|
||||||
|
my %conf_default = (
|
||||||
|
base_url => 'http://localhost:81/piwigogit',
|
||||||
|
site => 1,
|
||||||
|
username => 'plg',
|
||||||
|
password => 'plg',
|
||||||
|
caddie => 0,
|
||||||
|
privacy_level => 4,
|
||||||
|
cat => 162,
|
||||||
|
subcat => 1,
|
||||||
|
);
|
||||||
|
foreach my $conf_key (keys %conf_default) {
|
||||||
|
$conf{$conf_key} = defined $opt{$conf_key} ? $opt{$conf_key} : $conf_default{$conf_key}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ua->default_headers->authorization_basic(
|
||||||
|
$conf{username},
|
||||||
|
$conf{password}
|
||||||
|
);
|
||||||
|
|
||||||
|
my $result = undef;
|
||||||
|
my $query = undef;
|
||||||
|
|
||||||
|
binmode STDOUT, ":encoding(utf-8)";
|
||||||
|
|
||||||
|
# Login to Piwigo
|
||||||
|
piwigo_login();
|
||||||
|
piwigo_refreshFolder();
|
||||||
|
piwigo_refresh();
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
# Functions
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
|
||||||
|
sub piwigo_login {
|
||||||
|
$ua->post(
|
||||||
|
$conf{base_url}.'/ws.php?format=json',
|
||||||
|
{
|
||||||
|
method => 'pwg.session.login',
|
||||||
|
username => $conf{username},
|
||||||
|
password => $conf{password},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub piwigo_refresh {
|
||||||
|
if ($conf{cat} > 0)
|
||||||
|
{
|
||||||
|
$ua->post(
|
||||||
|
$conf{base_url}.'/admin.php?page=site_update&site='.$conf{site},
|
||||||
|
{
|
||||||
|
sync => 'files',
|
||||||
|
display_info => 0,
|
||||||
|
add_to_caddie => $conf{caddie},
|
||||||
|
privacy_level => $conf{privacy_level},
|
||||||
|
sync_meta => 1,
|
||||||
|
simulate => 0,
|
||||||
|
cat => $conf{cat},
|
||||||
|
'subcats-included' => $conf{subcat},
|
||||||
|
submit => 1,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ua->post(
|
||||||
|
$conf{base_url}.'/admin.php?page=site_update&site='.$conf{site},
|
||||||
|
{
|
||||||
|
sync => 'files',
|
||||||
|
display_info => 0,
|
||||||
|
add_to_caddie => $conf{caddie},
|
||||||
|
privacy_level => $conf{privacy_level},
|
||||||
|
sync_meta => 1,
|
||||||
|
simulate => 0,
|
||||||
|
#cat => $conf{cat},
|
||||||
|
'subcats-included' => $conf{subcat},
|
||||||
|
submit => 1,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub piwigo_refreshFolder {
|
||||||
|
$ua->post(
|
||||||
|
$conf{base_url}.'/admin.php?page=site_update&site='.$conf{site},
|
||||||
|
{
|
||||||
|
sync => 'dirs',
|
||||||
|
display_info => 0,
|
||||||
|
privacy_level => $conf{privacy_level},
|
||||||
|
sync_meta => 1,
|
||||||
|
simulate => 0,
|
||||||
|
#cat => $conf{cat},
|
||||||
|
'subcats-included' => 1,
|
||||||
|
submit => 1,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
86
piwigo_thumbgen.sh
Executable file
86
piwigo_thumbgen.sh
Executable file
@@ -0,0 +1,86 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#Author: Poul Serek
|
||||||
|
|
||||||
|
shopt -s globstar
|
||||||
|
|
||||||
|
#echo "Starting Piwigo thumbnail generation"
|
||||||
|
|
||||||
|
#Remember a trailing '/'
|
||||||
|
sourceDir="$1"
|
||||||
|
destDir="$2"
|
||||||
|
|
||||||
|
echo "Source: $sourceDir"
|
||||||
|
echo "Dest: $destDir"
|
||||||
|
|
||||||
|
counter=0
|
||||||
|
fnNoExt=""
|
||||||
|
fnExt=""
|
||||||
|
fnPath=""
|
||||||
|
|
||||||
|
STARTTIME=$(date +%s)
|
||||||
|
|
||||||
|
# drop CIFS cache in case target files existed before
|
||||||
|
sync; echo 3 > /proc/sys/vm/drop_caches;
|
||||||
|
|
||||||
|
for file in "$sourceDir"/**/*.{jpg,JPG,jpeg,JPEG}
|
||||||
|
do
|
||||||
|
if [[ ! -f "$file" ]]
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $file in
|
||||||
|
*[[:space:]]*)
|
||||||
|
# replace all blanks
|
||||||
|
mv "${file}" "${file// /_}"
|
||||||
|
file=${file// /_}
|
||||||
|
echo "Space replaced: ${file}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
fnNoExt="${file%.*}"
|
||||||
|
fnExt="${file##*.}"
|
||||||
|
fnPath="${file%/*}"
|
||||||
|
fnPath="${fnPath#$sourceDir}"
|
||||||
|
fnNoExt="${fnNoExt#$sourceDir}"
|
||||||
|
|
||||||
|
#echo "${fnPath} ${fnNoExt}"
|
||||||
|
|
||||||
|
#If the medium thumbnail exists we assume that the rest also exists and skip this image
|
||||||
|
if [ ! -f "${destDir}${fnNoExt}-me.${fnExt}" ]; then
|
||||||
|
|
||||||
|
mkdir -p "${destDir}${fnPath}"
|
||||||
|
|
||||||
|
#Error checking
|
||||||
|
result=$(jpeginfo -c "$file")
|
||||||
|
if [[ $result != *"[OK]"* ]]
|
||||||
|
then
|
||||||
|
echo $result
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Auto rotate source image according to exif orientation information
|
||||||
|
orient=$(exiftool -Orientation "${file}")
|
||||||
|
if [ ! -z "${$orient##*"normal"*}" ]; then
|
||||||
|
mogrify -auto-rotate -quality 94 "${file}" #> /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
#echo "MISSING! ${destDir}${fnNoExt}-me.${fnExt}"
|
||||||
|
#Store correctly oriented base image (medium) in memory. All other thumbnails are created from this
|
||||||
|
convert "${file}" -auto-orient -thumbnail 1008x756^ -write mpr:baseline +delete \
|
||||||
|
mpr:baseline -write "${destDir}${fnNoExt}-la.${fnExt}" +delete \
|
||||||
|
mpr:baseline -thumbnail 792x594 -write "${destDir}${fnNoExt}-me.${fnExt}" +delete \
|
||||||
|
mpr:baseline -thumbnail 150x9999 -write "${destDir}${fnNoExt}-cu_s150x9999.${fnExt}" +delete \
|
||||||
|
mpr:baseline -thumbnail 144x144 -write "${destDir}${fnNoExt}-th.${fnExt}" +delete \
|
||||||
|
mpr:baseline -define jpeg:size=144x144 -thumbnail 120x120^ -gravity center -extent 120x120 "${destDir}${fnNoExt}-sq.${fnExt}"
|
||||||
|
#mpr:baseline -resize 240x240 -write "${destDir}${fnNoExt}-2s.${fnExt}" +delete \
|
||||||
|
fi
|
||||||
|
counter=$[$counter +1]
|
||||||
|
if [ $(($counter%100)) -eq 0 ]; then
|
||||||
|
ENDTIME=$(date +%s)
|
||||||
|
echo "Processed: ${counter} - Executing for $((($ENDTIME - $STARTTIME)/60)) minutes"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
chown -R www-data: ${destDir}
|
||||||
|
|
||||||
|
ENDTIME=$(date +%s)
|
||||||
|
echo "It took $((($ENDTIME - $STARTTIME)/60)) minutes to complete this task..."
|
22
piwirefresh.sh
Executable file
22
piwirefresh.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
catId=0
|
||||||
|
subCatId=1
|
||||||
|
|
||||||
|
if [ "$1" != "" ] && [ "$2" != "" ]
|
||||||
|
then
|
||||||
|
catId=$1
|
||||||
|
subCatId=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
perl -w /root/script/piwigo_refresh.pl \
|
||||||
|
--base_url=https://change.me/gallery \
|
||||||
|
--site=2 \
|
||||||
|
--user="-change me-" \
|
||||||
|
--password="-change me-" \
|
||||||
|
--directory="/var/www/piwigo/network" \
|
||||||
|
--caddie=0 \
|
||||||
|
--privacy_level=4 \
|
||||||
|
--cat=${catId} \
|
||||||
|
--subcat=${subCatId}
|
24
piwisync.sh
Executable file
24
piwisync.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
myyear=$(date "+%Y")
|
||||||
|
|
||||||
|
if [ "$1" != "" ]
|
||||||
|
then
|
||||||
|
myyear=$1
|
||||||
|
#echo Error subdir parameter missing
|
||||||
|
#exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
subDir="$myyear/"
|
||||||
|
piwigoThumbRoot="/var/www/piwigo/_data/i/network/network/${subDir}"
|
||||||
|
networkPhotoRoot="/home/network/Qbilder/photos/${subDir}"
|
||||||
|
|
||||||
|
if [ ! -e ${networkPhotoRoot} ]
|
||||||
|
then
|
||||||
|
echo "${networkPhotoRoot} not found"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
/root/script/piwigo_thumbgen.sh "${networkPhotoRoot}" "${piwigoThumbRoot}"
|
||||||
|
|
||||||
|
/root/script/piwirefresh.sh
|
Reference in New Issue
Block a user