Author |
Message |
whoa
|
Posted: Sat Jan 23, 2010 8:21 pm |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
So I upgraded from R5.5 to R6 and after recording a cpl of shows noticed that Remove Commercials wasnt running.
A while back I figured out a script to remove commercials:
http://knoppmyth.net/phpBB2/viewtopic.p ... ommercials
and the place to put the script was /usr/local/bin/ well I noticed that's changed to /usr/bin/ because after doing some trouble shooting I did a find on my script's name "removecommercials" and much to my surprise it looks like r6 puts a file in /usr/bin named exactly like my script....but...it doesnt work. Now I'm not a script genius and the default script looks VERY interesting I'm just not interested in figuring out where the file is bad at but here's the guts:
Code: #!/bin/sh # remove commercials from recording # version 0.1
# usage: # first parameter must be %DIR% of the recording # second parameter must be %FILE% of the recording # third parameter must be %CHANID% # fourth parameter must be %STARTTIME% # fifth parameter must be %JOBID% for the User Job status to be updated in MythTV # in the mythtv setup screen invoke this script like this: # MYTHTV User Job Command: # /usr/LH/bin/removecommercials "%DIR%" "%FILE%" "%CHANID%" "%STARTTIME%" "%JOBID%"
# Auguments passed from command line VIDEODIR=$1 FILENAME=$2 CHANID=$3 STARTTIME=$4 JOBID=$5
# database settings BACKEND_HOSTNAME=${BACKEND_HOSTNAME:-"localhost"} DBUSERNAME=${DBUSERNAME:-"mythtv"} DBPASSWORD=${DBPASSWORD:-"mythtv"} SQLCMD="mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e"
#------FUNCTIONS--------------- update_comment() # Arg_1 = COMMENT { if [ $NO_JOBID = 0 ]; then `$SQLCMD "update jobqueue set comment=\"$1\" where id=\"$JOBID\";"` fi }
update_status() # Arg_1 = status code { if [ $NO_JOBID = 0 ]; then `$SQLCMD "update jobqueue set status=\"$1\" where id=\"$JOBID\";"` fi }
check_myth_jobcmds() # check the myth database for stop pause or resume commands { if [ $NO_JOBID = 0 ]; then CURRENT_CMD=`$SQLCMD "select cmds from jobqueue where id=\"$JOBID\";" | sed '/[0-9]/!d'` case "$CURRENT_CMD" in # JOB_RUN 0) ;; # JOB_PAUSE 1) update_status 6 kill -s STOP $TPID ;; # JOB_RESUME 2) update_status 4 `$SQLCMD "update jobqueue set cmds=\"0\" where id=\"$JOBID\";"` kill -s CONT $TPID ;; # JOB_STOP 4) update_status 5 `$SQLCMD "update jobqueue set cmds=\"0\" where id=\"$JOBID\";"` kill -9 $TPID clean_up_files echo "Cancelled" update_status 320 exit ;; esac fi }
check_background_progress() #check progress in background { while [ `tail -1 $STATUSFILE | grep -c "Done"` = 0 ] do sleep 5 check_myth_jobcmds current_status=`tail -1 $STATUSFILE` if [ `expr match "$current_status" '.*\complete'` -ne 0 ]; then prog_percent=`echo "$current_status" | awk '{print $3}'` if [ -n "$prog_percent" ]; then echo "Removing Commercials - $prog_percent Completed" update_comment "Removing Commercials - $prog_percent Completed" fi fi done }
get_pid() { process_name="" i1=1 while [ "$process_name" != "found" ]; do if [ "`ps $TPID | grep mythtranscode | sed 's_.*\(mythtranscode\).*_\1_'`" = "mythtranscode" ]; then process_name="found" else TPID=`expr $TPID + 1` fi i1=`expr $i1 + 1` if [ $i1 -gt 20 ]; then break fi done }
clean_up_files() # clean up left over files { unlink $TMPFILE 2> /dev/null unlink $TMPFILE.map 2> /dev/null unlink $STATUSFILE 2> /dev/null unlink $VIDEODIR/$FILENAME.tmp 2> /dev/null }
#-------MAIN SCRIPT------------ # check if %JOBID% is passed from command line JOBID=$5 if [ -z "$JOBID" ]; then NO_JOBID=1 else NO_JOBID=0 fi # check if file is a .mpg if [ `expr match "$FILENAME" '.*\.mpg'` -ne 0 ]; then MPEG="--mpeg2" else MPEG="" fi
# create temp filename so multiple instances won't conflict TMPNAME=rmvCOMMS-$$ TMPFILE=$VIDEODIR/$FILENAME-$$ STATUSFILE=/myth/tmp/$TMPNAME-status.log
touch $STATUSFILE
update_status 4
check_myth_jobcmds
# check for cutlist MYTHCOMMFRAMES=`mythcommflag --getcutlist -f $VIDEODIR/$FILENAME | grep 'Cutlist:' | cut -d \ -f 2` if [ -n "$MYTHCOMMFRAMES" ]; then echo "Extracting cutlist..." update_comment "Removing Commercials..." ( /usr/bin/nice -n19 /usr/bin/mythtranscode -c $CHANID -s $STARTTIME -o $TMPFILE $MPEG --honorcutlist --showprog$ TPID=$! get_pid check_background_progress ERROR=$? if [ $ERROR -ne 0 ]; then echo "Transcoding failed for ${FILENAME} with error $ERROR" exit $ERROR fi
check_myth_jobcmds # move temp file to output location echo "Moving file..." update_comment "Moving file..." if [ `$SQLCMD "select data from settings where value='SaveTranscoding';" | sed '/[0-9]/!d'` = 1 ]; then echo "DB is set to save transcodeing" mv $VIDEODIR/$FILENAME $VIDEODIR/$FILENAME.old fi mv $TMPFILE $VIDEODIR/$FILENAME
# file has changed, rebuild index echo "Rebuilding index..." update_comment "Rebuilding index..." mythcommflag -c $CHANID -s $STARTTIME --rebuild ERROR=$? if [ $ERROR -ne 0 ]; then echo "Rebuilding seek list failed for ${FILENAME} with error $ERROR" exit $ERROR fi
# remove old cutlist echo "Removing old cutlist..." update_comment "Removing old cutlist..." mythcommflag -c $CHANID -s $STARTTIME --clearcutlist ERROR=$? if [ $ERROR -eq 0 ]; then # Fix the database entry for the file `$SQLCMD UPDATE recorded SET cutlist = 0, filesize = $(ls -l $VIDEODIR/$FILENAME | awk '{print $5}') WHERE b$ else echo "Clearing cutlist failed for ${FILENAME} with error $ERROR" exit $ERROR fi clean_up_files echo "Commercials Removed" update_status 272 update_comment "Sucessfully Completed." else echo "No cutlist found." fi
when you run the script basically it errors out with "No cutlist found." Now I suspect thats because the new script requires a JOBID variable...My script didnt require such. So how does one find out the JOBID variable to use in the default script?!
I'm renaming the new script to .old and using mine for the time being but it would be nice to see how this works. Thanks!
|
|
Top |
|
|
brfransen
|
Posted: Sun Jan 24, 2010 12:06 pm |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
This script is meant to be run as a User Job from the Myth menus. The reason for the JOBID is so that the status can be updated in Myth's Job Queue System Status as it is running.
|
|
Top |
|
|
whoa
|
Posted: Sun Jan 24, 2010 1:40 pm |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
Yeah. I'm aware of that, but my point is...its not working...Any ideas?
|
|
Top |
|
|
brfransen
|
Posted: Sun Jan 24, 2010 11:06 pm |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
With the no cutlist found message it would seem that it is not detecting a cutlist for your selected recording. Did you create a cutlist? Without a cutlist the script doesn't know what to cut.
|
|
Top |
|
|
whoa
|
Posted: Mon Jan 25, 2010 9:12 am |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
brfransen...before asking your question did you look at the script to see what its supposed to do?
If you had you would see that at the very beginning, the script is supposed to generate a cutlist. So to answer your question...no...I didn't generate a cutlist, because the script is supposed to do that...and back to my original point...its not working. Does anyone else have any ideas?
|
|
Top |
|
|
brfransen
|
Posted: Mon Jan 25, 2010 10:15 am |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
I have looked at it, in fact, I wrote it so I am pretty sure I know what it is suppose to do. It seems you are misunderstanding what this script does. The script does NOT generate a cutlist. It looks for an existing cutlist and if it doesn't find one it finishes with "No cutlist found". Since you are not loading a cutlist and you are getting "No cutlist found" it seems that the script is working as intended.
|
|
Top |
|
|
whoa
|
Posted: Mon Jan 25, 2010 10:43 am |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
uh...then Im REALLY confused...I mean why would you create a script to automatically remove commercials when it doesnt work automatically?
as to your script I saw some mythcommflag lines figured one of them was the one that generates the cutlist, but yer right none of them do...so rather than erroring out sayng no cutlist...why not add in the line that generates it?
Code: mythcommflag --gencutlist -f $VIDEODIR/$FILENAME
I mean yer script looks very complex but why make it work so hard at not being real helpful?
|
|
Top |
|
|
brfransen
|
Posted: Mon Jan 25, 2010 11:38 am |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
It was never meant to automatically remove commercials. It was meant to provide the user a quicker and more obvious way to remove a created cutlist instead of having to configure one of the Transcoders to do it. See FS#459 for how this came to be.
In my experience mythcommflag is not nearly accurate enough that I would want it to automatically generate the cutlist and then allow it to delete those portions without first being able to review and modify what it was going to cut. That is why for this script it is expected that the user generate the cutlist.
If mythcommflag is accurate enough for you, feel free to modify the script to have it automatically generate the cutlist.
|
|
Top |
|
|
whoa
|
Posted: Mon Jan 25, 2010 11:51 am |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
Correct me if I'm wrong but isn't the user job list executed at the termination of a queued program recording automatically? Rhetorical question actually since the answer is yes. Correct me if I'm wrong but isnt your script imbedded as a default script to be run in the user job queue section? Again a rhetorical question...So if the script is already set to be part of an automatic execution at the conclusion of a recorded program BUT it wont actually remove any commercials automatically...doesnt there appear to be a problem in the logic there?
|
|
Top |
|
|
brfransen
|
Posted: Mon Jan 25, 2010 12:30 pm |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
whoa wrote: Correct me if I'm wrong but isn't the user job list executed at the termination of a queued program recording automatically? Rhetorical question actually since the answer is yes. Actually the answer to this is it depends on the user's settings. In your case it may be yes because you set it that way but on a default install the answer is no. The user job is not executed at the end of a recording unless the user sets it to run in the schedule or the default JobQueue setting is set to run the user job. Quote: doesnt there appear to be a problem in the logic there? Based on your incorrect assumption that user jobs are always executed at the end of a recording there would be a problem in logic. However, this script was written based on the assumption that it would not be executed automatically and that the user would load the cutlist and tweak as desired.
To get this script to do what you want you would need to modify it to have mythcommflag generate the cutlist and then set either the individual schedule or the default JobQueue setting to execute whatever user job # you assign the script to.
|
|
Top |
|
|
whoa
|
Posted: Mon Jan 25, 2010 1:16 pm |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
In order to execute a user job its a matter of checking the box appropriate for that job. For this thread the job I'm referring to is the one involving your script "removecommercials" or User Job 4. By default the box to execute that job is not checked...correct...but lets say default user out there who is looking over the user jobs sees User Job 4 and thinks to himself...Hmm this seems handy...and checks the box. It will now execute automatically at the conclusion of the recorded program....but....much to the chagrin of the default user no commercials are taken out of the recorded program because your script wont cut out the commercials automatically. How is this an incorrect assumption and how is my logic flawed?
|
|
Top |
|
|
brfransen
|
Posted: Mon Jan 25, 2010 1:53 pm |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
Basically we are talking about 2 different use cases, one the cutlist is generated manually and the other the user generates. This script only accounts for use case where the user loads the cutlist and manually runs the user job.
Britney
|
|
Top |
|
|
whoa
|
Posted: Mon Jan 25, 2010 2:14 pm |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
Britney
I understand how your script works. Truly I do. In order to use your script you must either watch the recorded program in flagging mode generating a cutlist manually or use something like mythcommflag to do it for you. In whatever case the cutlist must be made prior to the execution of your script...but that is my point entirely that I'm trying to make. Your script is set to be used as an automatic script so that when a user checks the box for User Job 4 it will execute automatically. However since at the conclusion of the recorded program no cutlist is made checking that box yields precisely nothing. So whats the point of putting your script in place to be used automatically when all it will do is fail 100% of the time?
|
|
Top |
|
|
brfransen
|
Posted: Mon Jan 25, 2010 3:31 pm |
|
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location:
SC
|
whoa wrote: So whats the point of putting your script in place to be used automatically when all it will do is fail 100% of the time? Because in the Myth UI there is no way to separate automatic and manual user jobs. If you want a user job to be selectable from the recordings Info-->Job Options menu it will always have the option to be run automatically in the schedule UI.
Here is how I use the script. Play a recording, enter edit mode, load the mythcommflag cut list, look at the various cutpoints and move as needed, exit recording to recordings UI, press Info-->Job Options-->Remove Commercials.
With mythcommflag not being 100% accurate, I default to protecting the users recordings over being able to automatically generate the cutlist.
Britney
|
|
Top |
|
|
whoa
|
Posted: Mon Jan 25, 2010 4:46 pm |
|
Joined: Fri Oct 07, 2005 7:18 am
Posts: 77
Location:
Dallas, TX
|
Your script already protects the user by making the original recording into a *.old file. There is nothing left "unprotected". I am still confused why a User Job made specifically to be executed automatically after a recording is finished will automatically fail every time. That sort of script IMO should be made available via documentation...much like DVD scripts are loaded but not made automatically available unless the user specifically runs them. If a user executes a job..Im fairly certain that the vast majority of the user population out there expects it to do its job automatically. To expect a user to know that a User Job is intentionally made to not work unless they do something ahead of time is irresponsible and frankly unhelpful...
That mythcommflag is not 100% accurate is true...but the removal of ANY commercials automatically is of great use and benefit when the user has to do NOTHING in order to achieve that state. I cant understand how that doesnt make sense to you.
|
|
Top |
|
|