| 1 |
#!/usr/bin/perl |
|---|
| 2 |
# |
|---|
| 3 |
# Anime recording system foltia |
|---|
| 4 |
# http://www.dcc-jpl.com/soft/foltia/ |
|---|
| 5 |
# |
|---|
| 6 |
#digitalradiorecording.pl |
|---|
| 7 |
# IPサイマルラジオ「radiko」を録音する。 |
|---|
| 8 |
# |
|---|
| 9 |
#usage digitalradiorecording.pl stationname length(sec) filename |
|---|
| 10 |
#引数 |
|---|
| 11 |
#stationname : radikoの使う曲識別子 例:文化放送 QRR [必須項目] |
|---|
| 12 |
#length(sec) :録画秒数 [必須項目] |
|---|
| 13 |
#filename :出力ファイル名 [必須項目] |
|---|
| 14 |
# |
|---|
| 15 |
# DCC-JPL Japan/foltia project |
|---|
| 16 |
# |
|---|
| 17 |
# |
|---|
| 18 |
|
|---|
| 19 |
$path = $0; |
|---|
| 20 |
$path =~ s/digitalradiorecording.pl$//i; |
|---|
| 21 |
if ($path ne "./"){ |
|---|
| 22 |
push( @INC, "$path"); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
#tvConfig.pl ------------------------------- |
|---|
| 26 |
$extendrecendsec = 10; #recording end second. |
|---|
| 27 |
#$startupsleeptime = 52; #process wait(MAX60sec) |
|---|
| 28 |
$startupsleeptime = 57; #process wait(MAX60sec) |
|---|
| 29 |
#------------------------------- |
|---|
| 30 |
|
|---|
| 31 |
require 'foltialib.pl'; |
|---|
| 32 |
|
|---|
| 33 |
# &writelog("digitalradiorecording.pl: DEBUG $ARGV[0] $ARGV[1] "); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
#準備 |
|---|
| 37 |
&prepare; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
&calldigitalrecorder; |
|---|
| 41 |
|
|---|
| 42 |
# &writelog("digitaldigitalradiorecording:RECEND:$bandtype $recch $lengthsec $stationid $sleeptype $filename $tid $countno $unittype"); |
|---|
| 43 |
|
|---|
| 44 |
# -- これ以下サブルーチン ---------------------------- |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
sub prepare{ |
|---|
| 48 |
|
|---|
| 49 |
#引数エラー処理 |
|---|
| 50 |
$stationname = $ARGV[0] ; |
|---|
| 51 |
$lengthsec = $ARGV[1] ; |
|---|
| 52 |
$filename = $ARGV[2] ; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
if (($stationname eq "" ) || ($lengthsec eq "") || ($filename eq "")){ |
|---|
| 56 |
print "usage digitalradiorecording.pl stationname length(sec) filename\n"; |
|---|
| 57 |
exit; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
#my $intval = $recch % 10; # 0〜9 sec |
|---|
| 61 |
my $intval = 0; |
|---|
| 62 |
my $startupsleep = $startupsleeptime - $intval; # 18〜27 sec |
|---|
| 63 |
$reclengthsec = $lengthsec + (60 - $startupsleep) + 10; # |
|---|
| 64 |
|
|---|
| 65 |
if ( $sleeptype ne "N"){ |
|---|
| 66 |
&writelog("digitalradiorecording: DEBUG SLEEP $startupsleeptime:$intval:$startupsleep:$reclengthsec"); |
|---|
| 67 |
sleep ( $startupsleep); |
|---|
| 68 |
#2008/08/12_06:39:00 digitalradiorecording: DEBUG SLEEP 17:23:-6:367 |
|---|
| 69 |
}else{ |
|---|
| 70 |
&writelog("digitalradiorecording: DEBUG RAPID START"); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
$outputpath = "$recfolderpath"."/"; |
|---|
| 74 |
|
|---|
| 75 |
if ($countno eq "0"){ |
|---|
| 76 |
$outputfile = $outputpath.$tid."--"; |
|---|
| 77 |
}else{ |
|---|
| 78 |
$outputfile = $outputpath.$tid."-".$countno."-"; |
|---|
| 79 |
} |
|---|
| 80 |
#2番目以降のクリップでファイル名指定があったら |
|---|
| 81 |
if ($filename ne ""){ |
|---|
| 82 |
|
|---|
| 83 |
$outputfile = $filename ; |
|---|
| 84 |
$outputfile = &filenameinjectioncheck($outputfile); |
|---|
| 85 |
$outputfilewithoutpath = $outputfile ; |
|---|
| 86 |
$outputfile = $outputpath.$outputfile ; |
|---|
| 87 |
&writelog("digitalradiorecording: DEBUG FILENAME ne null \$outputfile $outputfile "); |
|---|
| 88 |
}else{ |
|---|
| 89 |
$outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60)); |
|---|
| 90 |
chomp($outputfile); |
|---|
| 91 |
$outputfile .= ".aac"; |
|---|
| 92 |
$outputfilewithoutpath = $outputfile ; |
|---|
| 93 |
&writelog("digitalradiorecording: DEBUG FILENAME is null \$outputfile $outputfile "); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
@wday_name = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); |
|---|
| 98 |
$sleepcounter = 0; |
|---|
| 99 |
$cmd=""; |
|---|
| 100 |
|
|---|
| 101 |
#二重録りなど既に同名ファイルがあったら中断 |
|---|
| 102 |
if ( -e "$outputfile" ){ |
|---|
| 103 |
if ( -s "$outputfile" ){ |
|---|
| 104 |
&writelog("digitalradiorecording :ABORT :recfile $outputfile exist."); |
|---|
| 105 |
exit 1; |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
}#end prepare |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
sub calldigitalrecorder{ |
|---|
| 114 |
|
|---|
| 115 |
#if (-e "$toolpath/perl/tool/ffmpeg"){ |
|---|
| 116 |
#2010/4/7 radikoに対策されたのでffmpeg直接受信できなくなった |
|---|
| 117 |
#./ffmpeg -i rtmp://radiko.smartstream.ne.jp:1935/QRR/_defInst_/simul-stream -t 180 -acodec copy ~/php/tv/qrr.aac |
|---|
| 118 |
#&writelog("digitalradiorecording :DEBUG :$toolpath/perl/tool/ffmpeg -y -i rtmp://radiko.smartstream.ne.jp:1935/$stationname/_defInst_/simul-stream -t $reclengthsec -acodec copy $outputfile."); |
|---|
| 119 |
#system("$toolpath/perl/tool/ffmpeg -y -i rtmp://radiko.smartstream.ne.jp:1935/$stationname/_defInst_/simul-stream -t $reclengthsec -acodec copy $outputfile"); |
|---|
| 120 |
|
|---|
| 121 |
if (-e "$toolpath/perl/tool/rtmpdump"){ |
|---|
| 122 |
#./rtmpdump -y "simul-stream" -n "radiko.smartstream.ne.jp" -c 1935 -p "http://radiko.jp/player/player.html#QRR" -a "QRR/_defInst_" -f "WIN 10,0,45,2" -v -B 180 -o joqr.flv |
|---|
| 123 |
|
|---|
| 124 |
&writelog("digitalradiorecording :DEBUG :$toolpath/perl/tool/rtmpdump -r \"rtmpe://radiko.smartstream.ne.jp:1935/$stationname/_defInst_/simul-stream\" -s \"http://radiko.jp/player/player.html#${stationname}\" -f \"WIN 10,0,45,2\" -v -B $reclengthsec -o ${outputfile}.flv"); |
|---|
| 125 |
|
|---|
| 126 |
#system("$toolpath/perl/tool/rtmpdump -y \"simul-stream\" -n \"radiko.smartstream.ne.jp\" -c 1935 -p \"http://radiko.jp/player/player.html#${stationname}\" -a \"$stationname/_defInst_\" -f \"WIN 10,0,45,2\" -v -B $reclengthsec -o ${outputfile}.flv"); |
|---|
| 127 |
system("$toolpath/perl/tool/rtmpdump -r \"rtmpe://radiko.smartstream.ne.jp:1935/$stationname/_defInst_/simul-stream\" -s \"http://radiko.jp/player/player.html#${stationname}\" -f \"WIN 10,0,45,2\" -v -B $reclengthsec -o ${outputfile}.flv"); |
|---|
| 128 |
|
|---|
| 129 |
&writelog("digitalradiorecording :DEBUG :ffmpeg -y -i ${outputfile}.flv -vn -acodec copy $outputfile"); |
|---|
| 130 |
|
|---|
| 131 |
system("ffmpeg -y -i ${outputfile}.flv -vn -acodec copy $outputfile"); |
|---|
| 132 |
|
|---|
| 133 |
unlink("${outputfile}.flv"); |
|---|
| 134 |
}else{ |
|---|
| 135 |
&writelog("digitalradiorecording :ABORT :File not found,recordable ffmpeg on $toolpath/perl/tool/ffmpeg. Show http://d.hatena.ne.jp/nazodane/20100315/1268646192 "); |
|---|
| 136 |
exit 1; |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
}# end sub calldigitalrecorder |
|---|
| 142 |
|
|---|
| 143 |
|
|---|