I want to extract m3u8 and wmsAuthSign by regex

问题内容:

I could extract m3u8 and wmsAuthSign of below link by regex before but now my code doesn’t work! what’s the problem ?!

Link : https://www.liveonlinetv247.info/embed/btsport2.php

This is my regex code :

$streamSite = "https://www.liveonlinetv247.info/embed/btsport2.php";

function writeFile($url, $channel) {
        $File = $channel.".strm";
        $Handle = fopen($File, 'w');
        fwrite($Handle, $url);
        fclose($Handle);
}

  $input = @file_get_contents($streamSite) or die("Please try again later: $url");

  preg_match("/(http.*?wmsAuthSign\=[^\&\">]+)/", $input, $matches);
echo $matches[1];

问题评论:

答案:

答案1:

Your regex gets the full url. In this case, you could load your $matches[1]into parse_url to get your data.

For example:

$streamSite = "https://www.liveonlinetv247.info/embed/btsport2.php";

function writeFile($url, $channel) {
    $File = $channel.".strm";
    $Handle = fopen($File, 'w');
    fwrite($Handle, $url);
    fclose($Handle);
}

$input = @file_get_contents($streamSite) or die("Please try again later: $url");
preg_match("/(http.*?wmsAuthSign\=[^\&\">]+)/", $input, $matches);

$wmsAuthSignKv = parse_url($matches[1], PHP_URL_QUERY);
$wmsAuthSign = explode('=', $wmsAuthSignKv);
echo $wmsAuthSign[1] . "<br>";

$m3u8 = parse_url($matches[1], PHP_URL_PATH);
echo basename($m3u8) . "<br>";

That would give you:

c2VydmVyX3RpbWU9MTIvMTEvMjAxNyAyOjAxOjE4IFBNJmhhc2hfdmFsdWU9aWlHVHYwbGVNaWJjSEFZVy82WndZZz09JnZhbGlkbWludXRlcz02MCZpZD0xNDEuMTAxLjEwNC4xMTMmc3RybV9sZW49MTY

playlist.m3u8

答案评论:

    
Unfortunately it doesn’t work at all!
– Michael
1 hour ago
    
@Michael I’ve updated my answer with the full code based on your code. What does not work? Do you get an error running the full code?
    
I put it in my web page your code but it doesn’t work yet , I receive just error : ” Please try again later: “
– Michael
1 hour ago
    
Its really strange that why it doesn’t work on my web page!
– Michael
1 hour ago
    
Do you run it on your local on from a webserver? Are you sure file_get_contents is allowed to perform that action? Try running it without the @ sign like file_get_contents and see if there is an error. You may check this post.

答案2:

This code output the following:

https://edge1.liveonlinetv247.org/live/btsport2-hq/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MTIvMTEvMjAxNyAxMTo0ODo0NSBBTSZoYXNoX3ZhbHVlPXRNSkJvMFlpKzFQN1preStzcS9VaUE9PSZ2YWxpZG1pbnV0ZXM9NjAmaWQ9MTYyLjE1OC4xMC4yMiZzdHJtX2xlbj0xNg==

Do you want to get “wmsAuthSign” data? then you need to use substr() and strpos() functions.

答案评论:

    
Yes output will be : https://edge1.liveonlinetv247.org/live/btsport2-hq/playlist.‌​m3u8?wmsAuthSign=c2V‌​ydmVyX3RpbWU9MTIvMTE‌​vMjAxNyAxMTo0ODo0NSB‌​BTSZoYXNoX3ZhbHVlPXR‌​NSkJvMFlpKzFQN1preSt‌​zcS9VaUE9PSZ2YWxpZG1‌​pbnV0ZXM9NjAmaWQ9MTY‌​yLjE1OC4xMC4yMiZzdHJ‌​tX2xlbj0xNg==
– Michael
4 hours ago
    
but I can’t extract it with my code! which part of my code should change?!
– Michael
4 hours ago
    
I want to get m3u8 and wmsAuthSign together from above link.
– Michael
4 hours ago

原文地址:

https://stackoverflow.com/questions/47752016/i-want-to-extract-m3u8-and-wmsauthsign-by-regex

Tags:, ,

添加评论

友情链接:蝴蝶教程