| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 |  | 
|---|
| 4 |  | 
|---|
| 5 |  | 
|---|
| 6 |  | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | use DBI; | 
|---|
| 15 | use DBD::Pg; | 
|---|
| 16 | use Schedule::At; | 
|---|
| 17 | use Time::Local; | 
|---|
| 18 |  | 
|---|
| 19 | $path = $0; | 
|---|
| 20 | $path =~ s/addpidatq.pl$//i; | 
|---|
| 21 | if ($pwd  ne "./"){ | 
|---|
| 22 | push( @INC, "$path"); | 
|---|
| 23 | } | 
|---|
| 24 |  | 
|---|
| 25 | require "foltialib.pl"; | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | $pid = $ARGV[0] ; | 
|---|
| 30 | if ($pid eq "" ){ | 
|---|
| 31 |  | 
|---|
| 32 | print "usage;addpidatq.pl <PID>\n"; | 
|---|
| 33 | exit; | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", | 
|---|
| 39 | $DBDriv,$DBName,$DBHost,$DBPort); | 
|---|
| 40 | $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; | 
|---|
| 41 |  | 
|---|
| 42 | $DBQuery =  "SELECT count(*) FROM  foltia_subtitle WHERE pid = '$pid' "; | 
|---|
| 43 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 44 | $sth->execute(); | 
|---|
| 45 | @titlecount= $sth->fetchrow_array; | 
|---|
| 46 |  | 
|---|
| 47 | if ($titlecount[0]  == 1 ){ | 
|---|
| 48 |  | 
|---|
| 49 | $DBQuery =  "SELECT bitrate,digital FROM  foltia_tvrecord , foltia_subtitle  WHERE foltia_tvrecord.tid = foltia_subtitle.tid AND pid='$pid' "; | 
|---|
| 50 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 51 | $sth->execute(); | 
|---|
| 52 | @titlecount= $sth->fetchrow_array; | 
|---|
| 53 | $bitrate = $titlecount[0]; | 
|---|
| 54 | if ($titlecount[1] >= 1){ | 
|---|
| 55 | $usedigital = $titlecount[1]; | 
|---|
| 56 | }else{ | 
|---|
| 57 | $usedigital = 0; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | $now = &epoch2foldate(`date +%s`); | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | $DBQuery =  "SELECT stationrecch,digitalch ,digitalstationband ,foltia_station.stationid  FROM foltia_station,foltia_subtitle WHERE foltia_subtitle.pid = '$pid'  AND  foltia_subtitle.stationid =  foltia_station.stationid "; | 
|---|
| 65 |  | 
|---|
| 66 | $stationh = $dbh->prepare($DBQuery); | 
|---|
| 67 | $stationh->execute(); | 
|---|
| 68 | @stationl =  $stationh->fetchrow_array; | 
|---|
| 69 | $recch = $stationl[0]; | 
|---|
| 70 | if ($recch eq ""){ | 
|---|
| 71 | &writelog("addpidatq ERROR recch is NULL:$DBQuery."); | 
|---|
| 72 | exit 1; | 
|---|
| 73 | } | 
|---|
| 74 | if ($stationl[1] => 1){ | 
|---|
| 75 | $digitalch = $stationl[1]; | 
|---|
| 76 | }else{ | 
|---|
| 77 | $digitalch = 0; | 
|---|
| 78 | } | 
|---|
| 79 | if ($stationl[2] => 1){ | 
|---|
| 80 | $digitalstationband = $stationl[2]; | 
|---|
| 81 | }else{ | 
|---|
| 82 | $digitalstationband = 0; | 
|---|
| 83 | } | 
|---|
| 84 | $DBQuery =  "SELECT  * FROM  foltia_subtitle WHERE pid='$pid' "; | 
|---|
| 85 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 86 | $sth->execute(); | 
|---|
| 87 | ($pid , | 
|---|
| 88 | $tid , | 
|---|
| 89 | $stationid , | 
|---|
| 90 | $countno, | 
|---|
| 91 | $subtitle, | 
|---|
| 92 | $startdatetime, | 
|---|
| 93 | $enddatetime, | 
|---|
| 94 | $startoffset , | 
|---|
| 95 | $lengthmin, | 
|---|
| 96 | $atid ) = $sth->fetchrow_array(); | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | if($now< $startdatetime){ | 
|---|
| 100 |  | 
|---|
| 101 | $startafter = &calclength($now,$startdatetime); | 
|---|
| 102 | &writelog("addpidatq DEBUG \$startafter $startafter \$now $now \$startdatetime $startdatetime"); | 
|---|
| 103 |  | 
|---|
| 104 | if ($startafter > 14 ){ | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 | Schedule::At::remove ( TAG => "$pid"."_X"); | 
|---|
| 108 | &writelog("addpidatq remove que $pid"); | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 |  | 
|---|
| 113 | $atdateparam = &calcatqparam(300); | 
|---|
| 114 | Schedule::At::add (TIME => "$atdateparam", COMMAND => "$toolpath/perl/folprep.pl $pid" , TAG => "$pid"."_X"); | 
|---|
| 115 | &writelog("addpidatq TIME $atdateparam   COMMAND $toolpath/perl/folprep.pl $pid "); | 
|---|
| 116 | }else{ | 
|---|
| 117 | $atdateparam = &calcatqparam(60); | 
|---|
| 118 | $reclength = $lengthmin * 60; | 
|---|
| 119 |  | 
|---|
| 120 |  | 
|---|
| 121 | Schedule::At::remove ( TAG => "$pid"."_R"); | 
|---|
| 122 | &writelog("addpidatq remove que $pid"); | 
|---|
| 123 |  | 
|---|
| 124 | if ($countno eq ""){ | 
|---|
| 125 | $countno = "0"; | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | Schedule::At::add (TIME => "$atdateparam", COMMAND => "$toolpath/perl/recwrap.pl $recch $reclength $bitrate $tid $countno $pid $stationid $usedigital $digitalstationband $digitalch" , TAG => "$pid"."_R"); | 
|---|
| 129 | &writelog("addpidatq TIME $atdateparam   COMMAND $toolpath/perl/recwrap.pl $recch $reclength $bitrate $tid $countno $pid $stationid $usedigital $digitalstationband $digitalch"); | 
|---|
| 130 |  | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | }else{ | 
|---|
| 134 | &writelog("addpidatq drop:expire $pid $startafter $now $startdatetime"); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | }else{ | 
|---|
| 138 | print "error record TID=$tid SID=$station $titlecount[0] match:$DBQuery\n"; | 
|---|
| 139 | &writelog("addpidatq error record TID=$tid SID=$station $titlecount[0] match:$DBQuery"); | 
|---|
| 140 |  | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 |  | 
|---|