root/trunk/install/perl/addatq.pl

リビジョン 1, 4.3 kB (コミッタ: jplcom, コミット時期: 18 年 前)

initial import

  • svn:executable 属性の設定値:
Line 
1 #!/usr/bin/perl
2 #
3 # Anime recording system foltia
4 # http://www.dcc-jpl.com/soft/foltia/
5 #
6 #addatq.pl
7 #
8 #TIDと局IDを受け取りatqに入れる
9 # addatq.pl <TID> <StationID> [DELETE]
10 # DELETEフラグがつくと削除のみ行う
11 #
12 # DCC-JPL Japan/foltia project
13 #
14 #
15
16 use DBI;
17 use DBD::Pg;
18 use Schedule::At;
19 use Time::Local;
20
21 $path = $0;
22 $path =~ s/addatq.pl$//i;
23 if ($pwd  ne "./"){
24 push( @INC, "$path");
25 }
26
27 require "foltialib.pl";
28
29 #引き数がアルか?
30 $tid = $ARGV[0] ;
31 $station = $ARGV[1];
32
33 if (($tid eq "" )|| ($station eq "")){
34         #引き数なし出実行されたら、終了
35         print "usage;addatq.pl <TID> <StationID> [DELETE]\n";
36         exit;
37 }
38
39 #DB検索(TIDとStationIDからPIDへ)
40  $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
41                 $DBDriv,$DBName,$DBHost,$DBPort);
42          $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
43
44 if ($station == 0){
45         $DBQuery =  "SELECT count(*) FROM  foltia_tvrecord WHERE tid = '$tid'  ";
46 }else{
47         $DBQuery =  "SELECT count(*) FROM  foltia_tvrecord WHERE tid = '$tid' AND stationid  = '$station' ";
48 }
49          $sth = $dbh->prepare($DBQuery);
50         $sth->execute();
51  @titlecount = $sth->fetchrow_array;
52 #件数数える
53
54 #2以上だったら
55 if ($titlecount[0]  >= 2){
56         #全曲取りが含まれているか調べる
57         $DBQuery =  "SELECT count(*) FROM  foltia_tvrecord WHERE tid = '$tid'  AND  stationid  ='0' ";
58         $kth = $dbh->prepare($DBQuery);
59         $kth->execute();
60         @reservecounts = $kth->fetchrow_array;
61
62         if($reservecounts[0] >= 1 ){#含まれていたら
63                 if($tid == 0){
64                 #今回の引き数がSID 0だったら
65                 #全局取りだけ予約
66 #               &writelog("addatq  DEBUG; ALL STATION RESERVE. TID=$tid SID=$station $titlecount[0] match:$DBQuery");
67                 &addcue;
68                 }else{
69                 #ほかの全局録画addatqが予約入れてくれるからなにもしない
70 #               &writelog("addatq  DEBUG; SKIP OPERSTION. TID=$tid SID=$station $titlecount[0] match:$DBQuery");
71                 exit;
72                 }#end if ふくまれていたら
73         }#endif 2つ以上   
74 }elsif($titlecount[0]  == 1){
75                 &addcue;
76 }else{
77 &writelog("addatq  error; reserve impossible . TID=$tid SID=$station $titlecount[0] match:$DBQuery");
78 }
79
80 #旧処理
81 # if ($titlecount[0]  == 1 ){
82 #       & addcue;
83 # }else{
84 #&writelog("addatq  error record TID=$tid SID=$station $titlecount[0] match:$DBQuery");
85 #}
86
87 sub addcue{
88
89 if ($station == 0){
90         $DBQuery =  "SELECT * FROM  foltia_tvrecord WHERE tid = '$tid'  ";
91 }else{
92         $DBQuery =  "SELECT * FROM  foltia_tvrecord WHERE tid = '$tid' AND stationid  = '$station' ";
93 }
94  $sth = $dbh->prepare($DBQuery);
95 $sth->execute();
96  @titlecount= $sth->fetchrow_array;
97 $bitrate = $titlecount[2];#ビットレート取得
98
99 #PID抽出
100 $now = &epoch2foldate(`date +%s`);
101 $twodaysafter = &epoch2foldate(`date +%s` + (60 * 60 * 24 * 2));
102 #キュー入れは直近2日後まで
103 if ($station == 0 ){
104         $DBQuery =  "
105 SELECT * from foltia_subtitle WHERE tid = '$tid'  AND startdatetime >  '$now'  AND startdatetime < '$twodaysafter' ";
106 }else{
107         $DBQuery =  "
108 SELECT * from foltia_subtitle WHERE tid = '$tid' AND stationid  = '$station'  AND startdatetime >  '$now'  AND startdatetime < '$twodaysafter' ";
109 #stationIDからrecch
110 $getrecchquery="SELECT stationid , stationrecch  FROM foltia_station where stationid  = '$station' ";
111  $stationh = $dbh->prepare($getrecchquery);
112         $stationh->execute();
113 @stationl =  $stationh->fetchrow_array;
114 $recch = $stationl[1];
115 }
116
117  $sth = $dbh->prepare($DBQuery);
118         $sth->execute();
119  
120 while (($pid ,
121 $tid ,
122 $stationid ,
123 $countno,
124 $subtitle,
125 $startdatetime,
126 $enddatetime,
127 $startoffset ,
128 $lengthmin,
129 $atid ) = $sth->fetchrow_array()) {
130
131 if ($station == 0 ){
132 #stationIDからrecch
133 $getrecchquery="SELECT stationid , stationrecch  FROM foltia_station where stationid  = '$stationid' ";
134  $stationh = $dbh->prepare($getrecchquery);
135         $stationh->execute();
136 @stationl =  $stationh->fetchrow_array;
137 $recch = $stationl[1];
138 }
139 #キュー入れ
140         #プロセス起動時刻は番組開始時刻の-1分
141 $atdateparam = &calcatqparam(300);
142 $reclength = $lengthmin * 60;
143 #&writelog("TIME $atdateparam COMMAND $toolpath/perl/tvrecording.pl $recch $reclength 0 0 $bitrate $tid $countno");
144 #キュー削除
145  Schedule::At::remove ( TAG => "$pid"."_X");
146         &writelog("addatq remove $pid");
147 if ( $ARGV[2] eq "DELETE"){
148         &writelog("addatq remove  only $pid");
149 }else{
150         Schedule::At::add (TIME => "$atdateparam", COMMAND => "$toolpath/perl/folprep.pl $pid" , TAG => "$pid"."_X");
151         &writelog("addatq TIME $atdateparam   COMMAND $toolpath/perl/folprep.pl $pid ");
152 }
153 ##processcheckdate
154 #&writelog("addatq TIME $atdateparam COMMAND $toolpath/perl/schedulecheck.pl");
155 }#while
156
157
158
159 }#endsub
160
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed