nisargshh / dlive-video-embed

DLive LiveStream Embed for Multi Rare Drop
0 stars 3 forks source link

usage question #1

Open hammerheaddown opened 3 years ago

hammerheaddown commented 3 years ago

i just stumbled across this embed and was wondering if you can help out with some info on how to use this?

i have changed up a few parts of the code but even with the m3u8 it wont play on video.js or any other player i have found

<?php
    error_reporting(E_ERROR | E_PARSE);

    $displayname = 'VinylRecords';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,"https://cors-anywhere.herokuapp.com/https://graphigo.prd.dlive.tv/");
        curl_setopt($ch, CURLOPT_POST, 1);
        $headers = [
            'Content-Type: application/json',
            'origin: https://dlive.tv',
            'Access-Control-Request-Method: GET',
        ];
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // Do not send to screen
        $obj1->operationName = "LivestreamPageRefetch";
        $obj1->variables->displayname = $displayname;
        $obj1->variables->add = false;
        $obj1->variables->isLoggedIn = false;
        $obj1->extensions->persistedQuery->version = 1;
        $obj1->extensions->persistedQuery->sha256Hash = "5fb08d9011ad28aa96b193636a70252a85ec044f7a6c715e3d59c19ebab56e24";

        $post_data = json_encode($obj1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $apiResponse = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            echo " the error is:" . $error_msg."<br><br>";
            }

        curl_close($ch);
        $jsonArrayResponse = json_decode($apiResponse);
        $username = $jsonArrayResponse->data->userByDisplayName->username;      

        //All video urls
        $ch1 = curl_init();
        curl_setopt($ch1, CURLOPT_URL,"https://live.prd.dlive.tv/hls/live/" . $username . ".m3u8");
        curl_setopt($ch1,CURLOPT_RETURNTRANSFER,1);
        $apiResponse = curl_exec($ch1);
        curl_close($ch1);

        preg_match_all('/(?P<tag>#EXTINF:-1)|(?:(?P<prop_key>[-a-z]+)=\"(?P<prop_val>[^"]+)")|(?<something>,[^\r\n]+)|(?<url>http[^\s]+)/', $apiResponse, $match );

        $count = count( $match[0] );

        $result = [];
        $index = -1;

        for( $i =0; $i < $count; $i++ ){
            $item = $match[0][$i];

            if( !empty($match['tag'][$i])){
                //is a tag increment the result index
                ++$index;
            }elseif( !empty($match['prop_key'][$i])){
                //is a prop - split item
                $result[$index][$match['prop_key'][$i]] = $match['prop_val'][$i];
            }elseif( !empty($match['something'][$i])){
                //is a prop - split item
                $result[$index]['something'] = $item;
            }elseif( !empty($match['url'][$i])){
                $result[$index]['url'] = $item ;
            }
        }

        // $video_url= $result[$index]['url'];
?>

do you still have this working in some way? seems it is being caused from a cors

if you look above i changed the header with the curl request it was missing 'Access-Control-Request-Method: GET',

nisargshh commented 3 years ago

I was stumbling upon this same problem about a month ago. They have the m3u8 file itself locked behind the CORS. This basically means that you can't access the video live stream. You can try to run that same video file with a VLC media player and find that it works since VLC doesn't care about CORS. So there might be some workaround with using VLC but I haven't gone to in-depth with it yet.