Results 1 to 8 of 8

Thread: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

  1. #1
    Join Date
    Sep 2011
    Beans
    8

    Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    At the mythlink.pl wiki page http://www.mythtv.org/wiki/Mythlink.pl the intro paragraph states: "Once you have created a directory of readable symlinks, the show can be archived with the link's name using appropriate copy or move commands."

    I have a script that makes a copy of the video file that I intend to use as a User Job.. I can get mythlink.pl to run any time I want it to run and, since I don't use those names to watch the files, I can parse the mythlink.pl command to include the %CHANID% and %STARTTIME%.

    What copy or move commands are needed to use the name of a link to file A (${INDIR}/${CHANID}_${STARTTIME}.* where * is either mpg or nuv, separate question, see here) to name file B (${OUTDIR}/${CHANID}_${STARTTIME}), using %CHANID% and %STARTTIME% to define file A and remove %CHANID% and %STARTTIME% from the name of file B?

    Here are the mythlink.pl arguments and the user job so far:
    Code:
    mythlink.pl --link /var/lib/mythtv/pretty --format '%T %- %S%-%c_%Y%m%d%H%i%s
    Code:
    #! /bin/bash
    %STARTTIME 
    scriptstarttime=$(date +%F-%H%M%S)
    
    CHANID=$1
    STARTTIME=$2
    
    INDIR="/var/lib/mythtv/recordings"
    OUTDIR="/home/username/Dropbox"
    PROG="/home/username/bin/ffmpeg"
    PARAMS="-y -stats -deinterlace -vcodec libx264 -vprofile baseline -level 13 -maxrate 76800 -bufsize 3000000 -acodec libfdk_aac -ac 2 -ab 128k -ar 44100 -sn"
    
    LOGFILE="/home/username/Dropbox/DropboxTranscode.log"
    OUTFILE="${OUTDIR}/${CHANID}_${STARTTIME}"
    
    COMMAND="${PROG} -i ${INDIR}/${CHANID}_${STARTTIME}.mpg ${PARAMS} ${OUTFILE}.mp4"
    
    touch $LOGFILE
    chown mythtv:mythtv $LOGFILE
    chmod 777 $LOGFILE
    echo "$scriptstarttime Dropbox Transcode" >> $LOGFILE
    echo "${COMMAND}" >> $LOGFILE
    $COMMAND >> $LOGFILE 2>&1
    
    
    Thanks,
    Iago6776
    Last edited by Iago6776; March 30th, 2014 at 08:59 PM. Reason: missed a space

  2. #2
    Join Date
    Jan 2014
    Beans
    224
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    Sorry don't understand what you are doing.

    I think you are trying to use actual recordings & the job queue to perform actions on files (symlinks made by mythlink) to the actual recording file.

    If you want to archive an actual file from a symlink you must copy & de-reference the symlink:
    Code:
    cp -L source destination-dir
    Can you break down the problem into small soluble steps?

  3. #3
    Join Date
    Sep 2011
    Beans
    8

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    Say I have a recording a TV series called "Linux" with the subtitle "Ubuntu." the channel ID is, according to the database it's, say, 1085. The recording start time, according to my database, was 20140328190000. That night, mythlink.pl runs in its cron job and makes a link called "Linux - Ubuntu 1085_20140328190000.mpg" in the directory /var/lib/mythtv/pretty that points to /var/lib/mythtv/recordings/1085_20140328190000.mpg.
    With my script, I don't want to do anything but make a shrunken copy of that /var/lib/mythtv/recordings/1085_20140328190000.mpg file in my Dropbox directory but I want to name the h264/aac mp4 file "Linux - Ubuntu.mp4".

  4. #4
    Join Date
    Apr 2012
    Beans
    5,472

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    Are you asking about manipulating a filename string within a shell variable?

    To remove a trailing sequence (such as the .mpg) suffix from a variable in bash, the bash recipe is ${var%pattern} where var is the variable name and pattern is the sequence you want to remove. A variant ${var%%pattern} is similar but tries to remove the longest matching sequence. So for example:

    Code:
    $ filename="Linux - Ubuntu 1085_20140328190000.mpg"
    $ echo "${filename%.mpg}"
    Linux - Ubuntu 1085_20140328190000
    You can extend this using some shell globbing tricks e.g. to remove the longest trailing sequence consisting wholly of digits followed by .mpg I *think* you could do something like

    Code:
    $ echo "${filename%%*([0-9]).mpg}"
    Linux - Ubuntu 1085_
    or to remove the longest trailing sequence consisting of a single space followed by digits-underscore-digits.mpg

    Code:
    $ echo "${filename%% *([0-9])_*([0-9]).mpg}"
    Linux - Ubuntu
    You could also pipe the string through a variety of true regex based tools (sed, awk, perl...) instead of bash substitutions / globs. I'm not sure which is a better solution.

    You can concatenate the new suffix in the same expression e.g.

    Code:
    $ newname="${filename%% *([0-9])_*([0-9]).mpg}.mp4"
    $ echo "$newname"
    Linux - Ubuntu.mp4
    See more at http://tldp.org/LDP/abs/html/string-manipulation.html

  5. #5
    Join Date
    Sep 2011
    Beans
    8

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    More than that, steeldriver, I'm looking to use the name of the link to the first file to name the file I create by running a script on that same file. If I can help it, without having to edit the name of the link.

  6. #6
    Join Date
    Jan 2014
    Beans
    224
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    Pass the variables %TITLE% & %SUBTITLE$ to your user-job script (along with the filename &/or starttime-chanid)
    http://www.mythtv.org/wiki/User_Jobs

    I don't see what you need "mythlink" for ?? Was it the nice file naming ?

  7. #7
    Join Date
    Sep 2011
    Beans
    8

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    I haven't been able to find out why %TITLE% and %SUBTITLE% don't work in this script, I've tried using them and found that mythlink works flawlessly where as:
    %TITLE% for "Daniel Tiger's Neighborhood" returns "Daniel"
    And
    %SUBTITLE% returns the TV episode's description or the movie's... nothing.

  8. #8
    Join Date
    Jan 2014
    Beans
    224
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Using "appropriate copy or move commands" in a bash script after mythlink.pl runs

    If you are using simple command line parsing then always enclose each parameter (that could have spaces) in quotes.
    Your title has spaces which defeats simple parameter passing..

    The user-job line in mythtv becomes:
    Code:
    /path/my-user-job "%TITLE%"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •