Page 1 of 1

[LINUX/BASH]re-index script with synology DSM 3.0

Posted: February 19th, 2011, 6:52 am
by prometheus247
hi folks,

intro:
i tried some scripts i found on my research, to solve the following problem:
when i download something and let it automatically sorted (through SABnzbd sort function), the index of my synology diskstation will not update itself,
which leads to the issue that i just cant see the new files on my wd tv live (which uses a media DLNA share of my disk station).

i am able to start a system wide re-index out of the OS, but it will take ages (1 hour+).

what scripts i tried
i guess, this was the one that has written to achieve it, but for some reasons, neither im able to run it succesfully in the postprocess, nor through direct running:

Code: Select all

#!/usr/bin/perl

#
# Synology Media Indexer
#
# The Synology's synoindexd service will only index files if those have been copied to the media
# directory via FTP, SMB, AFP. If you move or copy media files via Telnet/SSH, the indexer is not
# aware of those, and you would have to manually reindex (which is time-consuming).
#
# This script will scan the video directory for modified files over the last two days and will then
# query the synoindex-service if the file was already indexed. If the file does not exist in the index
# database, the script will manually add it for immediate indexing.
#
# The logging component is handy, if you want to monitor when files are indexed and possibly tune your
# cronjob settings. I run the script in a cronjob every 10 minutes, which will then result in little
# overhead.
#
# I have included my most common media types in the script, but if I missed something, you are welcome
# to extend the script (and let me know what types I have missed).
#
# Usage: perl update-syno.sh /volume1/video
#
# Or add to crontab:
# */10 * * * * root perl /volume1/Extensions/scripts/update-syno.sh /volume1/video
#
# DISCLAIMER: 
#
# (C) 2010 by Gerd W. Naschenweng ([email protected] / http://www.naschenweng.info)

### Logging: Adjust the path below to the base-directory where you place the script (if you don't need logging, comment out)
use lib qw(/volume1/Extensions/scripts);
use Logging::Log;

@include_files = ("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"
);

# message of synoindex indicating that file is not indexed
# for English this is: "Failed to get MediaInfo."
# You can get the message in your locale with the following command (execute as is): synoindex -g "myfile.test" -t video
my $SYNO_ERROR_MSG = "Failed to get MediaInfo.";


## Initialise logging (comment out if you don't need it - but then also comment out the relevant sections in the code below
my $log = Logging::Log->new();
my $log = Logging::Log->new(Handle => \*F);
my $log = Logging::Log->new(File => "/var/log/media-update.log", Mode => 'append');

# pass in number the directory to scan, this will be a recursive scan
my $scan_dir = shift;

if (!$scan_dir) {
	$log->entry("No scanning directory passed, using /volume1/video");
	$scan_dir="/volume1/video/jay/Serien";
}

### Search for files which have changed during the last two days (adjust if necessary to shorter/longer intervals)
my @files = `find $scan_dir -type f -mtime -2`;
my $files_indexed = 0;

foreach (@files) {
	my $file = $_;
	chomp($file);
	my $ext = ($file =~ m/([^.]+)$/)[0];

	### Check if the file-name extension is a valid media file
	if (grep {lc $_ eq lc $ext} @include_files) {
		my $result = `synoindex -g \"$file\" -t video`;
		chomp($result);
  
		if ($result =~ m/^$SYNO_ERROR_MSG/i) {
			 $log->entry("Adding file to index: $file");
			my @synorc = `synoindex -a \"$file\"`;
			++$files_indexed;
		}
	}
}

if ($files_indexed) {
	$log->entry("Synology Media Indexer added $files_indexed new media file(s)");
 } else {
 	$log->entry("Synology Media Indexer did not find any new media");
}

# Close the log-file - remove/comment out if you disable logging
 $log->close;
it uses its own log structe, and i had to comment a line out, which made trouble while running.
the log.pm (had to rename it to log.log to get it uploaded here) is attached.

what im asking for
... is someone who can explain to me, what im doing wrong? or is there a better way how to reindex my machine?
im really stuck on this. if you say the script above is crap, i could paste another 2 scripts i tried.

thanks for any help

Re: [LINUX/BASH]re-index script with synology DSM 3.0

Posted: March 5th, 2011, 4:05 pm
by prometheus247
*push*

anybody have a clue of this ?

Re: [LINUX/BASH]re-index script with synology DSM 3.0

Posted: August 14th, 2011, 5:59 am
by wsoet
I use this small script. Maybe it helpfull for you

Code: Select all

#! /bin/ash

## Switches below are only for reference purpose. $1 is the one we need
fullpath=$1
nzbfile=$2
jobname=$3
reportnumber=$4
category=$5
newsgroup=$6

## change owner and usergroep
/bin/chown -R admin:users "$fullpath"

## Remove index if already exist
/usr/syno/bin/synoindex -D "$fullpath"

## Add index to targetfolder
/usr/syno/bin/synoindex -A "$fullpath"

echo "Mediaindex successfull at $fullpath"