I need to return the text of a m3u file in lists

Asked

Viewed 476 times

0

I have a file ". m3u" I need to return some data in list.

PHP example:

<?php 
    $m3u_file = file_get_contents('meuarquivo.m3u');
    preg_match_all('/(tvg-name="(?<name>.*?)".+\n(?P<link>https?:\/\/.+))/', 
    $m3u_file, $channels, PREG_SET_ORDER);
?>

<ul>
    <?php foreach($channels as $m3u_file): ?>
        <li id="title"><?php echo $m3u_file["name"] ?></li>
        <li id="URL"><?php echo str_replace(".ts", ".m3u8", $m3u_file["link"]) ?></li>
    <?php endforeach; ?>
</ul>

Upshot:

<ul>    
  <li id="title">A&E</li>
  <li id="URL">http://meucanal.tv:25461/9906</li>

  <li id="title">AMC</li>
  <li id="URL">http://meucanal.tv:25461/9904</li>

  <li id="title">AMC HD</li>
  <li id="URL">http://meucanal.tv:25461/9902</li>

  <li id="title">Animal Planet</li>
  <li id="URL">http://meucanal.tv:25461/9900</li>

  <li id="title">Arte 1</li>
  <li id="URL">http://meucanal.tv:25461/9893</li>

  <li id="title">AXN</li>
  <li id="URL">http://meucanal.tv:25461/9897</li>
</ul>

Using the PHP preg_match_all with this result, but I need to do the same thing using javascript. tried using the match() but I couldn’t get the same result.

I’m sorry for the mistakes, I’m new here kkk

  • I could not understand a pattern of what you want to take with the given example. I suggest editing the question and better detail what you want and what you have already done.

2 answers

0

In case someone who has the same doubt that I find this post, it solved my problem...

$(document).ready(function() {

    var myString = `#EXTM3U
            #EXTINF:-1 tvg-id="AeE" tvg-name="A&E" tvg-logo="https://minhalogo.com/img4597.jpg" group-title="Canais Séries",A&E
            http://mylista.com/6782/27khsf/aed
            #EXTINF:-1 tvg-id="AMC" tvg-name="AMC" tvg-logo="https://minhalogo.com/img5332.jpg" group-title="Filmes",AMC
            http://mylista.com/6782/27khsf/amc`;

    var pattern = /(tvg-name="(?<nome>.*?)".+\n(?<url>https?:\/\/.+))/g;
    var match;

    while (match = pattern.exec(myString)) {
        $('body').append(
            `<ul>    
                    <li id="title">` + match[2] + `</li>
                    <li id="URL">` + match[3] + `</li>
                </ul>`
        )
    }
});

-2

Try this code, it will return you exactly what you need, but I’m not able to format the button to play the video inside the div with the video.js, is causing me error.

If you know how to fix this little problem share with me.
Hug.

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://url-do-seu-arquivo.m3u");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

if (substr($info["http_code"], 0, 2) != 20) {
    die("Could not connect to server. Check username and password");
}

preg_match_all('/(tvg-name="(?<name>.*?)".+tvg-logo="(?<logo>.*?)".+\n(?P<link>https?:\/\/.+))/', $response, $channels, PREG_SET_ORDER);

?>
<table>
    <thead>
        <tr>
            <th>Logo</th>
            <th>Name</th>
            
        </tr>
    </thead>

    <tbody>
        <?php foreach($channels as $channel): ?>
        <tr>
            <body>
            <?php
            $link = $channel["link"];
            
           ?>
            
            <td><button type="button" class="w3-bar-item w3-button" data-toggle="modal" data-target="#myModal" id="<?php echo $link ?>" /><a  data-value = "<?php echo $link ?>" href="<?php echo $link ?>" target="player"/><img src="<?php echo $channel["logo"] ?>" height="30" width="30" /></button></td>
            <td><?php echo $channel["name"] ?></td>
              
       
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.