Advertisement
Guest User

update-video.sh

a guest
Apr 26th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.13 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #
  4. # Synology Media Indexer
  5. #
  6. # The Synology's synoindexd service will only index files if those have been copied to the media
  7. # directory via FTP, SMB, AFP. If you move or copy media files via Telnet/SSH, the indexer is not
  8. # aware of those, and you would have to manually reindex (which is time-consuming).
  9. #
  10. # This script will scan the video directory for modified files over the last two days and will then
  11. # query the synoindex-service if the file was already indexed. If the file does not exist in the index
  12. # database, the script will manually add it for immediate indexing.
  13. #
  14. # The logging component is handy, if you want to monitor when files are indexed and possibly tune your
  15. # cronjob settings. I run the script in a cronjob every 10 minutes, which will then result in little
  16. # overhead.
  17. #
  18. # I have included my most common media types in the script, but if I missed something, you are welcome
  19. # to extend the script (and let me know what types I have missed).
  20. #
  21. # Usage: perl update-syno.sh /volume1/video
  22. #
  23. # Or add to crontab:
  24. # */10 * * * * root perl /volume1/Extensions/scripts/update-syno.sh /volume1/video
  25. #
  26. # DISCLAIMER:
  27. #
  28. # (C) 2010 by Gerd W. Naschenweng (Gerd@Naschenweng.info / http://www.naschenweng.info)
  29.  
  30.  
  31. @include_files = ("ASF","AVI","DIVX","IMG","ISO","M1V","M2P","M2T","M2TS","M2V",
  32.     "M4V","MKV","MOV","MP4","MPEG4","MPE","MPG","MPG4","MTS","QT","RM","TP","TRP","TS","VOB","WMV","XVID"
  33. );
  34.  
  35. # message of synoindex indicating that file is not indexed
  36. # for English this is: "Failed to get MediaInfo."
  37. # You can get the message in your locale with the following command (execute as is): synoindex -g "myfile.test" -t video
  38. #my $SYNO_ERROR_MSG = "Failed to get MediaInfo.";
  39. my $SYNO_ERROR_MSG = "";
  40.  
  41.  
  42. # pass in number the directory to scan, this will be a recursive scan
  43. my $scan_dir = shift;
  44.  
  45. if (!$scan_dir) {
  46.     ## $log->entry("No scanning directory passed, using /volume2/video");
  47.     ## $scan_dir="/volume2/video";
  48. }
  49.  
  50. ### Search for files which have changed during the last two days (adjust if necessary to shorter/longer intervals)
  51. my @files = `find $scan_dir -type f -mtime -5`;
  52. my $files_indexed = 0;
  53.  
  54. foreach (@files) {
  55.     my $file = $_;
  56.     chomp($file);
  57.     my $ext = ($file =~ m/([^.]+)$/)[0];
  58.    
  59.     ### Check if the file-name extension is a valid media file
  60.     if (grep {lc $_ eq lc $ext} @include_files) {
  61.         my $result = `/usr/syno/bin/synoindex -g \"$file\" -t video`;
  62.         chomp($result);
  63.        
  64.  
  65.         if ($result =~ m/^$SYNO_ERROR_MSG/i) {
  66.             ## $log->entry("Adding file to index: $file");
  67.             $dirname = substr($file, 0, rindex($file, '/') + 1);
  68.             my @synofolderrc = `/usr/syno/bin/synoindex -A \"$dirname\"`;
  69.             ## $log->entry("`/usr/syno/bin/synoindex -A \"$dirname\"`");
  70.             my @synorc = `/usr/syno/bin/synoindex -a \"$file\"`;
  71.             ## $log->entry("`/usr/syno/bin/synoindex -a \"$file\"`");
  72.             ++$files_indexed;
  73.         }
  74.     }
  75. }
  76.  
  77. if ($files_indexed) {
  78.     ## $log->entry("Synology Media Indexer added $files_indexed new media file(s)");
  79. } else {
  80.     ## $log->entry("Synology Media Indexer did not find any new media");
  81. }
  82.  
  83. # Close the log-file - remove/comment out if you disable logging
  84. ## $log->close;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement