====== Synology DiskStation ====== ===== Overview ===== * Synology Website: www.synology.com * Current Firmware for [[http://www.synology.com/support/download.php?lang=enu&m=DS-106j|DS-106j]]: DSM 2.1-0839; Build Date: 2009/03/25 ===== Tweaking iTunes Music Indexing ===== * Activate iTunes Service * Login to the DiskStation using telnet or ssh * Remove music folder: rm /volume1/music * Symlink the folder to your favorite location: ln -s /volume1/public/my_music /volume1/music * Re-run the indexer to manually update the index: synoindex -A /volume1/music Make sure not to put a slash (/) at the end of the path! ''synoindex -A /folder'' is not the same as ''synoindex -A /folder/''. Read below for more information on ''synoindex''. The index is only kept up to date as long as you use Synology's "official" interfaces (ftp, smb, etc.) for adding/removing media files. Whenever you add/remove files manually using the command line you have to fix the index using ''synoindex''. ===== Synology Indexing ===== The meta information of media files (music, photos, videos etc.) is kept in a database that is updated automatically by ''synoindexd''. The database is PostgreSQL and can be found at ''/volume1/@database''. The indexing daemon can be manipulated from the command line by ''synoindex''. ==== Index database ==== To access the database use the following command: DiskStation> /usr/syno/pgsql/bin/psql mediaserver admin Welcome to psql 8.2.5, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit mediaserver=# To list all tables type mediaserver=# \dt List of relations Schema | Name | Type | Owner --------+-----------+-------+------- public | directory | table | admin public | music | table | admin public | photo | table | admin public | playlist | table | admin public | video | table | admin (5 rows) To show the contents of the music table type select * from music; To quit type \q ==== synoindex ==== Copyright (c) 2003-2008 Synology Inc. All rights reserved. usage: Add: synoindex -a filename Delete: synoindex -d filename Add folder: synoindex -A folder Delete folder: synoindex -D folder Rename/move file/folder: synoindex -N newfullpath oldfullpath Update Photo Images: synoindex -U photo Get from DB: synoindex -g filename -t [video|music|photo|playlist] Additionally there is another undocumented option -R: synoindex -R [video|music|photo|playlist|all] It seems to re-index the given table but I am not sure what it does exactly. If you removed or renamed a folder from the console and want to fix the index the ''-R'' option doesn't help you. In that case you have to delete the old folder using ''-D'' and then add the new folder using ''-A''. When deleting a folder make sure not to add a trailing slash (/) to the path! To remove the index from all files in the music share type: synoindex -D /volume1/music ==== Orphans in the database ==== Whenever you rename or move files manually using the console the database still contains information to these files which is no longer valid. This is especially annoying when you rename files or folders and then run ''synoindex -A /your_folder'' to update the database. The information for the renamed files will then be added a second time to the database. In iTunes the files will show up twice but only one link (the new one) will still work. Unfortunately ''synoindex -R'' does not remove entries for files from the database that do no longer exist. The only way to fix this is to use ''synoindex -D'' on the old folder and then re-index using ''synoindex -A''. The following script queries all files from the music database and verifies if the file still physically exists. If not a message is printed to STDOUT. If started with ''-f'' the script also removes these files from the index database. Usage: ./remove_orphans.sh [-f] #!/bin/sh # Usage: ./remove_orphans.sh [-f] [ "$1" = "-f" ] && REMOVE=1 IFS=' ' for db in music video photo; do for testfile in `/usr/syno/pgsql/bin/psql mediaserver admin -tA -c "select path from $db;"`; do if [ ! -f "$testfile" ]; then echo "MISSING: $testfile" [ -n "$REMOVE" ] && synoindex -d "$testfile" fi done done