Anyone else having problems with commercial removal in 0.28?

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

just ran this 3 times and it's working for me as a user job /path/script.py --jobid %JOBID%

Code: Select all

#!/usr/bin/env python2
#MythTV commercial removal -- by Daraden
#usage userjob = /path to script/script.py --jobid %JOBID%
#/path to script/script.py --chanid --starttime can also be used
from MythTV import Job, Program, Recorded, System, MythDB, findfile, MythError, MythLog, datetime
import argparse
import subprocess
import os
import sys
import shutil
from glob import glob
import time
from datetime import timedelta
import logging
db=MythDB()

#set this to True to use commflag results as cut list
use_commflag = True
#save copy of original file as file.old if not using output file
save_old = True
#user needs write access to this directory to save logfile
logdir ='/tmp/'

#logging setup for file and console
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
lf= logging.Formatter('%(asctime)s:%(levelname)s:%(message)s')
if os.access(logdir,os.W_OK):
    fh = logging.FileHandler(filename='%scut.log'%(logdir),mode='w')
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(lf)
    logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(lf)
logger.addHandler(ch)

def run_cut(jobid=None,chanid=None,starttime=None,outfile=None):
    logging.info('Started')
    #check for ffmpeg or mythffmpeg
    ffmpeg = prog_check()[0]
    
    logging.debug('ffmpeg=%s',ffmpeg)

    if jobid:
        job = Job(jobid, db=db)
        chanid = job.chanid
        starttime = job.starttime
        logging.debug('chanid=%s starttime=%s',chanid,starttime)
    if not jobid:
        chanid = chanid
        starttime = starttime
        logging.debug('chanid=%s starttime=%s',chanid,starttime)

    rec = find_rec(chanid,starttime)
    logging.debug('DB recording entry=%s',rec)
    sg = findfile('/'+rec.basename, rec.storagegroup, db=db)
    infile = os.path.join(sg.dirname, rec.basename)
    tmpdir = sg.dirname +'crtmp/'
    tmp_chk(tmpdir)

    if save_old and not outfile:
        shutil.copyfile(infile,'%s.old' % infile)

    if outfile != None:
        Outfile = outfile
    elif outfile == None:
        Outfile = infile

    if rec.cutlist == 1 or use_commflag == True:
        if jobid:
            job.update({'status':job.RUNNING, 'comment':'Removing Cutlist'})
        logging.info('getting cutlist')
        if rec.cutlist == 1:
            cut_list =''.join(str(rec.markup.getcutlist())).replace('[','').replace(']','').replace('(','').replace(')','').replace(' ','')
        elif rec.cutlist == 0 and rec.commflagged == 1:
            cut_list =''.join(str(rec.markup.getskiplist())).replace('[','').replace(']','').replace('(','').replace(')','').replace(' ','')
        else:
            print 'No cut/skip list found'
            logging.debug('No cut/skip list found')
            sys.exit(1)            
        cutlist = cut_list
        if cutlist.startswith('0,'):
            cutlist = cutlist.replace("0,",'',1)
        if cutlist.endswith(',9999999'):
            cutlist = cutlist.replace(",9999999",'',-1)
        logging.debug('Myth cutlist:%s',cut_list)
        logging.debug('FFmpeg cutlist:%s',cutlist)
        logging.info('cutting started')
        cut =subprocess.Popen([ffmpeg,'-i',infile,'-c','copy','-map','0','-f','segment','-segment_list','%scut.ffcat'%(tmpdir),'-segment_frames',cutlist,'%scut%%03d.ts'%(tmpdir)],stdout = subprocess.PIPE, stderr = subprocess.STDOUT,universal_newlines=True)
        output = cut.communicate()[0]
        if cut.wait() == 0:
            if jobid:
                job.update({'status':job.RUNNING, 'comment':'Cuting Finished'})
            logging.info('Cuting Finished')
        if cut.wait() != 0:
            if jobid:
                job.update({'status':job.ERRORED, 'comment':'FFMPEG ERROR: cutiing'})
            logging.error('FFMPEG ERROR: cutiing')
            logging.error('%s',output)
            sys.exit(1)

        if jobid:
            job.update({'status':job.RUNNING, 'comment':'Merging Cuts'})
        logging.info('Merging Cuts')
        j = []
        for root, dirs, files in os.walk(tmpdir):
            for files in files:
                if files.endswith('.ts') and files.startswith('cut'):
                    if os.path.isfile(os.path.join(root,files)):
                        j.append(os.path.join(root,files))
        if cut_list.startswith('0,'):
          ls = j[1::2]
        if not cut_list.startswith('0,'):
          ls = j[0::2]
        q =','.join(ls).replace(',','|')
        logging.debug('concat list:%s' % q)
        join =subprocess.Popen([ffmpeg,'-y','-i','concat:%s'%q,'-map','0','-c','copy','-f','mpegts',Outfile],stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output = join.communicate()[0]
        if join.wait() == 0:
            if jobid:
                job.update({'status':job.RUNNING, 'comment':'Merging Finished'})
            logging.info('Merging Finished')
        if join.wait() != 0:
            if jobid:
                job.update({'status':job.ERRORED, 'comment':'FFMPEG ERROR: merging'})
            logging.error('FFMPEG ERROR: merging')
            logging.error('%s',output)
            sys.exit(1)
    rem_tmp(tmpdir)
    if  outfile == None:
        clear_markup(rec,infile,outfile)
def clear_markup(rec,infile,outfile):
    logging.info('Started Clearing markup')
    
    logging.debug('rec=%s infile=%s outfile=%s',rec,infile,outfile)
    chanid = rec.chanid
    utcstarttime = rec.starttime
    starttime = str(utcstarttime.utcisoformat().replace(u':', '').replace(u' ', '').replace(u'T', '').replace('-', ''))
    logging.debug('chanid=%s starttime=%s',chanid,starttime)
    logging.info('start clearing markup')
    try:
        rcl = subprocess.Popen(['mythutil','--chanid',str(chanid),'--starttime',str(starttime),'--clearcutlist'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output1 = rcl.communicate()
        if rcl.wait() == 0:
            logging.info('Cutlist removed for:%s_%s',chanid,starttime)
            logging.debug('%s',output1)
        if rcl.wait() != 0:
            logging.error('MYTHUTIL ERROR: clearing cutlist for:%s_%s',chanid,starttime)
            logging.error('%s',output1)
    except Exception as e:
        logging.error('Mythutil exception clearing cutlist%s',e)
    try:
        rsl = subprocess.Popen(['mythutil','--chanid',str(chanid),'--starttime',str(starttime),'--clearskiplist'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output2 = rsl.communicate()[0]
        if rsl.wait() == 0:
            logging.info('Skiplist removed for:%s_%s',chanid,starttime)
        if rsl.wait() != 0:
            logging.error('MYTHUTIL ERROR: clearing skiplist for:%s_%s',chanid,starttime)
            logging.error('%s',output2)
    except Exception as e:
        logging.error('Mythutil exception clearing skiplist:%s',e)

    for index,mark in reversed(list(enumerate(rec.markup))):
        if mark.type in (rec.markup.MARK_COMM_START, rec.markup.MARK_COMM_END):
            del rec.markup[index]
    rec.bookmark = 0
    rec.cutlist = 0
    rec.commflagged = 0
    rec.markup.commit()
    rec.basename = os.path.basename(infile)
    rec.filesize = os.path.getsize(infile)
    rec.transcoded = 1
    rec.seek.clean()
    rec.update()
    
    try:
        logging.info('Removing PNG files')
        for png in glob('%s*.png' % infile):
            os.remove(png)
    except Exception as e:
        logging.error('Error removing png files',e)
    try:
        logging.info('Removing JPG files')
        for jpg in glob('%s*.jpg' % infile):
            os.remove(jpg)
    except Exception as e:
        logging.error('Error removing jpg files',e)    
    try:
        logging.info('Rebuilding seektable')
        rst = subprocess.Popen(['mythcommflag','--chanid',str(chanid),'--starttime',str(starttime),'--rebuild'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output2 = rst.communicate()[0]
        if rst.wait() == 0:
            logging.info('Seektable Rebuilt for:%s_%s',chanid,starttime)
            logging.info('%s',output2)
        if rst.wait() != 0:
            logging.error('MYTHcommflag ERROR: Rebuilding Seektable for:%s_%s',chanid,starttime)
            logging.error('%s',output2)
    except Exception as e:
        logging.error('Mythcommflag ERROR clearing skiplist:%s',e)

def tmp_chk(tmpdir):
        try:
            if os.path.isdir(tmpdir):
                logging.info('temp Folder found:')
                if os.listdir(tmpdir) != 0:
                    logging.warning('Temp folder not empty!:Removing Files:')
                    shutil.rmtree(tmpdir)
                    os.makedirs(tmpdir)
            if not os.path.isdir(tmpdir):
                logging.info('no temp folder found:')
                os.makedirs(tmpdir)
                logging.info('Temp folder created:')
        except Exception as e:
            logging.error('%s',e)
def rem_tmp(tmpdir):
            try:
                if os.path.isdir(tmpdir):
                    logging.info('temp Folder found')
                    shutil.rmtree(tmpdir)
                    logging.info('Temp Folder Removed')
                if not os.path.isdir(tmpdir):
                    logging.info('no temp folder found')
            except Exception as e:
                logging.error('%s',e)
def find_rec(chanid,starttime):
    def local_time_offset(t=None):
        if t is None:
            t = time.time()

        if time.localtime(t).tm_isdst and time.daylight:
            return -time.altzone
        else:
            return -time.timezone

    def RecordedFromBasename(chanid,starttime):
        bnts = '%s_%s.ts' % (chanid,starttime)
        bnmpg = '%s_%s.mpg' % (chanid,starttime)

        x = list(db.searchRecorded(basename=bnmpg))
        if len(x) == 1:
            for recorded in x:
                return recorded
                
        if len(x) != 1:
            x = list(db.searchRecorded(basename=bnts))
            if len(x) == 1:
                for recorded in x:
                    return recorded
            if len(x) != 1:    
                raise LookupError\
        ('unable to find Recorded entry for ChanID %s StartTime %s'\
         % (chanid,starttime))
    try:
        rec = Recorded((chanid,starttime), db=db)
    except:        
        try:
            tzoffset = local_time_offset() / (60*60)
            utcstarttime = datetime.strptime(starttime,"%Y%m%d%H%M%S")
            utcstarttime = utcstarttime + timedelta(hours=tzoffset)
            rec = Recorded((chanid,utcstarttime), db=db)
        except:
            rec = RecordedFromBasename(chanid,starttime)
    return rec
def prog_check():
    if os.access('/usr/bin/ffmpeg', os.X_OK):
        ffmpeg = '/usr/bin/ffmpeg'
    elif os.access('/usr/bin/mythffmpeg', os.X_OK):
        ffmpeg = '/usr/bin/mythffmpeg'
    else:
        ffmpeg = None
    if os.access('/usr/bin/ffprobe', os.X_OK):
        ffprobe ='/usr/bin/ffprobe'
    elif os.access('/usr/bin/mythffprobe', os.X_OK):
        ffprobe = '/usr/bin/mythffprobe'
    else:
        ffprobe = None
    if ffmpeg == None or ffprobe == None:
        raise LookupError ('Unable to find ffmpeg/ffprobe')
    return ffmpeg,ffprobe
def main():
    parser = argparse.ArgumentParser(description='MythTV Commercial removal and closed caption extraction tool.\nNOTE:Having .srt file in same dir as media files breaks playback in some media players(VLC)')
    parser.add_argument('--chanid',action='store',type=str,dest='chanid',help='Channel-Id of Recording')
    parser.add_argument('--starttime',action='store',type=str,dest='starttime',help='Starttime of recording in utc format')
    parser.add_argument('--jobid',action='store',type=int,dest='jobid',help='JOBID')
    parser.add_argument('-o',action='store',type=str,dest='outfile',help='Output file to be created')
    args = parser.parse_args()
    if args.jobid:
        run_cut(jobid=args.jobid,outfile=args.outfile)
        sys.exit(0)        
    if args.chanid and args.starttime:
        run_cut(chanid=args.chanid,starttime=args.starttime,outfile=args.outfile)
        sys.exit(0)
    else:
        print 'chanid and starttime or jobid'
main()
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

Put that in place. Ran it. Get this in the MythWeb frontend still:
Remove Comms.py (Errored: Sun Nov 20, 2016, 10:43 PM)
ERROR: User Job returned non-zero, check logs.

I don't get a .old file. No log file in /tmp/

Get this in the mythbackend log:
2016-11-20 22:43:25.187207 I [2341/29340] UserJob_9790 jobqueue.cpp:2410 (DoUserJobThread) - JobQueue: Started Remove Comms.py for "The Andy Griffith Show":"The Cow Thief" recorded from channel 2502 at 2016-10-15T00:00:00Z
2016-11-20 22:43:30.901636 E [2341/29340] UserJob_9790 jobqueue.cpp:2445 (DoUserJobThread) - JobQueue: User Job '/usr/local/bin/removecommercials.py --jobid 9790' failed.

Double checked the listing in setup. Matches what you said (and the log entry). ?
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

put this on the second line

Code: Select all

# -*- coding: UTF-8 -*-
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

I added that line and re-ran the Task. I still get:
Remove Comms.py (Errored: Mon Nov 21, 2016, 04:44 PM)
ERROR: User Job returned non-zero, check logs.
in the myuthweb console.

In the log:
2016-11-21 16:44:27.927817 I [2341/22756] UserJob_9998 jobqueue.cpp:2410 (DoUserJobThread) - JobQueue: Started Remove Comms.py for "The Andy Griffith Show":"Cyrano Andy" recorded from channel 2501 at 2016-09-12T10:30:00Z
2016-11-21 16:44:33.743973 E [2341/22756] UserJob_9998 jobqueue.cpp:2445 (DoUserJobThread) - JobQueue: User Job '/usr/local/bin/removecommercials.py --jobid 9998' failed.

No .old file is created.
No new log file is created in /tmp.
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

after trying to break the script for quite a while last night, hopefully i found the bug.

Code: Select all

#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
#MythTV commercial removal -- by Daraden
#usage userjob = /path to script/script.py --jobid %JOBID%
#/path to script/script.py --chanid --starttime can also be used
from MythTV import Job, Program, Recorded, System, MythDB, findfile, MythError, MythLog, datetime
import argparse
import subprocess
import os
import sys
import shutil
from glob import glob
import time
from datetime import timedelta
import logging
db=MythDB()

#set this to True to use commflag results as cut list
use_commflag = True
#save copy of original file as file.old if not using output file
save_old = True
#user needs write access to this directory to save logfile
logdir ='/tmp/'
#logging setup for file and console
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
lf= logging.Formatter('%(asctime)s:%(levelname)s:%(message)s')
try:
    if os.access(logdir,os.W_OK):
        fh = logging.FileHandler(filename='%scut.log'%(logdir),mode='w')
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(lf)
        logger.addHandler(fh)
except:
    pass
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(lf)
logger.addHandler(ch)

def run_cut(jobid=None,chanid=None,starttime=None,outfile=None):
    logging.info('Started')
    #check for ffmpeg or mythffmpeg
    ffmpeg = prog_check()[0]
    
    logging.debug('ffmpeg=%s',ffmpeg)

    if jobid:
        job = Job(jobid, db=db)
        chanid = job.chanid
        starttime = job.starttime
        logging.debug('chanid=%s starttime=%s',chanid,starttime)
    if not jobid:
        chanid = chanid
        starttime = starttime
        logging.debug('chanid=%s starttime=%s',chanid,starttime)

    rec = find_rec(chanid,starttime)
    logging.debug('DB recording entry=%s',rec)
    sg = findfile('/'+rec.basename, rec.storagegroup, db=db)
    infile = os.path.join(sg.dirname, rec.basename)
    tmpdir = sg.dirname +'crtmp/'
    tmp_chk(tmpdir)

    if save_old == True and outfile == None:
        logging.info('Backing up original file')
        shutil.copyfile(infile,'%s.old' % infile)
        logging.info('Finished backing up original file')
    if outfile != None:
        Outfile = outfile
    elif outfile == None:
        Outfile = infile

    if rec.cutlist == 1 or use_commflag == True:
        if jobid:
            job.update({'status':job.RUNNING, 'comment':'Removing Cutlist'})
        logging.info('getting cutlist')
        if rec.cutlist == 1:
            cut_list =''.join(str(rec.markup.getcutlist())).replace('[','').replace(']','').replace('(','').replace(')','').replace(' ','')
        elif rec.cutlist == 0 and rec.commflagged == 1:
            cut_list =''.join(str(rec.markup.getskiplist())).replace('[','').replace(']','').replace('(','').replace(')','').replace(' ','')
        else:
            print 'No cut/skip list found'
            logging.debug('No cut/skip list found')
            sys.exit(1)            
        cutlist = cut_list
        if cutlist.startswith('0,'):
            cutlist = cutlist.replace("0,",'',1)
        if cutlist.endswith(',9999999'):
            cutlist = cutlist.replace(",9999999",'',-1)
        logging.debug('Myth cutlist:%s',cut_list)
        logging.debug('FFmpeg cutlist:%s',cutlist)
        logging.info('cutting started')
        cut =subprocess.Popen([ffmpeg,'-i',infile,'-c','copy','-map','0','-f','segment','-segment_list','%scut.ffcat'%(tmpdir),'-segment_frames',cutlist,'%scut%%03d.ts'%(tmpdir)],stdout = subprocess.PIPE, stderr = subprocess.STDOUT,universal_newlines=True)
        output = cut.communicate()[0]
        if cut.wait() == 0:
            if jobid:
                job.update({'status':job.RUNNING, 'comment':'Cuting Finished'})
            logging.info('Cuting Finished')
        if cut.wait() != 0:
            if jobid:
                job.update({'status':job.ERRORED, 'comment':'FFMPEG ERROR: cutiing'})
            logging.error('FFMPEG ERROR: cutiing')
            logging.error('%s',output)
            sys.exit(1)

        if jobid:
            job.update({'status':job.RUNNING, 'comment':'Merging Cuts'})
        logging.info('Merging Cuts')
        j = []
        for root, dirs, files in os.walk(tmpdir):
            for files in files:
                if files.endswith('.ts') and files.startswith('cut'):
                    if os.path.isfile(os.path.join(root,files)):
                        j.append(os.path.join(root,files))
        if cut_list.startswith('0,'):
          ls = j[1::2]
        if not cut_list.startswith('0,'):
          ls = j[0::2]
        q =','.join(ls).replace(',','|')
        logging.debug('concat list:%s' % q)
        join =subprocess.Popen([ffmpeg,'-y','-i','concat:%s'%q,'-map','0','-c','copy','-f','mpegts',Outfile],stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output = join.communicate()[0]
        if join.wait() == 0:
            if jobid:
                job.update({'status':job.RUNNING, 'comment':'Merging Finished'})
            logging.info('Merging Finished')
        if join.wait() != 0:
            if jobid:
                job.update({'status':job.ERRORED, 'comment':'FFMPEG ERROR: merging'})
            logging.error('FFMPEG ERROR: merging')
            logging.error('%s',output)
            sys.exit(1)
    rem_tmp(tmpdir)
    if  outfile == None:
        clear_markup(rec,infile,outfile)
def clear_markup(rec,infile,outfile):
    logging.info('Started Clearing markup')
    
    logging.debug('rec=%s infile=%s outfile=%s',rec,infile,outfile)
    chanid = rec.chanid
    utcstarttime = rec.starttime
    starttime = str(utcstarttime.utcisoformat().replace(u':', '').replace(u' ', '').replace(u'T', '').replace('-', ''))
    logging.debug('chanid=%s starttime=%s',chanid,starttime)
    logging.info('start clearing markup')
    try:
        rcl = subprocess.Popen(['mythutil','--chanid',str(chanid),'--starttime',str(starttime),'--clearcutlist'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output1 = rcl.communicate()
        if rcl.wait() == 0:
            logging.info('Cutlist removed for:%s_%s',chanid,starttime)
        if rcl.wait() != 0:
            logging.error('MYTHUTIL ERROR: clearing cutlist for:%s_%s',chanid,starttime)
            logging.error('%s',output1)
    except Exception as e:
        logging.error('Mythutil exception clearing cutlist%s',e)
    try:
        rsl = subprocess.Popen(['mythutil','--chanid',str(chanid),'--starttime',str(starttime),'--clearskiplist'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output2 = rsl.communicate()[0]
        if rsl.wait() == 0:
            logging.info('Skiplist removed for:%s_%s',chanid,starttime)
        if rsl.wait() != 0:
            logging.error('MYTHUTIL ERROR: clearing skiplist for:%s_%s',chanid,starttime)
            logging.error('%s',output2)
    except Exception as e:
        logging.error('Mythutil exception clearing skiplist:%s',e)

    for index,mark in reversed(list(enumerate(rec.markup))):
        if mark.type in (rec.markup.MARK_COMM_START, rec.markup.MARK_COMM_END):
            del rec.markup[index]
    rec.bookmark = 0
    rec.cutlist = 0
    rec.commflagged = 0
    rec.markup.commit()
    rec.basename = os.path.basename(infile)
    rec.filesize = os.path.getsize(infile)
    rec.transcoded = 1
    rec.seek.clean()
    rec.update()
    
    try:
        logging.info('Removing PNG files')
        for png in glob('%s*.png' % infile):
            os.remove(png)
    except Exception as e:
        logging.error('Error removing png files',e)
    try:
        logging.info('Removing JPG files')
        for jpg in glob('%s*.jpg' % infile):
            os.remove(jpg)
    except Exception as e:
        logging.error('Error removing jpg files',e)    
    try:
        logging.info('Rebuilding seektable')
        rst = subprocess.Popen(['mythcommflag','--chanid',str(chanid),'--starttime',str(starttime),'--rebuild'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output2 = rst.communicate()[0]
        if rst.wait() == 0:
            logging.info('Seektable Rebuilt for:%s_%s',chanid,starttime)
        if rst.wait() != 0:
            logging.error('MYTHcommflag ERROR: Rebuilding Seektable for:%s_%s',chanid,starttime)
            logging.error('%s',output2)
    except Exception as e:
        logging.error('Mythcommflag ERROR clearing skiplist:%s',e)

def tmp_chk(tmpdir):
        try:
            if os.path.isdir(tmpdir):
                logging.info('temp Folder found:')
                if os.listdir(tmpdir) != 0:
                    logging.warning('Temp folder not empty!:Removing Files:')
                    shutil.rmtree(tmpdir)
                    os.makedirs(tmpdir)
            if not os.path.isdir(tmpdir):
                logging.info('no temp folder found:')
                os.makedirs(tmpdir)
                logging.info('Temp folder created:')
        except Exception as e:
            logging.error('%s',e)
def rem_tmp(tmpdir):
            try:
                if os.path.isdir(tmpdir):
                    logging.info('temp Folder found')
                    shutil.rmtree(tmpdir)
                    logging.info('Temp Folder Removed')
                if not os.path.isdir(tmpdir):
                    logging.info('no temp folder found')
            except Exception as e:
                logging.error('%s',e)
def find_rec(chanid,starttime):
    def local_time_offset(t=None):
        if t is None:
            t = time.time()

        if time.localtime(t).tm_isdst and time.daylight:
            return -time.altzone
        else:
            return -time.timezone

    def RecordedFromBasename(chanid,starttime):
        bnts = '%s_%s.ts' % (chanid,starttime)
        bnmpg = '%s_%s.mpg' % (chanid,starttime)

        x = list(db.searchRecorded(basename=bnmpg))
        if len(x) == 1:
            for recorded in x:
                return recorded
                
        if len(x) != 1:
            x = list(db.searchRecorded(basename=bnts))
            if len(x) == 1:
                for recorded in x:
                    return recorded
            if len(x) != 1:    
                raise LookupError\
        ('unable to find Recorded entry for ChanID %s StartTime %s'\
         % (chanid,starttime))
    try:
        rec = Recorded((chanid,starttime), db=db)
    except:        
        try:
            tzoffset = local_time_offset() / (60*60)
            utcstarttime = datetime.strptime(starttime,"%Y%m%d%H%M%S")
            utcstarttime = utcstarttime + timedelta(hours=tzoffset)
            rec = Recorded((chanid,utcstarttime), db=db)
        except:
            rec = RecordedFromBasename(chanid,starttime)
    return rec
def prog_check():
    if os.access('/usr/bin/ffmpeg', os.X_OK):
        ffmpeg = '/usr/bin/ffmpeg'
    elif os.access('/usr/bin/mythffmpeg', os.X_OK):
        ffmpeg = '/usr/bin/mythffmpeg'
    else:
        ffmpeg = None
    if os.access('/usr/bin/ffprobe', os.X_OK):
        ffprobe ='/usr/bin/ffprobe'
    elif os.access('/usr/bin/mythffprobe', os.X_OK):
        ffprobe = '/usr/bin/mythffprobe'
    else:
        ffprobe = None
    if ffmpeg == None or ffprobe == None:
        raise LookupError ('Unable to find ffmpeg/ffprobe')
    return ffmpeg,ffprobe
def main():
    parser = argparse.ArgumentParser(description='MythTV Commercial removal and closed caption extraction tool.\nNOTE:Having .srt file in same dir as media files breaks playback in some media players(VLC)')
    parser.add_argument('--chanid',action='store',type=str,dest='chanid',help='Channel-Id of Recording')
    parser.add_argument('--starttime',action='store',type=str,dest='starttime',help='Starttime of recording in utc format')
    parser.add_argument('--jobid',action='store',type=int,dest='jobid',help='JOBID')
    parser.add_argument('-o',action='store',type=str,dest='outfile',help='Output file to be created')
    args = parser.parse_args()
    if args.jobid:
        run_cut(jobid=args.jobid,outfile=args.outfile)
        sys.exit(0)        
    if args.chanid and args.starttime:
        run_cut(chanid=args.chanid,starttime=args.starttime,outfile=args.outfile)
        sys.exit(0)
    else:
        print 'chanid and starttime or jobid required'
main()
try both as a user job and in a terminal
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

From terminal seems to work:
[root@glutton bin]# ./removecommercials.py --chanid 2501 --starttime 20160912103000
2016-11-21 17:27:05,653:INFO:Started
2016-11-21 17:27:05,655:DEBUG:ffmpeg=/usr/bin/ffmpeg
2016-11-21 17:27:05,655:DEBUG:chanid=2501 starttime=20160912103000
2016-11-21 17:27:05,700:DEBUG:DB recording entry=<Recorded 'The Andy Griffith Show','2016-09-12 06:30:00-04:00' at 0x2cfceb0>
2016-11-21 17:27:05,705:INFO:no temp folder found:
2016-11-21 17:27:05,723:INFO:Temp folder created:
2016-11-21 17:27:05,723:INFO:Backing up original file
2016-11-21 17:28:05,502:INFO:Finished backing up original file
2016-11-21 17:28:05,502:INFO:getting cutlist
2016-11-21 17:28:05,511:DEBUG:Myth cutlist:0,8639,43115,50064,90824,108710
2016-11-21 17:28:05,511:DEBUG:FFmpeg cutlist:8639,43115,50064,90824,108710
2016-11-21 17:28:05,511:INFO:cutting started
2016-11-21 17:29:32,244:INFO:Cuting Finished
2016-11-21 17:29:32,245:INFO:Merging Cuts
2016-11-21 17:29:32,245:DEBUG:concat list:/data/mythtv/crtmp/cut001.ts|/data/mythtv/crtmp/cut003.ts
2016-11-21 17:30:20,566:INFO:Merging Finished
2016-11-21 17:30:20,566:INFO:temp Folder found
2016-11-21 17:30:23,544:INFO:Temp Folder Removed
2016-11-21 17:30:23,545:INFO:no temp folder found
2016-11-21 17:30:23,545:INFO:Started Clearing markup
2016-11-21 17:30:23,545:DEBUG:rec=<Recorded 'The Andy Griffith Show','2016-09-12 06:30:00-04:00' at 0x2cfceb0> infile=/data/mythtv/2501_20160912103000.ts outfile=None
2016-11-21 17:30:23,547:DEBUG:chanid=2501 starttime=20160912103000
2016-11-21 17:30:23,547:INFO:start clearing markup
2016-11-21 17:30:25,092:INFO:Cutlist removed for:2501_20160912103000
2016-11-21 17:30:25,885:INFO:Skiplist removed for:2501_20160912103000
2016-11-21 17:31:06,144:INFO:Removing PNG files
2016-11-21 17:31:06,179:INFO:Removing JPG files
2016-11-21 17:31:06,197:INFO:Rebuilding seektable
2016-11-21 17:31:30,105:INFO:Seektable Rebuilt for:2501_20160912103000


-rw-r--r-- 1 root root 1.6G Nov 21 17:28 2501_20160912103000.ts.old
-rw-r--r-- 1 mythtv mythtv 1.2G Nov 21 17:30 2501_20160912103000.ts

It also puts a "transcoded" icon in Mythweb (handy so I know which ones it's been run on, even if an accidental side effect).

Occurs to me some of these show titles have an apostrophe in them. I don't think that's been any of the ones I've been tinkering with, but something I will pay attention to.

It still errors my MYthWeb:
Remove Comms.py (Errored: Mon Nov 21, 2016, 05:34 PM)
ERROR: User Job returned non-zero, check logs.

2016-11-21 17:34:33.531505 I [2341/23564] UserJob_9999 jobqueue.cpp:2410 (DoUserJobThread) - JobQueue: Started Remove Comms.py for "The Andy Griffith Show":"A Plaque for Mayberry" recorded from channel 2501 at 2016-09-15T10:30:00Z
2016-11-21 17:34:39.319719 E [2341/23564] UserJob_9999 jobqueue.cpp:2445 (DoUserJobThread) - JobQueue: User Job '/usr/local/bin/removecommercials.py --jobid 9999' failed.


Thanks for all of your help!
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

since it works in a terminal, try it as a userjob with --chanid %CHANID% --starttime %STARTTIMEUTC%.
The transcoded flag is intentional for the reason you stated.
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

If I take the exact line from the log and run it, it runs (as root).

If I try this (running as mythtv) it fails:
[root@glutton bin]# su mythtv
[mythtv@glutton bin]$ removecommercials.py --chanid 2501 --starttime 20160922103000
Traceback (most recent call last):
File "/usr/local/bin/removecommercials.py", line 16, in <module>
db=MythDB()
File "/usr/lib/python2.7/site-packages/MythTV/database.py", line 1275, in __init__
raise MythDBError(MythError.DB_CREDENTIALS)
MythTV.exceptions.MythDBError: Could not find database login credentials
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

check /home/mythtv/.mythtv/config.xml and see if it has correct info and if the mythtv user has read/write permissions
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

I didn't have a /home/mythtv/.mythtv/config.xml file. I did have a /root/.mythtv/config.xml file, and copied it to /home/mythtv/.mythtv/config.xml

That made it work from su mythtv

Running it from mythweb, I still get:
Remove Comms.py (Errored: Tue Nov 22, 2016, 01:07 AM)
ERROR: User Job returned non-zero, check logs.

2016-11-22 01:07:33.583897 E [2341/757] UserJob_10061 jobqueue.cpp:2445 (DoUserJobThread) - JobQueue: User Job 'removecommercials.py --chanid 2502 --starttime 20161007000000' failed.
(note I changed the path to not include '/usr/local/bin' because I noticed my old script didn't include that.)

BUT I now get a .old file, and a /tmp/cut.log file:
2016-11-21 22:45:52,543:INFO:Started
2016-11-21 22:45:52,548:DEBUG:ffmpeg=/usr/bin/ffmpeg
2016-11-21 22:45:52,549:DEBUG:chanid=2501 starttime=20160915103000
2016-11-21 22:45:52,586:DEBUG:DB recording entry=<Recorded 'The Andy Griffith Show','2016-09-15 06:30:00-04:00' at 0x1a52cf0>
2016-11-21 22:45:52,590:INFO:no temp folder found:
2016-11-21 22:45:53,348:INFO:Temp folder created:
2016-11-21 22:45:53,348:INFO:Backing up original file
2016-11-21 22:46:35,754:INFO:Finished backing up original file
2016-11-21 22:46:35,754:INFO:getting cutlist
2016-11-21 22:46:35,763:DEBUG:Myth cutlist:0,9144,48436,54812,92566,108730
2016-11-21 22:46:35,763:DEBUG:FFmpeg cutlist:9144,48436,54812,92566,108730
2016-11-21 22:46:35,763:INFO:cutting started
2016-11-21 22:47:28,876:INFO:Cuting Finished
2016-11-21 22:47:28,876:INFO:Merging Cuts
2016-11-21 22:47:28,876:DEBUG:concat list:/data/mythtv/crtmp/cut001.ts|/data/mythtv/crtmp/cut003.ts
2016-11-21 22:48:05,663:INFO:Merging Finished
2016-11-21 22:48:05,664:INFO:temp Folder found
2016-11-21 22:48:06,280:INFO:Temp Folder Removed
2016-11-21 22:48:06,280:INFO:no temp folder found
2016-11-21 22:48:06,281:INFO:Started Clearing markup
2016-11-21 22:48:06,281:DEBUG:rec=<Recorded 'The Andy Griffith Show','2016-09-15 06:30:00-04:00' at 0x1a52cf0> infile=/data/mythtv/2501_20160915103000.ts outfile=None
2016-11-21 22:48:06,282:DEBUG:chanid=2501 starttime=20160915103000
2016-11-21 22:48:06,283:INFO:start clearing markup
2016-11-21 22:48:07,561:INFO:Cutlist removed for:2501_20160915103000
2016-11-21 22:48:08,339:INFO:Skiplist removed for:2501_20160915103000
2016-11-21 22:48:44,628:INFO:Removing PNG files
2016-11-21 22:48:45,397:INFO:Removing JPG files
2016-11-21 22:48:45,413:INFO:Rebuilding seektable
2016-11-21 22:49:12,604:INFO:Seektable Rebuilt for:2501_20160915103000


So there's that :-)

So that means, I think, it's working. Thank you so much for all of your help. Do you think it's possible to get it to not "ERROR: User Job returned non-zero, check logs." by changing the script so that it returns zero?
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

Poking about to see if I can get it to return zero, and I noticed this in the log:
2016-11-21 22:48:05,664:INFO:temp Folder found
2016-11-21 22:48:06,280:INFO:Temp Folder Removed
2016-11-21 22:48:06,280:INFO:no temp folder found
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

At least now we seem have found the source of the problem. The script should be returning 0. You can try removing or commenting out sys.exit(0) on lines 292 and 295.

Code: Select all

    if args.jobid:
        run_cut(jobid=args.jobid,outfile=args.outfile)
        #sys.exit(0)       
    if args.chanid and args.starttime:
        run_cut(chanid=args.chanid,starttime=args.starttime,outfile=args.outfile)
        #sys.exit(0)
    else:
        print 'chanid and starttime or jobid required'
main()
the temp folder part is working correctly. don't remember why i set it up that way. probably just to check that the folder was actually removed.
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

So i made a few changes.
added code to catch the database connection error
removed extra log output from removing temp directory
added set job finished in job queue (only when using --jobid) <-- this should avoid your issue with non 0 exit

Code: Select all

#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
#MythTV commercial removal -- by Daraden
#usage userjob = /path to script/script.py --jobid %JOBID%
#/path to script/script.py --chanid --starttime can also be used
from MythTV import Job, Program, Recorded, System, MythDB, findfile, MythError, MythLog, datetime
import argparse
import subprocess
import os
import sys
import shutil
from glob import glob
import time
from datetime import timedelta
import logging
#set this to True to use commflag results as cut list
use_commflag = True
#save copy of original file as file.old if not using output file
save_old = True
#user needs write access to this directory to save logfile
logdir ='/tmp/'

#logging setup for file and console
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
lf= logging.Formatter('%(asctime)s:%(levelname)s:%(message)s')
try:
    if os.access(logdir,os.W_OK):
        fh = logging.FileHandler(filename='%scut.log'%(logdir),mode='w')
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(lf)
        logger.addHandler(fh)
except:
    pass
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(lf)
logger.addHandler(ch)

try:
    db=MythDB()
except exception as e:
    logging.error(e)
    sys.exit(1)
def run_cut(jobid=None,chanid=None,starttime=None,outfile=None):
    logging.info('Started')
    #check for ffmpeg or mythffmpeg
    ffmpeg = prog_check()[0]
    
    logging.debug('ffmpeg=%s',ffmpeg)

    if jobid:
        job = Job(jobid, db=db)
        chanid = job.chanid
        starttime = job.starttime
        logging.debug('chanid=%s starttime=%s',chanid,starttime)
    if not jobid:
        chanid = chanid
        starttime = starttime
        logging.debug('chanid=%s starttime=%s',chanid,starttime)

    rec = find_rec(chanid,starttime)
    logging.debug('DB recording entry=%s',rec)
    sg = findfile('/'+rec.basename, rec.storagegroup, db=db)
    infile = os.path.join(sg.dirname, rec.basename)
    tmpdir = sg.dirname +'crtmp/'
    tmp_chk(tmpdir)

    if save_old == True and outfile == None:
        logging.info('Backing up original file')
        shutil.copyfile(infile,'%s.old' % infile)
        logging.info('Finished backing up original file')
    if outfile != None:
        Outfile = outfile
    elif outfile == None:
        Outfile = infile

    if rec.cutlist == 1 or use_commflag == True:
        if jobid:
            job.update({'status':job.RUNNING, 'comment':'Removing Cutlist'})
        logging.info('getting cutlist')
        if rec.cutlist == 1:
            cut_list =''.join(str(rec.markup.getcutlist())).replace('[','').replace(']','').replace('(','').replace(')','').replace(' ','')
        elif rec.cutlist == 0 and rec.commflagged == 1:
            cut_list =''.join(str(rec.markup.getskiplist())).replace('[','').replace(']','').replace('(','').replace(')','').replace(' ','')
        else:
            logging.debug('No cut/skip list found')
            sys.exit(1)            
        cutlist = cut_list
        if cutlist.startswith('0,'):
            cutlist = cutlist.replace("0,",'',1)
        if cutlist.endswith(',9999999'):
            cutlist = cutlist.replace(",9999999",'',-1)
        logging.debug('Myth cutlist:%s',cut_list)
        logging.debug('FFmpeg cutlist:%s',cutlist)
        logging.info('cutting started')
        cut =subprocess.Popen([ffmpeg,'-i',infile,'-c','copy','-map','0','-f','segment','-segment_list','%scut.ffcat'%(tmpdir),'-segment_frames',cutlist,'%scut%%03d.ts'%(tmpdir)],stdout = subprocess.PIPE, stderr = subprocess.STDOUT,universal_newlines=True)
        output = cut.communicate()[0]
        if cut.wait() == 0:
            if jobid:
                job.update({'status':job.RUNNING, 'comment':'Cuting Finished'})
            logging.info('Cuting Finished')
        if cut.wait() != 0:
            if jobid:
                job.update({'status':job.ERRORED, 'comment':'FFMPEG ERROR: cutiing'})
            logging.error('FFMPEG ERROR: cutiing')
            logging.error('%s',output)
            sys.exit(1)

        if jobid:
            job.update({'status':job.RUNNING, 'comment':'Merging Cuts'})
        logging.info('Merging Cuts')
        j = []
        for root, dirs, files in os.walk(tmpdir):
            for files in files:
                if files.endswith('.ts') and files.startswith('cut'):
                    if os.path.isfile(os.path.join(root,files)):
                        j.append(os.path.join(root,files))
        if cut_list.startswith('0,'):
          ls = j[1::2]
        if not cut_list.startswith('0,'):
          ls = j[0::2]
        q =','.join(ls).replace(',','|')
        logging.debug('concat list:%s' % q)
        join =subprocess.Popen([ffmpeg,'-y','-i','concat:%s'%q,'-map','0','-c','copy','-f','mpegts',Outfile],stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output = join.communicate()[0]
        if join.wait() == 0:
            if jobid:
                job.update({'status':job.RUNNING, 'comment':'Merging Finished'})
            logging.info('Merging Finished')
        if join.wait() != 0:
            if jobid:
                job.update({'status':job.ERRORED, 'comment':'FFMPEG ERROR: merging'})
            logging.error('FFMPEG ERROR: merging')
            logging.error('%s',output)
            sys.exit(1)
    rem_tmp(tmpdir)
    if  outfile == None:
        clear_markup(rec,infile,outfile)
    if jobid:
        job.update({'status':job.FINISHED, 'comment':'Commercial removal Completed'})


def clear_markup(rec,infile,outfile):
    logging.info('Started Clearing markup')
    
    logging.debug('rec=%s infile=%s outfile=%s',rec,infile,outfile)
    chanid = rec.chanid
    utcstarttime = rec.starttime
    starttime = str(utcstarttime.utcisoformat().replace(u':', '').replace(u' ', '').replace(u'T', '').replace('-', ''))
    logging.debug('chanid=%s starttime=%s',chanid,starttime)
    logging.info('start clearing markup')
    try:
        rcl = subprocess.Popen(['mythutil','--chanid',str(chanid),'--starttime',str(starttime),'--clearcutlist'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output1 = rcl.communicate()
        if rcl.wait() == 0:
            logging.info('Cutlist removed for:%s_%s',chanid,starttime)
        if rcl.wait() != 0:
            logging.error('MYTHUTIL ERROR: clearing cutlist for:%s_%s',chanid,starttime)
            logging.error('%s',output1)
    except Exception as e:
        logging.error('Mythutil exception clearing cutlist%s',e)
    try:
        rsl = subprocess.Popen(['mythutil','--chanid',str(chanid),'--starttime',str(starttime),'--clearskiplist'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output2 = rsl.communicate()[0]
        if rsl.wait() == 0:
            logging.info('Skiplist removed for:%s_%s',chanid,starttime)
        if rsl.wait() != 0:
            logging.error('MYTHUTIL ERROR: clearing skiplist for:%s_%s',chanid,starttime)
            logging.error('%s',output2)
    except Exception as e:
        logging.error('Mythutil exception clearing skiplist:%s',e)

    for index,mark in reversed(list(enumerate(rec.markup))):
        if mark.type in (rec.markup.MARK_COMM_START, rec.markup.MARK_COMM_END):
            del rec.markup[index]
    rec.bookmark = 0
    rec.cutlist = 0
    rec.commflagged = 0
    rec.markup.commit()
    rec.basename = os.path.basename(infile)
    rec.filesize = os.path.getsize(infile)
    rec.transcoded = 1
    rec.seek.clean()
    rec.update()
    
    try:
        logging.info('Removing PNG files')
        for png in glob('%s*.png' % infile):
            os.remove(png)
    except Exception as e:
        logging.error('Error removing png files',e)
    try:
        logging.info('Removing JPG files')
        for jpg in glob('%s*.jpg' % infile):
            os.remove(jpg)
    except Exception as e:
        logging.error('Error removing jpg files',e)    
    try:
        logging.info('Rebuilding seektable')
        rst = subprocess.Popen(['mythcommflag','--chanid',str(chanid),'--starttime',str(starttime),'--rebuild'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        output2 = rst.communicate()[0]
        if rst.wait() == 0:
            logging.info('Seektable Rebuilt for:%s_%s',chanid,starttime)
        if rst.wait() != 0:
            logging.error('MYTHcommflag ERROR: Rebuilding Seektable for:%s_%s',chanid,starttime)
            logging.error('%s',output2)
    except Exception as e:
        logging.error('Mythcommflag ERROR clearing skiplist:%s',e)

def tmp_chk(tmpdir):
        try:
            if os.path.isdir(tmpdir):
                logging.info('temp Folder found:')
                if os.listdir(tmpdir) != 0:
                    logging.warning('Temp folder not empty!:Removing Files:')
                    shutil.rmtree(tmpdir)
                    os.makedirs(tmpdir)
            if not os.path.isdir(tmpdir):
                logging.info('no temp folder found:')
                os.makedirs(tmpdir)
                logging.info('Temp folder created:')
        except Exception as e:
            logging.error('%s',e)
def rem_tmp(tmpdir):
            try:
                if os.path.isdir(tmpdir):
                    logging.info('temp Folder found')
                    shutil.rmtree(tmpdir)
                if not os.path.isdir(tmpdir):
                    logging.info('Temp Folder Removed')
            except Exception as e:
                logging.error('%s',e)
def find_rec(chanid,starttime):
    def local_time_offset(t=None):
        if t is None:
            t = time.time()

        if time.localtime(t).tm_isdst and time.daylight:
            return -time.altzone
        else:
            return -time.timezone

    def RecordedFromBasename(chanid,starttime):
        bnts = '%s_%s.ts' % (chanid,starttime)
        bnmpg = '%s_%s.mpg' % (chanid,starttime)

        x = list(db.searchRecorded(basename=bnmpg))
        if len(x) == 1:
            for recorded in x:
                return recorded
                
        if len(x) != 1:
            x = list(db.searchRecorded(basename=bnts))
            if len(x) == 1:
                for recorded in x:
                    return recorded
            if len(x) != 1:    
                raise LookupError\
        ('unable to find Recorded entry for ChanID %s StartTime %s'\
         % (chanid,starttime))
    try:
        rec = Recorded((chanid,starttime), db=db)
    except:        
        try:
            tzoffset = local_time_offset() / (60*60)
            utcstarttime = datetime.strptime(starttime,"%Y%m%d%H%M%S")
            utcstarttime = utcstarttime + timedelta(hours=tzoffset)
            rec = Recorded((chanid,utcstarttime), db=db)
        except:
            rec = RecordedFromBasename(chanid,starttime)
    return rec
def prog_check():
    if os.access('/usr/bin/ffmpeg', os.X_OK):
        ffmpeg = '/usr/bin/ffmpeg'
    elif os.access('/usr/bin/mythffmpeg', os.X_OK):
        ffmpeg = '/usr/bin/mythffmpeg'
    else:
        ffmpeg = None
    if os.access('/usr/bin/ffprobe', os.X_OK):
        ffprobe ='/usr/bin/ffprobe'
    elif os.access('/usr/bin/mythffprobe', os.X_OK):
        ffprobe = '/usr/bin/mythffprobe'
    else:
        ffprobe = None
    if ffmpeg == None or ffprobe == None:
        raise LookupError ('Unable to find ffmpeg/ffprobe')
    return ffmpeg,ffprobe
def main():
    parser = argparse.ArgumentParser(description='MythTV Commercial removal and closed caption extraction tool.\nNOTE:Having .srt file in same dir as media files breaks playback in some media players(VLC)')
    parser.add_argument('--chanid',action='store',type=str,dest='chanid',help='Channel-Id of Recording')
    parser.add_argument('--starttime',action='store',type=str,dest='starttime',help='Starttime of recording in utc format')
    parser.add_argument('--jobid',action='store',type=int,dest='jobid',help='JOBID')
    parser.add_argument('-o',action='store',type=str,dest='outfile',help='Output file to be created')
    args = parser.parse_args()
    if args.jobid:
        run_cut(jobid=args.jobid,outfile=args.outfile)
        sys.exit(0)        
    if args.chanid and args.starttime:
        run_cut(chanid=args.chanid,starttime=args.starttime,outfile=args.outfile)
        sys.exit(0)
    else:
        print 'chanid and starttime or jobid required'
main()
ricks03
Junior
Posts: 67
Joined: Thu Oct 01, 2015 8:59 pm
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by ricks03 »

Heck I thought we were done :-) I've fixed it so that the logs roll over and expire, and each separate task (when running more than one at a time) goes in its own folder, as well as some of my own modifications to the logs. Thanks, I'll merge these in!
daraden
Senior
Posts: 175
Joined: Tue Feb 23, 2016 7:33 am
United States of America

Re: Anyone else having problems with commercial removal in 0

Post by daraden »

not sure when i will be done, still have a list of changes to make. luckily they are wants not needs.
Post Reply