Page 1 of 1

Post Processing Script to Scan Media Folders

PostPosted: Sat Aug 25, 2012 4:27 am
by phillipah
I looked everywhere for a script that would perform the scan media folders function and I could not find anything. I knew that if you hit a specific link with subsonic it would update but there was no way to do it without logging in. So a buddy of mine wrote this. I figured I would share it. You can get the important parts of this script to run in windows as well. You will need to download wget for windows.

Code: Select all
###############################
#  SubSonic Auto Scan Script  #
#  Written by: Eli Keimig     #
#  Copyright: GPL 2012        #
###############################

#!/bin/bash

## VARIABLES ##
HOST="subsonichost"
PORT="subsonicport"
USER="subsonicusername"
PASS="subsonicpassword"
SESS="/tmp/subsonic.cookie"
CHECK1="/tmp/subsonic.check1"
CHECK2="/tmp/subsonic.check2"


## CHECK FOR OLD FILES AND CLEANUP ##
/bin/rm -f ${SESS}
/bin/rm -f ${CHECK1}
/bin/rm -f ${CHECK2}


## SCRIPT EXECUTION ##
/bin/echo ""
/bin/echo "Getting session..."
CONNECT=`/usr/bin/wget -O /dev/null -o ${CHECK1} --keep-session-cookies --save-cookies ${SESS} --post-data "j_username=${USER}&j_password=${PASS}" --no-check-certificate https://${HOST}:${PORT}/j_acegi_security_check`
/bin/echo "Updating SubSonic..."
UPDATE=`/usr/bin/wget -O /dev/null -o ${CHECK2} --keep-session-cookies --load-cookies ${SESS} --no-check-certificate https://${HOST}:${PORT}/musicFolderSettings.view?scanNow`


## BUILD ERROR ARRAY ##
ERRORCHECK1=`/bin/cat ${CHECK1} | /bin/grep "HTTP request sent, awaiting response..."`
ERRORCHECK2=`/bin/cat ${CHECK2} | /bin/grep "HTTP request sent, awaiting response..."`
ERRORARRAY=`/bin/echo -e "${ERRORCHECK1} \n${ERRORCHECK2}"`
ERRORARRAY=`/bin/echo "${ERRORARRAY}" | /bin/sed -e 's/ /BBBBBBBBBB/g'`


## CLEAR RESULT AND EXIT CODE ##
RESULT=""
ERRORCOUNT=0
EXITCODE=3


## CHECK FOR ERRORS ##
for i in ${ERRORARRAY}
do
  i=`/bin/echo "${i}" | /bin/sed -e 's/BBBBBBBBBB/ /g'`
  if [[ "${i}" != *"302 Found"* && "${i}" != *"200 OK"* ]]; then
    ERRORCOUNT=`echo $((ERRORCOUNT+1))`
  fi
done
if [[ ${ERRORCOUNT} -gt 0 ]]; then
  RESULT="SubSonic failed to update"
  EXITCODE=2
else
  RESULT="SubSonic has been successfully updated"
  EXITCODE=0
fi


## FINAL OUTPUT AND CLEANUP ##
/bin/echo "Cleaning up..."
/bin/rm -f ${SESS}
/bin/rm -f ${CHECK1}
/bin/rm -f ${CHECK2}
/bin/echo "${RESULT}"
/bin/echo ""


## EXIT ##
exit ${EXITCODE}


Re: Post Processing Script to Scan Media Folders

PostPosted: Sat Sep 01, 2012 3:04 am
by gnossdrawkcab
Could you explain how to do this? I am confused on how to use wget to run this script.

Thanks!

Re: Post Processing Script to Scan Media Folders

PostPosted: Mon Sep 10, 2012 3:26 am
by phillipah
Sure. What platform are you try to get this script working on. Linux, Windows, or OS X?

Re: Post Processing Script to Scan Media Folders

PostPosted: Wed Oct 22, 2014 5:34 am
by revjoseph
I was wondering if there was any way to get this scrip working on Linux, Ubuntu 14.04? I would love to set it as a scheduled task and update periodically.
Thanks in advanced!

Re: Post Processing Script to Scan Media Folders

PostPosted: Wed Oct 22, 2014 5:41 am
by revjoseph
revjoseph wrote:I was wondering if there was any way to get this scrip working on Linux, Ubuntu 14.04? I would love to set it as a scheduled task and update periodically.
Thanks in advanced!

Never mind! I got it executing properly last night! Thank you so much for this contributions!