143
145
logdebug("exportdir = $exportdir");
144
146
logdebug("starttime = @starttime");
145
147
logdebug("chanid = @chanid");
146
logdebug("config = $block");
148
logdebug("config = $config");
148
150
$exportdir =~ s/\/$//;
150
152
my $export_cfg = new Config::Simple();
151
153
$export_cfg->read('/etc/mythtv/mythexport/mythexport_settings.cfg') || logerror("Cannot read config file: /etc/mythtv/mythexport/mythexport_settings.cfg");
155
require "$config.pm";
157
my $object = new $config();
158
my $extension = $object->Extension;
153
my $exportdevice = $export_cfg->param("$block.device") unless ref $export_cfg->param("$block.device") eq 'ARRAY';
154
my $extension = $export_cfg->param("$block.extension") unless ref $export_cfg->param("$block.extension") eq 'ARRAY';
160
#my $exportdevice = $export_cfg->param("$block.device") unless ref $export_cfg->param("$block.device") eq 'ARRAY';
161
#my $extension = $export_cfg->param("$block.extension") unless ref $export_cfg->param("$block.extension") eq 'ARRAY';
156
163
#test that the directory has the correct permissions
157
164
-w $exportdir || logerror("ERROR: Directory $exportdir is not writeable.\n");
333
340
$chanid = (split(/\=/,$_))[1];
335
342
elsif ($_ =~ m/config/) {
336
$block = (split(/\=/,$_))[1];
343
$config = (split(/\=/,$_))[1];
345
elsif ($_ =~ m/deleteperiod/) {
346
$deleteperiod = (split(/\=/,$_))[1];
338
348
elsif ($_ =~ m/otg/) {
339
$block = (split(/\=/,$_))[1];
349
$otg = (split(/\=/,$_))[1];
351
elsif ($_ =~ m/podcastname/) {
352
$podcastname = (split(/\=/,$_))[1];
343
my $export_cfg = new Config::Simple();
344
$export_cfg->read('/etc/mythtv/mythexport/mythexport_settings.cfg') || logerror("Cannot read config file: /etc/mythtv/mythexport/mythexport_settings.cfg");
345
my $delete_period = 30;
347
my $exportdevice = $export_cfg->param("$block.device") unless ref $export_cfg->param("$block.device") eq 'ARRAY';
348
my $exportcodec = $export_cfg->param("$block.codec") unless ref $export_cfg->param("$block.codec") eq 'ARRAY';
349
$delete_period = $export_cfg->param("$block.deletePeriod") unless ref $export_cfg->param("$block.deletePeriod") eq 'ARRAY';
350
my $podcast_name = $export_cfg->param("$block.podcastName") unless ref $export_cfg->param("$block.podcastName") eq 'ARRAY';
351
my $args = $export_cfg->param("$block.ffmpegArgs") unless ref $export_cfg->param("$block.ffmpegArgs") eq 'ARRAY';
352
my $removeCommercials = $export_cfg->param("$block.removeCommercials") unless ref $export_cfg->param("$block.removeCommercials") eq 'ARRAY';
353
my $extension = $export_cfg->param("$block.extension") unless ref $export_cfg->param("$block.extension") eq 'ARRAY';
355
my @args = split('\|',$args);
356
#my $export_cfg = new Config::Simple();
357
#$export_cfg->read('/etc/mythtv/mythexport/mythexport_settings.cfg') || logerror("Cannot read config file: /etc/mythtv/mythexport/mythexport_settings.cfg");
358
#my $delete_period = 30;
360
#my $exportdevice = $export_cfg->param("$block.device") unless ref $export_cfg->param("$block.device") eq 'ARRAY';
361
#my $exportcodec = $export_cfg->param("$block.codec") unless ref $export_cfg->param("$block.codec") eq 'ARRAY';
362
#$delete_period = $export_cfg->param("$block.deletePeriod") unless ref $export_cfg->param("$block.deletePeriod") eq 'ARRAY';
363
#my $podcast_name = $export_cfg->param("$block.podcastName") unless ref $export_cfg->param("$block.podcastName") eq 'ARRAY';
364
#my $args = $export_cfg->param("$block.ffmpegArgs") unless ref $export_cfg->param("$block.ffmpegArgs") eq 'ARRAY';
365
#my $removeCommercials = $export_cfg->param("$block.removeCommercials") unless ref $export_cfg->param("$block.removeCommercials") eq 'ARRAY';
366
#my $extension = $export_cfg->param("$block.extension") unless ref $export_cfg->param("$block.extension") eq 'ARRAY';
368
#my @args = split('\|',$args);
357
370
my ($title, $subtitle, $description, $syndicatedepisodenumber, $showtype, $programid, $basename, $airdate) = "";
439
452
# move to the export directory incase any logs get written
440
453
chdir $exportdir;
455
#my $symlinkCmd = "";
446
if ($removeCommercials){
458
# move this to the new modules???
460
#if ($removeCommercials){
447
461
# First generate the cutlist from the flagged commercials
448
logdebug("command = nice -n19 mythcommflag --chanid $chanid --starttime $starttime --gencutlist 2>&1");
449
system("nice -n19 mythcommflag --chanid $chanid --starttime $starttime --gencutlist 2>&1") == 0 || logerror("ERROR: error generating cutlist for commercial removal");
462
# logdebug("command = nice -n19 mythcommflag --chanid $chanid --starttime $starttime --gencutlist 2>&1");
463
# system("nice -n19 mythcommflag --chanid $chanid --starttime $starttime --gencutlist 2>&1") == 0 || logerror("ERROR: error generating cutlist for commercial removal");
451
465
# Now transcode using that cutlist
452
logdebug("command = nice -n19 mythtranscode --mpeg2 --honorcutlist --showprogress --chanid $chanid --starttime $starttime 2>&1");
453
system("nice -n19 mythtranscode --mpeg2 --honorcutlist --showprogress --chanid $chanid --starttime $starttime 2>&1") == 0 || logerror("ERROR: error removing commercials");
455
$transcodeTemp = "$filename.tmp";
456
$filename = $transcodeTemp;
459
if ($exportdevice eq "symlink"){
460
$symlinkCmd = "ln -s $filename $newfilename";
462
elsif ($extension ne ""){
463
$newfilename .= $extension;
464
$webfilename .= $extension;
466
elsif ($exportdevice eq "mp3"){
467
$newfilename .= ".mp3";
468
$webfilename .= ".mp3";
470
elsif ($exportdevice eq "archos"){
471
$newfilename .= ".avi";
472
$webfilename .= ".avi";
475
$newfilename .= ".mp4";
476
$webfilename .= ".mp4";
466
# logdebug("command = nice -n19 mythtranscode --mpeg2 --honorcutlist --showprogress --chanid $chanid --starttime $starttime 2>&1");
467
# system("nice -n19 mythtranscode --mpeg2 --honorcutlist --showprogress --chanid $chanid --starttime $starttime 2>&1") == 0 || logerror("ERROR: error removing commercials");
469
# $transcodeTemp = "$filename.tmp";
470
# $filename = $transcodeTemp;
473
#if ($exportdevice eq "symlink"){
474
# $symlinkCmd = "ln -s $filename $newfilename";
476
#elsif ($extension ne ""){
477
# $newfilename .= $extension;
478
# $webfilename .= $extension;
480
#elsif ($exportdevice eq "mp3"){
481
# $newfilename .= ".mp3";
482
# $webfilename .= ".mp3";
484
#elsif ($exportdevice eq "archos"){
485
# $newfilename .= ".avi";
486
# $webfilename .= ".avi";
489
# $newfilename .= ".mp4";
490
# $webfilename .= ".mp4";
480
if($_ =~ m/\/dev\/null/){
481
$_ = "nice -n19 ffmpeg -i $filename $_";
484
$_ = "nice -n19 ffmpeg -i $filename $_ '$newfilename' 2>&1";
494
# if($_ =~ m/\/dev\/null/){
495
# $_ = "nice -n19 ffmpeg -i $filename $_";
498
# $_ = "nice -n19 ffmpeg -i $filename $_ '$newfilename' 2>&1";
488
502
# Run the commands
490
$log->notice("Exporting $newfilename");
491
logdebug("command = $_");
492
system($_) == 0|| logerror("ERROR: $_ FAILED/");
495
if ($removeCommercials){
496
unlink($transcodeTemp) || logerror("ERROR: cannot remove $transcodeTemp.");
499
# only continue if ffmpeg didn't fail
500
if (-e $newfilename){
502
if (!$debug && @args > 1){
504
# $log->notice("Exporting $newfilename");
505
# logdebug("command = $_");
506
# system($_) == 0|| logerror("ERROR: $_ FAILED/");
509
#if ($removeCommercials){
510
# unlink($transcodeTemp) || logerror("ERROR: cannot remove $transcodeTemp.");
513
require "$config.pm";
515
my $object = new $config($filename, $newfilename);
516
my $extension = $object->Extension();
519
my $returnCode = $object->checkOutput();
521
# only continue if encoding didn't fail
522
if ($returnCode == 1){
503
525
# clean up any log files left behind by ffmpeg
504
526
system "rm *.log";
507
529
# Update mp4 info using AtomicParsley
508
530
# need to fix this so movies actually show up as movies.
509
if ($newfilename eq ".mp4" && $webfilename eq ".mp4"){
510
$APcommand = "AtomicParsley '$newfilename' --genre \"TV Shows\" --stik \"TV Show\" --TVNetwork $channame --TVShowName \"$title_old\" --TVEpisode \"$programid\" --TVEpisodeNum $episodenumber --TVSeason $seasonnumber --description \"$description\" --title \"$subtitle_old\" 2>&1";
531
#if ($newfilename eq ".mp4" && $webfilename eq ".mp4"){
532
# $APcommand = "AtomicParsley '$newfilename' --genre \"TV Shows\" --stik \"TV Show\" --TVNetwork $channame --TVShowName \"$title_old\" --TVEpisode \"$programid\" --TVEpisodeNum $episodenumber --TVSeason $seasonnumber --description \"$description\" --title \"$subtitle_old\" 2>&1";
514
logdebug("command = $APcommand");
515
system($APcommand) == 0 || logerror("ERROR: $APcommand FAILED");
516
system "rm $newfilename";
517
system "mv $exportdir/*temp* $newfilename";
520
system($symlinkCmd) == 0 || logerror("ERROR: $symlinkCmd FAILED");
522
(-e $newfilename) || logerror("ERROR: $newfilename is not available");
536
# logdebug("command = $APcommand");
537
# system($APcommand) == 0 || logerror("ERROR: $APcommand FAILED");
538
# system "rm $newfilename";
539
# system "mv $exportdir/*temp* $newfilename";
542
# system($symlinkCmd) == 0 || logerror("ERROR: $symlinkCmd FAILED");
544
#(-e $newfilename) || logerror("ERROR: $newfilename is not available");
524
546
if($otg ne "true"){
526
548
$query = "INSERT into mythexport VALUES(NULL,?,?,?,?,NOW(),DATE_ADD(NOW(),INTERVAL ? DAY),?,?)";
527
549
$query_handle = $connect->prepare($query);
528
550
logdebug("query = $query");
529
$query_handle->execute($webfilename,$title_old,$subtitle,$description,$delete_period,$airdate,$podcast_name) || logerror("ERROR: Unable to update table.");
551
$query_handle->execute("$webfilename$extension",$title_old,$subtitle,$description,$deleteperiod,$airdate,$podcastname) || logerror("ERROR: Unable to update table.");