Skip to content

Automatically sort media files on a WD My Cloud NAS with Incron

License

Notifications You must be signed in to change notification settings

SylvainRX/WDMyCloud-MediaSorter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Automatically sort media files on a WD My Cloud NAS with Incron

Introduction

WD My Cloud is a NAS with a web access provided by Western Digital. As it is, it is a great storage device for your media center (eg : https://kodi.tv/), but it can become a repetitive task to find the right path in which to store each newly downloaded TV show episode or movie in your library. However, the My Cloud runs under a modified version of Debian, so it can be tweaked to suit our needs. This tutorial shows how we can add a feature to automatically sort any media files dropped into a given directory to their right path in the library.

The library handled by the sorting scripts must be organized as follow : /path/TV Shows/[tv show title]/[Season x]/[media files] /path/Movies/[movie title]/[media files]

Incron provides possibility to simply monitor various events on files in filesystems and will be use to trigger our sorting script. http://inotify.aiken.cz/?section=incron&page=about

Disclaimer

Any modification you may make using SSH to log into your WD My Cloud may break it and void its warranty. I am not responsible for any issues you may encounter through this process. This tutorial only exists for its informative purpose.

The firmware version on the WD My Cloud that has been used for this project is v04.04.02-105 and this setup won't function on earlier builds.

Setup

Step 1 : Enable SSH access to My Cloud

Before doing any modification, you must make sure they won't be erased by the next automatic firmware update. To do so, go in your web browser, open your My Cloud web interface (http://wdmycloud.local) and log in. Then, toggle off : Settings>Firmware>Auto Update>Enable Auto Update

From that same page, you must enable SSH access : toggle on : Settings>Network Services>SSH

Then from your terminal :

The default password is welc0me, you should change it once you are logged in.

Step 2 : Install Incron and its dependencies

Before executing the following lines, read the last section of this file. In your terminal, SSH as root in your My Cloud :

git clone git://github.com/SylvainRX/WDMyCloud_MediaSorter.git
chmod -R 700 WDMyCloud_MediaSorter
cd WDMyCloud_MediaSorter/incron_bin
./install.sh

Step 3 : Setup the file sorting script

As root in your My Cloud, create a directory under "/shares/YourShare/repository" which will be the repository for the sorting script :

mkdir /shares/YourShare/repository
mkdir /shares/YourShare/repository/.trash
chmod -R 777 /shares/YourShare/repository

Any new files that are added to the repository will be handled and sorted by the sorting script.

Then create a directory to put in the script files :

mkdir /root/.incron
cd ../sortmedia_scripts
mv * /root/.incron
cd ../..
rm -rf WDMyCloud_MediaSorter

You need to edit sortmedias.sh in order to specify where are your TV show and movie libraries :

nano /root/.incron/sortmedias.sh

Edit the following lines in the opened file so the paths are right :

PATH_TVSHOWS='/shares/YourShare/TV_Shows'
PATH_MOVIES='/shares/YourShare/Movies'
PATH_TRASH='/shares/YourShare/repository/.trash'

Save and exit.

Finally, you need to set up incron to watch for events happening in your repository :

incrontab -e

Add the following line in the opened file :

"/path/to/your/repository" IN_CREATE,IN_MOVED_TO,IN_ISDIR "/path/to/this/script/sortmedias.sh" $# $@ $% $&

Save and exit.

Make sure incron is running :

/etc/init.d/incron start

Your WD My Cloud should now be able to sort any files or directory of files dropped into /shares/YourShare/repository. You can further edit sortmedias.sh to specify a directory in which to write a log file and a trash directory to move unsorted files into.

Make it better with Transmission

I created this sorting script in a way that in can be used with the bittorrent client Transmission. Transmission can set the downloaded files into the sorting repository to have them sorted automatically.

To start a download on your remote tranmission client, you can either send magnet links or torrent through its web UI (http://wdmycloud.local:9091/transmission/web/) or using an extension for your browser (I personnally use this one with Chrome : https://github.com/bogenpirat/remote-torrent-adder).

If you wish to install Transmission, you can uncomment the last lines in install.sh before executing it. However, prior to installation, you will want to create a new user "debian-transmission" via the web ui (http://wdmycloud.local/UI/) and grant it full access to the shares directory.

Then you need to set up Transmission : start by stopping transmission-deamon, then create a new directory for incomplete downloads.

/etc/init.d/transmission-daemon stop
mkdir "/shares/YourShare/repository"
mkdir "/shares/YourShare/repository/.transmission"

Edit /var/lib/transmission-daemon/info/settings.json and set the parameter as follows, adapting the path to your own system :

"incomplete-dir": "/shares/YourShare/repository/.transmission",
"incomplete-dir-enabled": true,
"rpc-authentication-required": false,
"rpc-enabled": true,
"rpc-port": 9091,
"rpc-url": "/transmission/",
"rpc-username": "",
"rpc-whitelist": "127.0.0.1,192.168.0.*",
"rpc-whitelist-enabled": true,

Finally, restart transmission :

/etc/init.d/transmission-daemon start

You can now start downloads with transmission and have all those files sorted for you.

Thanks in advance for any feedback or informations about issues you may have encountered.

About

Automatically sort media files on a WD My Cloud NAS with Incron

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages