PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/EugeniaVoda.php

https://github.com/tejastank/Scripts
PHP | 43 lines | 39 code | 4 blank | 0 comment | 3 complexity | 5d2438e5f5e25360c685a4848c04dd5a MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. function ShowHeader($header)
  3. {
  4. $len = strlen($header);
  5. $width = (int) ((80 - $len) / 2) + $len;
  6. $format = "\n%" . $width . "s\n\n";
  7. printf($format, $header);
  8. }
  9. ShowHeader("KSV EugeniaVoda Downloader");
  10. $format = "%-8s : ";
  11. if ($argc <= 2)
  12. {
  13. printf($format, "URL");
  14. $url = trim(fgets(STDIN));
  15. printf($format, "Filename");
  16. $filename = trim(fgets(STDIN));
  17. }
  18. else
  19. {
  20. $url = $argv[1];
  21. $filename = $argv[2];
  22. }
  23. echo "Retrieving data . . .\n";
  24. $json = file_get_contents($url . "/offsets.json");
  25. $chunks = json_decode($json);
  26. if (!$chunks)
  27. die("Failed to decode json");
  28. $fh = fopen($filename, 'wb');
  29. fwrite($fh, pack("H*", "464C5601050000000900000000"));
  30. $total_chunks = count($chunks);
  31. for ($i = 0; $i < $total_chunks; $i++)
  32. {
  33. echo "Downloading " . ($i + 1) . "/$total_chunks chunks\r";
  34. $data = file_get_contents($url . "/$chunks[$i].flvtags");
  35. fwrite($fh, $data);
  36. }
  37. fclose($fh);
  38. echo "\nFinished\n";
  39. ?>