Synology – automatic indexing via synoindex

  • Pingback: Infographic - most popular content | naschenweng.info()

  • Xavier

    Hi,
    Gret idea but how to install it?
    How this can be extended to all directory (music, photo, video, doc…
    Thanks to the one who can help me on this

    • Have a look at the script itself – has all the instructions and you can adjust it to extend it to other dirs too.

  • Xavier

    I get this error when I run the script.
    No idea if the script indexed the files or not.
    Can’t call method “entry” on an undefined value at update-syno.sh line 80
    Any idea what needs to be corrected.?
    Thx

    • When you open the script you need to adjust the path on line 31 to where you placed the Logging folder:
      use lib qw(/volume1/Extensions/scripts);

  • GL

    Hi Gerd,

    Thanks for the great script. I just tested it out on the command line and it quickly addeda couple of new movie files that I copied over a mounted NFS from Fedora.

    One change I had to make was to comment out all the logging as I was getting the following error:
    Can’t locate Logging/Log.pm in @INC (@INC contains: /volume1/Extensions/scripts /usr/lib/perl5/5.8.6/MARVELL_88F6281 /usr/lib/perl5/5.8.6 /usr/lib/perl5/site_perl/5.8.6/MARVELL_88F6281 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl .) at update-syno.sh line 32.
    BEGIN failed–compilation aborted at update-syno.sh line 32.

    Did you have to do any additional configuration or did you have to install the logging module?

    perl -v
    This is perl, v5.8.6 built for MARVELL_88F6281

    • When you open the script you need to adjust the path on line 31 to where you placed the Logging folder:use lib qw(/volume1/Extensions/scripts);

      • Xmg67fr

        Thank you Gerd,
        Well I commented all looging references but now this is what I get :
        perl update-syno.sh /volume1/video
        WARNING:  nonstandard use of \ in a string literal
        LINE 1: … * FROM video WHERE fs_online = ‘t’ AND path like ‘/volume1/…
                                                                     ^
        HINT:  Use the escape string syntax for backslashes, e.g., E’\’.
        WARNING:  nonstandard use of \ in a string literal
        LINE 1: … * FROM video WHERE fs_online = ‘t’ AND path like ‘/volume1/…
                                                                     ^
        HINT:  Use the escape string syntax for backslashes, e.g., E’\’.
        WARNING:  nonstandard use of \ in a string literal
        LINE 1: … * FROM video WHERE fs_online = ‘t’ AND path like ‘/volume1/…
                                                                     ^
        HINT:  Use the escape string syntax for backslashes, e.g., E’\’.
        Can’t call method “entry” on an undefined value at update-syno.sh line 82.I am really lost and not a professional on this.Sorry. Little help would be welcome

  • Pingback: Sync iTunes music & playlists with Synology Diskstation « tech.log()

  • chris

    great script.
    Only a little problem with the @eadir:disqus  folders. but very nice!

    thx a lot.chris

  • Michael Moser

    HI – I found this page via Google since I was searching for a solution to automatically reindex my photo collecdtion whenver I add or modify something. Seems like what I was looking for.
    I may be missing the obvious, but where can I get or download that script that is mentioned here. I didn’t find a reference nor a download option on this page.

    Michael

    • Joakim

      The link has a greenish hue, in the second paragraph. darn hard to see: “Synology Media Indexer”

      • Michael Moser

        Aah! I really hadn’t noticed that before! Now that you “press my nose onto it” I finally see it.
        Thanks!

  • Rik

    Looks great! Took some time to experiment in Putty, but after commenting out the logging the errors stopped 🙂 and everyting looks to be running! Thanks!

  • Wout

    Hello,

    This looks like a fantastic script. The thing is, I am a complete n00b that doesn’t even know what a script exactly is. I read your other comments and apparently the instructions are in the text in the script itself, but I didn’t find them. I googled ‘how to use a script’ but this doesn’t really help me as well. I even tried to put the .sh file in Mac os X automator. I selected run shell script added the .sh file and clicked run, but that doesn’t work. I am pretty sure that there are more n00bs like me that would like to use this but don’t have a clue.

    Any chance anyone could put this script in a downloadable automator file, so I can run it in automator?

    I didn’t try just copying the script and the log file to my synology disk yet, but I can’t imagine that this would do the trick, right??

    I apoligize for my stupidity, but any help would be much appreciated!!

    Wout

  • Sanne

    Hi Gerd,

    Thanks for the script. I’ve trying to make it work, but I’m also having problems with errors. First I also had the logging errors on line 32 so I commented lines 31, 32, 45, 46 & 47. Now it says: Can’t call method “entry” on an undefined value at update-syno.sh line 82.

    Any ideas?

  • Jeremy Fisher

    I’d love to use this script, I’ve enabled Telnet on my NAS, have logged in using Terminal on my Mac, but now what?! I’m a complete noob at this and I just don’t know what the next step is… I’ve Googled as much as I can in various forums but I’m still very unsure… is there a step-by-step guide that will show me how to run/install this script on my Nas? As I’m using CouchPotato and SickBeard, I have to manually re-index all my media and it takes hours on my 410J!

    Any help would be VERY appreciated….

    Thanks in advance…
    Jeremy

  • Anthony

    THis is great and I’ve edited to handle my music directory. In fact I’m going to edit the script to handle the /video/, /music/ and /photo/ directories.

    However, is there something else that needs to be done after running the script? I copied a folder with some MP3s into my /music/ folder. I ran the script and the log said that it added the MP3s. However, if I log into Audio Station the newly added folder doesn’t show up.

    Can you think of why this is happening? Do I need to restart the indexer or something?

    Thanks Again!

    Anthony

    • Rob

      I am having this same problem… It seems that the script will index new files but somehow won’t index new folders. So it will index the files inside a new folder, but the folder hasn’t been indexed so the files can’t be accessed from a DLNA client. Would love to see a solution for this

      • Rob

        I think I found a solution… I went through the script and discovered that synoindex -a “filename” will index a file for the DLNA server, but you also need to index the new folder beforehand using the -A flag. Not sure if this solution is the best fix, but I modified the section under “### Check if the file-name extension is a valid media file” to the following:

        OLD
        —————-
        if ($result =~ m/^$SYNO_ERROR_MSG/i) {
        $log->entry(“Adding file to index: $file”);
        my @synorc = synoindex -a "$file";
        ++$files_indexed;
        }

        NEW
        —————-
        if ($result =~ m/^$SYNO_ERROR_MSG/i) {
        $log->entry(“Adding file to index: $file”);
        my @synofolderrc = synoindex -A "substr($file, 0, rindex($file, '/') + 1)";
        my @synorc = synoindex -a "$file";
        ++$files_indexed;
        }

        • Nasser

          Thanks, I will try this. I have worked around this by just adding the folder through filestation, which is of course a bit beside the point of this script.

        • Ambrož Salobir

          This is not working for me 🙁

  • Joshua

    Hi,
    How do you install this script?
    I can’t get it to work.

    Thanks.
    Josh.

    • goudkamp

      Open the script, installation instructions are there:

      # Usage: perl update-syno.sh /volume1/Video
      ## Or add to crontab:
      # */10 * * * * root perl /volume1/Extensions/scripts/update-syno.sh /volume2/Video

  • Andy

    I upload photos using rsync. Your script is very useful. Thanks!!

  • martijn

    is there a way to make this into a installable and (easily) customizable package? because if you dont have any scripting knowledge (like me), installing this probably won’t end well. or, perhaps a noobies guide to installing this script, step by step? because the instructions in the script might as well have been greek to me 🙂

    thanks in advance for any effort put in 🙂

    • Hi there, unfortunately not. The installation is fairly simple where you create a folder, unzip the content of the file and then create a cronjob. The script itself has some documentation describing it.

      • martijn

        the problem is pretty basic, i do not know where to start. for instance, what is a cronjob?

  • abc

    Hi,

    Thank you for this job, it works perfectly and solve at last my problem!

    Just one question : would it be hard to implement in PERL (that I don’t practice) to remove from the index the files that are deleted from the DS. For example, I remove one AVI file using a NFS connexion, the indexer does not see it, it leaves the AVI reference in the index, but no file exist anymore. Is it possible to pass through all the index lines and check if file still exists ?

    Many thanks

  • Mihai

    apparently the issue is with the postgres database behind the indexing service. I had two problems with it: first, I had disabled shell access to the admin user. The start scripts apparently use that user to start the database – the /var/log/pgsql.startup.log file showed that it was attempting to use the shell and it couldn’t. Solution: reenabled shell access to admin user. Second, the access rights to the config files were assigned to the root, not to admin. After trying to start again the NAS, the same /var/log/pgsql.startup.log showed pg_ctl: another server might be running; trying to start server anyway
    FATAL: lock file “/var/tmp/postmaster.pid” already exists
    HINT: Is another postmaster (PID 5340) running in data directory “/var/services/pgsql”?
    pg_ctl: could not start server
    Examine the log output.

    I killed the process, removed the pid and the database and tried to start the whole thing again, but now it was complaining about access rights to its config files. Simply follow the error messages and make sure that it can read everything.

    now everything is seen in both audio station and video station! yay!

  • I tried this out today and have a problem. Even though the file in question was added to the index, as evidenced by a normal return after executing the “synoindex -g filename” command, the file did NOT show up in my DLNA client.

    This was a file that had been entered into a previously non-existent directory and I see from other notes that this may be a problem. If so, is there a fix?

    After executing the “synoindex -R video” command, the folder (and the new file) do show up.

    • Rob

      Try this:

      I think I found a solution… I went through the script and discovered that synoindex -a “filename” will index a file for the DLNA server, but you also need to index the new folder beforehand using the -A flag. Not sure if this solution is the best fix, but I modified the section under “### Check if the file-name extension is a valid media file” to the following:

      OLD
      —————-
      if ($result =~ m/^$SYNO_ERROR_MSG/i) {
      $log->entry(“Adding file to index: $file”);
      my @synorc = synoindex -a "$file";
      ++$files_indexed;
      }

      NEW
      —————-
      if ($result =~ m/^$SYNO_ERROR_MSG/i) {
      $log->entry(“Adding file to index: $file”);
      my @synofolderrc = synoindex -A "substr($file, 0, rindex($file, '/') + 1)";
      my @synorc = synoindex -a "$file";
      ++$files_indexed;
      }

      • Master Acid

        Hi,
        I modified the code to this:

        if ($result =~ m/^$SYNO_ERROR_MSG/i) {
        $log->entry(“Adding to index:”);
        $dirname = substr($file, 0, rindex($file, ‘/’) + 1);
        my @synofolderrc = synoindex -A "$dirname";
        $log->entry(“synoindex -A "$dirname"“);
        my @synorc = synoindex -a "$file";
        $log->entry(“synoindex -a "$file"“);
        ++$files_indexed;
        }

        Inserted 2 more log enrties for the easier debugging … certainly they can be deleted.
        Now it’s working fine. Thank you!

  • Stefijn Kerkhoff

    Have been playing with this and it seems to work. Meaning: no errors. However, in the log I only see

    Mar 26 2013 19:48:40 MOD_MESG [::13338] Synology Media Indexer did not find any new media

    I have set the script to look to -10 day old files and there are files that match, I know that. What could be the problem? (FIXED)

    And, is it possible (and how) to start this script from the new taskscheduler?

  • Dogward

    Hi !

    I’ve “installed” your script, and commented out the logging (since I had the error on line 99), anyway, when I run the script, it seems to run fine (quite quickly in fact), but my files are not indexed.

    Could you please help me a bit ? I would greatly appreciate. I am on DSM 4.2.

    Thanks for anyhelp you could provide and for you script.

    • Dogward

      Just for info… after 4 month of “battleing” and messing around with
      your script, I’ve finally managed to have it work. It is quite usefull.
      Thanks for the script.

      It turns out that (between many
      other things) I had to make a minus 60 days to have some files indexed I
      dont know why (they are 3 days old at most)…

      Anyone needing help with this, do not hesitate contacting me.

      • Helmeczi Robert

        Hi Dogward,

        I have same problem (error online 99)
        Could you share me your script?
        Best regards,

        Robert

  • Eric

    Where is the script?

    • Dogward

      2nd paragraph, 6th, 7th and 8th words 😉 The link is greenish

  • Benm7

    Hi there, I have installed this script in my Videos folder and it runs great so thanks very much!

    However I want it to run periodically, say every 10mins, and it only appears to run when i invoke the command via CLI. Can you please advise the simplest way to have this script run frequently? If this is too frequent for my DS212j to handle, I could get away with running it daily or every few hours if need be.

    PS. I have no experience with Perl or Crontab or anything like that 🙂

  • g77

    and what about :
    my @files = find $scan_dir -type f -ctime -2 -L;

  • g77

    I mean changing mtime by ctime

  • Javon

    This message is for dogward. Can you work with me on the script you used in order to get the synology to index the files automatically. My email is [email protected]

  • Hasenpaar

    I believe “synoindex -g” no longer provides any output, it also is no longer documented, so nothing is indexed.

    Also manually running synoindex -a didn’t really work for me. 🙁

  • Tiron

    Any hint what the synoindex -g was for? As it is not longer supported I wonder what to use instead…

  • NiNjA

    Thanks for this script, does anyone have a working version that works on DSM 5.2 with a workaround for “synoindex -g” no longer being a valid argument?

  • Benoit Morange

    need help , because non of these are working here, i m on DSM 6…
    can’t find a way to add my music, i tried to index the folder 1rst synoindex -A Folder, then the files with -a … but still nothing visible in audiostation 🙁