#!/bin/bash VID_DIR=/export/docker/storage/other-videos RDIR=/export/myth/tv if [ $# -ne 2 ]; then echo "Usage: $argv " echo "search will be used as a %title% search in the title field of the recordings, and new-name is a full path to /export/myth/videos and should include any subdirs/xxx.ext" echo "E.g. $argv "\"Friday Fin\"" /export/docker/storage/other-videos/AFL/2020/Rd1-Away-Carlton.mpg" exit 0 else search=$1 new_name=$2 if [ `expr "$new_name" : "$VID_DIR"` = 0 ]; then echo "The filename you are copying to is not in $VID_DIR, exiting..." exit 1 fi fi footy=0 if [ `expr "$new_name" : "$VID_DIR/AFL"` -gt 0 ]; then footy=1 fi echo "s=$search -- (footy=$footy) & its a full path: $new_name" found_in="title" basename=$(echo -n "select basename from recorded where title like '%$search%'" \ | mysql --user=mythtv --password=mythtv mythconverg | tail -n1) full_title=$(echo -n "select title, subtitle from recorded where title like '%$search%'" \ | mysql --user=mythtv --password=mythtv mythconverg | tail -n1) if [ -z $basename ]; then found_in="subtitle" basename=$(echo -n "select basename from recorded where subtitle like '%$search%'" \ | mysql --user=mythtv --password=mythtv mythconverg | tail -n1) full_title=$(echo -n "select title, subtitle from recorded where subtitle like '%$search%'" \ | mysql --user=mythtv --password=mythtv mythconverg | tail -n1) elif [ -z $basename ]; then echo "Could not match $search in title or subtitle, Exiting..." exit 2 fi echo "Found: ($basename) (by $found_in match) - $full_title" echo "Okay to: sudo mv $RDIR/$basename $new_name (y/N?)" read response if [ "$response" != "y" ]; then echo "Cancelling..." exit 0; fi sudo mv $RDIR/$basename $new_name echo "You Need to rescan in myth now... press any key when done" read response sig_bit=`expr $new_name : "$VID_DIR/"` myth_new_name=${new_name:$sig_bit} intid=$(echo -n "select intid from videometadata where filename like '%$myth_new_name'" \ | mysql --user=mythtv --password=mythtv mythconverg | tail -n1) if [ "$intid" = "" ]; then echo "Something is not right, I can't find the file we just scanned for" exit 0; fi length_in_sec=`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $new_name 2> /dev/null` length=`echo "$length_in_sec/ 60" | bc` echo "update videometadata set length = $length where intid=$intid; update videometadata set plot = (select description from recorded where basename='$basename') where intid=$intid; update videometadata set year = year( date( (select starttime from recorded where basename='$basename') )) where intid=$intid; update videometadata set rating = 'G' where intid=$intid;" \ | mysql --user=mythtv --password=mythtv mythconverg if [ $footy = 1 ]; then pat='Rd([0-9]+)' [[ $new_name =~ $pat ]] # $pat must be unquoted Rd="${BASH_REMATCH[1]}" # Rd=`echo $new_name | cut -c30-31` echo "This is a football stream, also copying gfc.jpg, and slotting this in for Round: $Rd" echo "update videometadata set director = 'AFL Round $Rd' where intid=$intid; update videometadata set coverfile = '/myth/video-cover-art/gfc.jpg' where intid=$intid;" \ | mysql --user=mythtv --password=mythtv mythconverg fi # put a zero-byte file in tv dir so it can be deleted out of myth's db touch $RDIR/$basename