Indicate the path obtained with DOM to a player in php

235 views Asked by At

Exists: http://server1.com/player.php Inside server 1 there is a player with Clappr that looks like this:

<script type='text/javascript'>

        var player = new Clappr.Player({
        source: window.atob("bXlzdHJlYW0ubTN1OA=="),
        plugins: [],
        parentId: '#player',
        width: '100%',
        height: '100%',
        //hlsMinimumDvrSize: 0,
        chromecast: {
          appId: '9DFB77C0',
          media: {
            type: ChromecastPlugin.None,
            title: 'Tittle',
            subtitle: 'Sub'
        }}
        //playback: {
          //  hlsjsConfig: {
            //    liveSyncDurationCount: 2
            //}
        //}
    });

I used the following code in a file called test.php inside http://server2.com

  • (Check the PHP Code at the end).

And I got:

var player = new Clappr.Player({ source: window.atob("bXlzdHJlYW0ubTN1OA=="), plugins: []
  1. How can I "decode" the route? ("bXlzdHJlYW0ubTN1OA==" to "mystream.m3u8")
  2. Once the path is decoded, how can i leave it "alone" to use in a new player?

[https://stackoverflow.com/a/44234560/12765259][1]


$url = 'http://server1.com/player.php';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10');
$html = curl_exec($curl);
curl_close($curl);
$dom = new DOMDocument();
@$dom->loadHTML($html);  //convert character asing
$xpath = new DOMXPath($dom);    
$script = $xpath->query ('//script[contains(text(),"window.atob(")]')->item (0)->nodeValue;

$json = end(explode( 'sources:', $script));
$json = explode ( ']', $json)[0].']';

echo $json 

?>```


  [1]: https://stackoverflow.com/a/44234560/12765259
1

There are 1 answers

0
verjas On

To achieve this, you should look up these PHP functions: base64_decode and preg_match

Then do something like this:

// get $html with CURL...
// for example
$html = '<script>...window.atob("bXlzdHJlYW0ubTN1OA==")...';

// capture window.atob("....") inside a variable: $html_snip
preg_match('/(window\.atob\(\".*\"\))/', $html, $html_snip);

// transform it to array [0][window.atob(] [1][....] [2][)]
$html_snip = explode('"', $html_snip[0]);

// get the encoded part [1][...]
$encoded_link = $html_snip[1];

// decode it from base64 to "mystream.m3u8"
$real_link = base64_decode($encoded_link);

// Now you can use $real_link where you want

// A. save it in a file...
$save_path = "links.txt";
file_put_contents($save_path, $real_link);

// B. echo it inside a <script>
<script>
    // javacript here....
    var real_link = "<?php echo $real_link; ?>";
</script>