March 2, 2005

Share Your EyeTV Archive

If you have an Elgato EyeTV PRV for your Mac and you want to share the recorded programs on a local network you've got a problem. I love the interface but you're pretty much forced to use it if you want to access your content. EyeTV stores your programs in a directory on your hard drive but its far from as user friendly as the system iTunes uses.

EyeTV Archive folder:



Folder of links created by the script:

UPDATE:
New version available here.

With the shell script below you can have a better way to access your content through the file system locally or on a network. This is especially helpful if you want to share it with other users on your LAN or stream it to a Home Theater system. Plus you can easily drag an mpg on to your iPod to watch at your friends house without exporting it first from EyeTV. This script will create links to the files in your EyeTV Archive in another folder that you choose—with human readable names.

FIRST A DISCLAIMER
You agree to use this software at your own risk and will not hold me liable for any unexpected results or lost data.

If you agree to that, copy the code below and paste it into a text file named eyetvlinks.sh or download the file here. Save the file to /usr/local/bin and chmod +x it. Then you'll need to edit the first few lines to set up your preferences. A couple important notes about this:

The script is set up by default to create hard links. You can change this to create symbolic links instead. Symbolic links are more like aliases and the finder will treat them as such. The disadvantage is they wont necessarily work for file sharing (AFP & Samba). Hard links are more like a pointer to the same location on your hard drive. And as such you can only use them if the file you are linking to is on the same physical drive as the link. Also the data on your drive wont be deleted until all hard links to it are removed.

You'll also need to enter the path of your EyeTV Archive and the folder you want to put the links in. This should be an empty folder because the script will delete anything there. Don't screw this up and come to me crying. This is a beta version.

I set up a cron job to fire off the script a couple times a day so the links get updated as the content in the archive changes. I recommend Cronnix for that.

#!/bin/sh
#
# EyeTVLinks 1.1b
#
# Search recursively through the EyeTV Archive and make some friendly
# links in my shared video directory for the roommates
#
# Written by Joshua McFarren 2/15/05
# This work is licensed under a Creative Commons License.
# http://creativecommons.org/licenses/by-sa/2.0/
#
# To do: rewrite this in perl instead of this kluge i hacked together ;)
#

# create hard links or symbolic links?
# set to no your symbolic links might not work over samba or afp
# set to yes the directories below must be on the same drive
hard_link="yes"

# declare constants for the working paths
my_dir="/Volumes/Caviar 120/Video/EyeTV"           # location of aliases
archive_dir="/Volumes/Caviar 120/EyeTV Archive/"   # location of archive

###############################################################################
#                                                                             #
#    DO NOT EDIT BELOW HERE UNLESS YOU CAN FIX MY USELESS USE OF BACKTICKS    #
#                                                                             #
###############################################################################

d=0            # counter for dir array
f=0            # counter for file array
name=""        # name of file
my_path=""     # path to file in archive
show_date=""   # date for multiple instances of same show
vid_dirs=()    # array of directories that may contain a file
vid_files=()   # array of files in the active directory

# fix the directory list to populate array without color
unset CLICOLOR

# turn this on for logger
echo -n "Refreshing EyeTV links "; date

# clear the old links
rm "$my_dir/"*.mpg 2>&1

# get an array of video directories and number
vid_dirs=(`ls -F1 "$archive_dir" | grep '/' | sed "s'/''"`)

# while there are directories left to traverse
while [ "$d" -lt `expr ${#vid_dirs[*]} - 1` ]
do
  # get the path for position of counter
  my_path="$archive_dir${vid_dirs[$d]}/"
  
  # get the name of the file in that dir
  name=`egrep string "$archive_dir${vid_dirs[$d]}/${vid_dirs[$d]}.eyetvp"\
  | sed -e "s|<string>||g" -e "s|</string>||" -e "s/ /_/g" | tail -1\
  | awk '{print $1}' | sed "s|:||"`
  
  # get an array of all files in the active dir and a total num of files
  vid_files=(`ls -1 "$archive_dir${vid_dirs[$d]}/"|grep .mpg|sed "s/.mpg//"`)
  
  # if there is a video file in the directory
  if [ "${#vid_files[*]}" -gt "0" ]; then
  
    # reset the file counter for each directory
    f=0
    
    # turn this on for error checking or logger
    echo "$my_path $name"  | sed "s'$archive_dir''"
    
    # for each video file print a result
    while [ "${#vid_files[*]}" -gt "$f" ]
    do
      show_date=`egrep date \
      "$archive_dir${vid_dirs[$d]}/${vid_files[$f]}.eyetvr" \
      | sed -e "s|<date>||g" -e "s|</date>||" -e "s/ /_/g" \
      -e "s/2005-//" -e "s/2004-//" -e "s/T.*//"| \
      awk '{print $1}' | tail -1`
      
      # make the link
      if [ $hard_link = "yes" ]; then
        ln "$my_path${vid_files[$f]}.mpg" "$my_dir/$name"_"$show_date.mpg"
      else
        ln -s "$my_path${vid_files[$f]}.mpg" "$my_dir/$name"_"$show_date.mpg"
      fi
      
      # increment the file counter
      f=`expr $f + 1`
    done
    # no more video files
    
  fi
  
  # increment the directory counter
  d=`expr $d + 1`
  
done
# no more video directories

Creative Commons License   This work is licensed under a Creative Commons License Technorati tags: , , , , , , , , , , , , , , ,
Posted by joshua at March 2, 2005 1:07 AM | TrackBack
Comments

Joshua -

Great program! I am having some problems with my eyetv recording and wanted to know if you ever had these problems. Not sure if your program is causing them, I don't see how it could.

Every now and then I open my eyeTV archive a find it empty, it seems the xml file is blank so no programs show up. Have you had this problem?

Thanks,

Marcelo

Posted by: marcelo at April 11, 2005 6:15 AM

Editors note: I've been working with Marcelo through e-mail to try and resolve his problem and figure out if the script could be the culprit. He configured everything properly and I didn't see any problems in his directory structure either. The results are not conclusive but he's been having other problems with programs crashing that lead to his reinstallation of OS X. Even after the reinstall—and not running the script—he's been having the same problem. Hopefully Elgato tech-support will sort him out, he's working with them now. If anyone else has experienced the problem Marcelo described, please let us know.

A quick note about how the script works and what damage it could cause in a worst case scenario. The script basically goes through your EyeTV Archive folder, and for each time stamped sub-folder, it reads the xml file inside that ends in .eyetvp to find the program name and date recorded. The only files it removes are the aliases in the location you declared as my_dir. And at worst you could only loose files in that folder that end in .mpg.

-Joshua

Posted by: Joshua McFarren at April 14, 2005 10:02 AM

Hi,

i want you to ask if you would allow me to include this little nice script to my EyeRecord Script. And perhaps you want to post it on my site.

Please contact me. i-c-q: 53021772 or email

Thx

Jan

Posted by: jan at April 22, 2005 5:41 AM


Post a comment









Remember personal info?