Jump to content

Automate moving of movies & update XBMC library, w/WOL/Notifications/Email


joelones

Recommended Posts

Script Description

A script to move movies from a cache dir or another drive outside the array to a user share, generally after scraping meta data. The script then pings a XBMC client to determine its state (sends a WOL packet if not powered on) and issues an UpdateLibrary command to update the XBMC library on the client. It can email newly added movies to recipients and send XBMC-style notifications to running XBMC clients.

 

As of Version 0.3:

New features include the ability to update the library without requiring xbmc-send on the client. Furthermore, you can then send a XBMC style notification to various clients with a list of movies that were moved to your shares. NOTE: this assumes that you configured your XBMC clients to accept control from other programs, see the screenshot below. Finally, in a similar fashion, a list of new movies (directories) can be sent to email recipients (assuming you installed and configured the ssmtp package). This script is meant to run as a cron job or added as a button on the 'User Scripts' link in unMENU

 

Version 0.4:

Script now emails some movie meta data, i.e., plot and rating, provided you have already scraped the movie with a program like EMM-r. It looks for an .nfo with a filename similar to the directory (minus the year) and looks for a Rating and Plot tag within that file. Email body sample:

TITLE: Pirates of the Caribbean - On Stranger Tides (2011)

RATING: 6.9

PLOT: Captain Jack Sparrow (Depp) crosses paths with a woman from his past (Cruz), and he's not sure if it's love -- or if she's a ruthless con artist who's using him to find the fabled Fountain of Youth. When she forces him aboard the Queen Anne's Revenge, the ship of the formidable pirate Blackbeard (McShane), Jack finds himself on an unexpected adventure in which he doesn't know who to fear more: Blackbeard or the woman from his past.

 

 

To recap, script does:

 

Move files (from temp location to array)--> Wake XBMC if not powered On --> Update XBMC Library --> Notify clients via XBMC Notification --> Notify by email

 

I say move movies, but in reality it acts as generic mover script as longer as you specify both a source and target directory.

 

This script applies to you if:

  • You are using a drive outside your array to process movies prior to moving them to your user share
  • You are running a linux XBMC client (really any client should work)
  • You do the following actions repeatedly: scrape movie, move movie, update XBMC library, repeat

 

Reason for Script:

Note: I understand that XBMC can be set to update its library on boot up (or on resume) by itself, however, with 2000+ movies the process could be rather long each time you start your client when you haven't added any movies. Personally, I prefer not updating on startup but rather updating the library at specific times, generally some time in the A.M. through a cron job. This script serves really two uses, 1) moves movies from a temporary directory to another (in the array), and 2) as described, it updates the XBMC library so I won't have to on each startup. The added bonus is that it emails newly copied movies to a recipient list and sends notifications if your XBMC clients are running.

 

Assumptions:

  • Single movies are stored under a single folder with the naming convention, 'Movie Name (Year)'
     

 

Included Files:

  • XBMCLU.sh (main script, developed by me)
  • wol.py (Python script for wake on lan functionality, not developed by me)
  • xbmc-send (to communicated with your XBMC client, not developed by me)
  • xbmcclient.py (need by xbmc-send, not developed by me)
  • add_xbmclu_cron_job.sh (script that updates root's crontab for nightly execution of XBMCLU.sh, not developed by me)

 

Dependencies:

  • a unRAID server
  • a XBMC client (with "Allow programs on other systems to control XBMC" turned on)
    screenshot20110607at827.png
     
  • wol.py script (supplied with this script)
  • xbmc-send (supplied with this script)
  • xbmcclient.py (supplied with this script and required by xbmc-send)
  • ssmtp package installed and configured if you want email notifications (please see the appropriate package in unMENU for installation and config)

 

Installation:


  • Copy the main script XBMCLU.sh, wol.py, xbmc-send, xbmcclient.py and add_xbmclu_cron_job.sh in a directory of your choosing, then set the SCRIPT_DIR variable in the main script accordingly.
     
     

  • Decide what functionality you want
     
     
  • Do I want the script to move files from a temporary drive to the array? If so:
    - Set MOVE_FILES to "true"
    - Specify at minimum one source and target dir, you may add more separate each with spaces.
    - Ex: MOVE_SOURCES=( /mnt/disk/downloads/HD ) MOVE_TARGETS=( /mnt/user/movies/HD )
    This will move all directories under /mnt/disk/downloads/HD to /mnt/user/movies/HD. Note: this script assumes that folders under the source directory are in the form "/source_dir/Movie Name (Year)"
     
     
     
  • Do I want the script to wake the XBMC client for which you will run the library update on? If so:
    - Set WAKE_XBMC_CLIENT to "true"
    - Specify the hostname or IP of the client in WAKE_HOST along with its MAC address in WAKE_HOST_MAC (in form 00:00:00:00:00:00)
     
     
     
  • Do I want the script to run the UpdateLibrary command on the host in part ii)?
    - Set UPDATE_XBMC_LIBRARY to "true"
     
     
     
  • Do I want the script to notify additional XBMC clients, besides WAKE_HOST?
    - Set NOTIFY_XBMC_CLIENTS to "true"
    - Add addition clients in NOTIFY_HOSTS
     
     
     
  • Do I want the script to notify people via email of new directories copied to your share (required: ssmtp package in unMENU installed and configured)?
    - Set EMAIL_RECIPIENTS to "true"
    - At minimum add one email address to EMAIL_TO
     
     
     
  • Setup the cron job (currently set for 2:00am everyday)
    - Copy add_xbmclu_cron_job.sh to SCRIPT_DIR
    - Modify add_xbmclu_cron_job.sh so that it points to  /SCRIPT_DIR/XBMCLU.sh
    - Add the following line to the go script /SCRIPT_DIR/add_extra_cron_jobs.sh for reboot
     
     

 

Disclaimer:

I am by no means a stellar programmer, I take no credit for any other programs but XBMCLU.sh, use at your own risk.

XBMCLU_v0.4.zip

Link to comment
  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...