[mythtv-users] Batch Download and Archive Recordings With Expanded File Names

Michael T. Dean mtdean at thirdcontact.com
Sat Oct 27 14:30:26 UTC 2012


On 10/26/2012 03:13 PM, tortise wrote:
> On 26/10/2012 6:34 p.m., tortise wrote:
>> On 26/10/2012 2:59 p.m., Michael T. Dean wrote:
>>>> I now realise I can also make a file listing under the web server
>>>> which makes for really quick navigation and selection on PC's without
>>>> a frontend! Nice.
>>>
>>> Feel free to update the mythlink.pl page with a section on how to do
>>> this, perhaps with an example.
>>>
>>
>> OK, will do. Just need to get the crontab working properly first, it may
>> be that running my command as root is causing the files to output as
>> $1.mpg $2.mpg $3.mpg.....instead of my current preference of:
>>
>> /usr/share/doc/mythtv-backend/contrib/user_jobs/mythlink.pl --link
>> /var/www/mythlinks --format '%T/%T-%Y%m%d-%H%i-%S'
>
> Think I've debugged my issue, the crontab files need the "%" signs
> escaped. I now have this that runs on the hour on mythbuntu 10.04:
>
> 0 * * * *   {username}
> /usr/share/doc/mythtv-backend/contrib/user_jobs/mythlink.pl --link
> /var/www/mythlinks --format '\%T/\%T-\%Y\%m\%d-\%H\%i-\%S'

Ah, yeah, that's why I have a script, mythlink.sh, that includes the 
desired mythlink.pl command line(s).  Then, the cron job (or whatever) 
can simply run it as "mythlink.sh".  I actually have my script create 5 
different views (sorted by start time, title, recording group, category, 
and original airdate--so I can find files using whatever view is easiest).

I'm attaching a copy of my script for reference.

> All my recordings start a minute early which is why on the hr is OK
> for me as the script takes a few seconds to run.  Anyone starting
> recordings on the hour might be better to make it run 1 minute past
> the hour. I'll see if I have any need for more often.

Yeah, or it can be run as a user job or--even better--as a MythTV System 
Event.

Mike

-------------- next part --------------
#!/bin/bash
#
# mythlink.sh
#
# Creates readable symlinks referring to MythTV recordings using the
# mythlink.pl script
#
# Usage:
#    mythlink.sh [chanid starttime]
#
#        chanid
#            The channel ID of the recording for which a link should be made
#
#        starttime
#            The starttime of the recording for which a link should be made
#
#    If chanid and starttime are not provided, links will be created for all
#    recordings.  This should be done periodically to remove links to
#    recordings that have been deleted.
#

### Modify these values for your installation ###

# The path in which the views ("pretty" links) will be created
VIEWS_PATH=/srv/mythtv/tv/views

# The location of the mythlink.pl script
# The default value assumes mythlink.pl is in the user's PATH
COMMAND=mythlink.pl

# The group used to create the links
# This allows multiple users to run the script, assuming all are in the
# specified group
GROUP=mythtv


### The following directory names and formats may be customized ###

# Formats may be constructed using the format specifiers listed in the
# output of "mythlink.pl --help"

# Files will be sorted "alphabetically" so the appropriate fields on which you
# would like to sort should be placed at the beginning of the format

# To add a custom format, simply include a directory name and format in the
# environment variables below using the syntax shown below.

# The names of the directories containing the views
DIRECTORIES=(
             'time'
             'title'
             'group'
             'category'
             'original_airdate'
            )
# The formats used for the respective directories specified above
FORMATS=(
         '%Y%m%d-%H%i-%eH%ei-%T-%S'
         '%T/%Y%m%d-%H%i-%eH%ei-%S'
         '%U-%T-%Y%m%d-%H%i-%eH%ei-%S'
         '%C-%T-%Y%m%d-%H%i-%eH%ei-%S'
         '%T-%oY%om%od-%S'
        )

# The string used to separate sections of the link name
SEPARATOR='-'

# The string used to replace illegal characters in the filename
REPLACEMENT='_'

# Whether to use underscores instead of spaces.
# Use '' to allow spaces
UNDERSCORES='--underscores'
#UNDERSCORES=''

# Whether to create links for LiveTV recordings.
# Use '' to skip LiveTV
LIVETV=''
#LIVETV='--live'

### The following should not require changes ###

unset CHANID STARTTIME
if [ ${#} -eq 2 -a "x${1}" != "x" -a "x${2}" != "x" ]; then
  CHANID="--chanid=${1}"
  STARTTIME="--starttime=${2}"
  shift 2
elif [ ${#} -ne 0 ]; then
  echo "Invalid arguments.  Ignoring."
fi

# Ensure word splitting occurs only for newlines as some directory names or
# formats may have spaces in their names
IFS=$'\n'

# Ensure directories have group write permissions
umask 0002

# Make the links by calling mythlink.pl with the appropriate arguments
last_index=$(( ${#DIRECTORIES[@]} - 1 ))
for directory in `seq 0 $last_index`; do
newgrp ${GROUP} <<EOF
  "${COMMAND}" --link="${VIEWS_PATH}/${DIRECTORIES[$directory]}" \
               --format="${FORMATS[$directory]}" --separator="${SEPARATOR}" \
               --replacement="${REPLACEMENT}" "${UNDERSCORES}" "${LIVETV}" \
               "${CHANID}" "${STARTTIME}"
EOF
done



More information about the mythtv-users mailing list