docs
[mirrors/Programs.git] / php / streamrip
1 #!/usr/bin/php
2 <?php
3 //StreamRipper
4 //Harvie 2007
5 /*
6 This can rip many types of streams simply by downloading them to file.
7 (MP3,OGG,MPEG,AVI,WMA,WMV,etc..)
8 */
9
10 ///CODE///////////////////////////////////////////////////////////
11 ///Implicit values
12 $len = 1000; //Block size
13 //$out = "broadcast.mp3";
14
15 ///Args
16 if(!isset($argc)) die('This is php-cli script you idiot!');
17 if($argc < 2) die("Usage: streamrip stream_url [output file] [block_size]\n");
18 if($argc > 1) $in = $argv[1];
19 $out = explode('/', $in); $out = trim($out[sizeof($out)-1]);
20 if($argc > 2) $out = $argv[2];
21 if($argc > 3) $len = $argv[3];
22
23 $i=1;
24 while(is_file($out)) {
25 $sout = $i.'-'.$out;
26 if(!is_file($sout)) $out = $sout;
27 $i++;
28 }
29
30 //Banner
31 echo("Rippin' da stream $in...\nSaving to $out\nc-C to stop\n\n");
32
33 //Init
34 $total = @(filesize($in));
35 $in = fopen($in, 'rb');
36 $out = fopen($out, 'wb');
37 $b = 0;
38 $sp = 'N/A';
39 $perc = 'N/A';
40 $st = time();
41
42 while(!feof($in) && !feof($out)) {
43 //Info
44 $t = time()-$st;
45 $s=$t%60;
46 $m=floor($t/60);
47 $kb=floor($b/1000);
48 $mb=floor($b/1000000);
49 if($s!=0) $sp = round($kb/$s, 2);
50 if(is_int($total)) $perc = ceil($b/$total*100);
51 echo("$mb MB = $kb KB == $m:$s Mins == $perc% == $sp kB/s (avg.) \r");
52
53 //Download
54 $data = fgets($in,$len);
55 fputs($out,$data);
56 $b = $b+strlen($data);
57 }
58 echo("\n");
59
60 //Fclose all
61 fclose($in);
62 fclose($out);
This page took 0.306963 seconds and 4 git commands to generate.