PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Power106.php

https://github.com/tejastank/Scripts
PHP | 82 lines | 74 code | 8 blank | 0 comment | 5 complexity | 3b633ef054fa089c2be2256179fc6ecf MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. function runAsyncBatch($command, $filename)
  3. {
  4. $BatchFile = fopen("Power106.bat", 'w');
  5. fwrite($BatchFile, "@Echo off\r\n");
  6. fwrite($BatchFile, "Title $filename\r\n");
  7. fwrite($BatchFile, "$command\r\n");
  8. fwrite($BatchFile, "Pause\r\n");
  9. fclose($BatchFile);
  10. $WshShell = new COM("WScript.Shell");
  11. $oExec = $WshShell->Run("Power106.bat", 1, false);
  12. unset($WshShell, $oExec);
  13. }
  14. function SafeFileName($filename)
  15. {
  16. $len = strlen($filename);
  17. for ($i = 0; $i < $len; $i++)
  18. {
  19. $char = ord($filename[$i]);
  20. if (($char < 32) || ($char >= 127))
  21. $filename = substr_replace($filename, ' ', $i, 1);
  22. }
  23. $filename = preg_replace('/[\/\\\?\*\:\|\<\>]/i', ' - ', $filename);
  24. $filename = preg_replace('/\s\s+/i', ' ', $filename);
  25. $filename = trim($filename);
  26. return $filename;
  27. }
  28. function ShowHeader($header)
  29. {
  30. $len = strlen($header);
  31. $width = (int) ((80 - $len) / 2) + $len;
  32. $format = "\n%" . $width . "s\n\n";
  33. printf($format, $header);
  34. }
  35. ShowHeader("KSV Power106 Downloader");
  36. $format = "%-8s : %s\n";
  37. if ($argc <= 2)
  38. {
  39. echo "Enter Channel ID : ";
  40. $channel_id = trim(fgets(STDIN));
  41. echo "Enter Asset ID : ";
  42. $asset_id = trim(fgets(STDIN));
  43. }
  44. else
  45. {
  46. $channel_id = $argv[1];
  47. $asset_id = $argv[2];
  48. }
  49. echo "Retrieving html . . .\n";
  50. $xml = file_get_contents("http://player.vidaroo.com/initiate/render/channel_id/$channel_id/asset_id/$asset_id/embed_id/2105/log_embed_id/128210038");
  51. $xml = simplexml_load_string($xml);
  52. $token = $xml->xpath('/rsp/msg/session/token');
  53. $token = (string) $token[0];
  54. printf($format, "Token", $token);
  55. $xml = file_get_contents("http://player.vidaroo.com/render/asset/channel_id/$channel_id/asset_id/$asset_id/token/$token");
  56. $xml = simplexml_load_string($xml);
  57. $title = $xml->xpath('/rsp/msg/slot/video/asset/title');
  58. $title = (string) $title[0];
  59. $filename = SafeFileName($title);
  60. $url = $xml->xpath('/rsp/msg/slot/video/asset/@url');
  61. $url = base64_decode((string) $url[0]);
  62. $host = substr($url, 0, strpos($url, '/', 8));
  63. $app = substr($url, strlen($host) + 1, strrpos($url, '/') - strlen($host));
  64. $playpath = substr(strrchr($url, '/'), 1);
  65. $command = 'rtmpdump -r "' . "$host/$app" . '" -a "' . $app . '" -f "WIN 11,1,102,63" -W "http://assets.vidaroo.com/platform/1331760804/player/shell.swf" -p "http://www.power106.com/powertv/index.aspx" -C B:1 -y "mp4:' . $playpath . '" -o "' . $filename . '.flv"';
  66. printf($format, "Title", $title);
  67. printf($format, "Host", $host);
  68. printf($format, "App", $app);
  69. printf($format, "Playpath", $playpath);
  70. printf($format, "Command", $command);
  71. if ($playpath)
  72. runAsyncBatch($command, $filename);
  73. echo "Finished\n";
  74. ?>