PDA

View Full Version : Script for Tivoserver



snake98
02-18-2010, 02:45 PM
I've written a script for tivoserver to help migrate to Media center, but still be able to use tivoserver. What this does is shorten names and works with sub directories to get rid of them by making symbolic links. I run my tivoserver in vmware so it run on ubuntu which in turns runs on my windows 7 home media center. Guess the best way is by example. Here is a layout

current layout
\shows\Friends\#Friends.name
\shows\Friends\Season 01\s01e01 example.avi
\shows\Friends\Season 01\s01e02 example.avi
\shows\Friends\Season 02\s02e01 example.avi
\shows\Friends\Season 02\s02e02 example.avi

converts it to
\tivo\Friends\Friends s01e01 example.avi
\tivo\Friends\Friends s01e02 example.avi
\tivo\Friends\Friends s02e01 example.avi
\tivo\Friends\Friends s02e02 example.avi

the #(enter your name).name, adds it to the beginning of the file name, so you can see what show it is.

this scripts cuts off all sub directories after the first, and add #enteryourname.name to the file in the current directory and sub directory, if the file exist in the sub directory, it will use that one.

I've just started using it. just change the /share1 to where the symbolic links will be created and the tivoserver to look there for the shows
shows="/share1"

change the /shows to where your shows exist.
tivo="/shows"

You don't have use the #enteryouname.name if it doesn't exist it just won't add any information.


This will also look to validate exsisting symbolic links, if there not valid, it removes them.

let me know what you think and if you use it.





#!/bin/bash
#version 1.02
# linktivo.sh by Snake98
# create symbolic links to ne directory for tivoserver. Tivoserver sorts directory
# by the last direcotry. this over comes this problem by combinding all sub directories
# and adding to the name #xxxxxx.name xxxxx is the name you want to add.
#--------------------------------------------------------------------------------
shows="/share1"
tivo="/shows"
subdir=true
[ ! -d "$shows" ] && echo "$shows does not exsist" && exit
[ ! -d "$tivo" ] && mkdir "$tivo"
find "$tivo" -type l | while read f; do if [ ! -e "$f" ]; then rm -f "$f"; fi; done
find "$shows" -type f | sort | while read readline; do
[ "$(echo $readline | awk -F"/" '{ print NF-1}')" -le "$(echo $shows | awk -F"/" '{ print NF}')" ] && newdir=$tivo/

if [[ "$readline" != "$subdir"* ]] || [[ $subdir == $shows ]] ;then
addname=$null
curdir=${readline%/*}
subdir=${readline%/*}
if [ "$(echo $readline | awk -F"/" '{ print NF-1}')" -gt "$(echo $shows | awk -F"/" '{ print NF}')" ]; then
for ((i="$(echo $readline | awk -F"/" '{ print NF-3}')"; i>="$(echo $shows | awk -F"/" '{ print NF}')"; i--))
do
subdir=${subdir%/*}
done
newdir=${subdir/$shows/$tivo}\/
[ ! -d "$newdir" ] && mkdir "$newdir"
fi
fi
if [[ "$readline" == *".name" ]];then
addname=${readline%\.name}
addname="${addname/*\/\#/} "
elif [ ! -L "$newdir$addname${readline/*\//}" ]; then
echo ln -s "$readline" "$newdir$addname${readline/*\//}"
ln -s "$readline" "$newdir$addname${readline/*\//}"
counterx=$(expr $counterx + 1)

else
echo file already exist "$newdir$addname${readline/*\//}"
fi
done


updated to 1.02 deleted invalid symbolic links
updated to 1.01 fix a file issues in the main directory

rbautch
04-30-2010, 05:03 PM
Cool script. Nice work!