Last active
August 29, 2015 14:15
-
-
Save savonarola/796c013c64d1914a68ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# Install "Perl" package via DSM Web UI | |
# | |
# Add this script to crontab: | |
# */5 * * * * root /usr/bin/perl /volume1/synology/scripts/reindex.pl /volume1/synology/download >> /root/reindex.log | |
# | |
# Then restart crond (DSM5): | |
# /usr/syno/sbin/synoservicectl --restart crond | |
use strict; | |
use warnings; | |
my $path = $ARGV[0] or die "Usage: $0 /absolute/path/for/reindex/"; | |
print "starting reindex: ".scalar(localtime())."\n"; | |
$path.= '/' unless substr($path, -1) eq '/'; | |
my $indexed_cmd = qq{/usr/syno/pgsql/bin/psql mediaserver admin -c "select path from video where path like '${path}%'"}; | |
my %indexed_files = (); | |
my @indexed_files_lines = `$indexed_cmd`; | |
foreach my $line (@indexed_files_lines) { | |
if( index($line, $path) == 1 ) { | |
chomp $line; | |
$line =~ s/^\s*//; | |
$line =~ s/\s*$//; | |
$indexed_files{$line} = 1; | |
} | |
} | |
my $present_cmd = qq{find $path}; | |
my @present_file_lines = `$present_cmd`; | |
foreach my $present_file (@present_file_lines) { | |
chomp $present_file; | |
if( $present_file =~ /(ASF|AVI|DIVX|IMG|ISO|M1V|M2P|M2T|M2TS|M2V|M4V|MKV|MOV|MP4|MPEG4|MPE|MPG|MPG4|MTS|QT|RM|TP|TRP|TS|VOB|WMV|XVID)$/i ) { | |
print "videofile found: $present_file\n"; | |
if( !$indexed_files{$present_file} ) { | |
print "$present_file is not indexed!\n"; | |
my $synoindex_cmd = "synoindex -a '$present_file'"; | |
print "launching index: $synoindex_cmd\n"; | |
system 'synoindex', '-a', $present_file; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment