Receive data from a url (m3u) using php

Asked

Viewed 6,673 times

2

I have the following doubt:

I have this URL: http://Infinity.quor8.com:8000/get.php?username=wesleybr&password=mxViBCIK05&type=m3u_plus&output=ts

When accessing it by the browser is made to download a file . m3u so far so good :)

I need to put this url in an input field and when pressing the button click below some data that is inside this file, for example:

tvg-logo tvg-name and all urls with end . ts

I’d like to show you this in a sort of a list:

Nome Logo Url

I don’t know where to start, I’ve actually tried many things that are not worth putting here :/ if someone can give a light :)

  • I think it’s never a good idea to pass Users and Passwords by GET....

  • @Matheuscuba the biggest problem is passing http instead of https. Without https, both POST and GET pass the open passwords. The POST only seems a little more discreet, but the difference is not as much as the people think. GET only gets a little worse because of the history, but only swap for POST is not real solution.

  • Right, but in this case I just need to list in table form the data I put up there, I will not pass the user data but upload the data I need that are in the file of that url

  • @Bacco I fully agree with you, but still requests POST despite being as exposed as requisitions GET, are still little, more secure. It is not all Users who possess the knowledge necessary to intercept their data. It is extremely necessary to use SSL certificate for security, but leave a login request with GET? Any Corner User can copy the URL and exit using

  • I know, Metheus, but I don’t think you understand the point. It does not matter if you will have login and Sneha in the url, what need is to get the data from the file that this url low.

2 answers

2


The easiest way is by using the function preg_match_all with Regex.

Capturing the list through Curl

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://Infinity.quor8.com:8000/get.php?username=USERNAME&password=PASSWORD&type=m3u_plus&output=ts");
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);
curl_close($ch);

echo $response;

Using this code, you will be able to capture all the contents of the file and store in the variable $response.

It is important that you use options such as CURLOPT_COOKIEJAR, CURLOPT_COOKIEFILE, CURLOPT_USERAGENT etc. Some servers block access when there are no certain headers.

Filtering the contents of the file

As I mentioned at the beginning, to filter you will need to use regex.

<?php

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

$data = reset($result);

(?:tvg-name)="(?<name>.*?)" - Here it will capture all the content involved by the " (quotes) that comes after tvg-name=

.+(?:tvg-logo)="(?<logo>.*?)" - The .+ is for him to go through all the content until tvg-logo=" and capture the content from between the " (quotes)

.+\n(?P<link>https?:\/\/.+) - Here the .+ is the same thing as the previous step, the difference is in the \n which means going through, including, a line break and capturing the entire line that starts with http or https

The ?: at the beginning of relatives tells not to capture that term. In this expression it is optional.

Finally, (?<name>.*?) informs to capture all the value and turn into a group with the name name

This will return you one array with the data of name, soon and link. Now you can make one foreach and display the data in a table.

Complete code

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://Infinity.quor8.com:8000/get.php?username=USERNAME&password=PASSWORD&type=m3u_plus&output=ts");
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>
            <th>Link</th>
        </tr>
    </thead>

    <tbody>
        <?php foreach($channels as $channel): ?>
        <tr>
            <td><img src="<?php echo $channel["logo"] ?>" height="75" width="75" /></td>
            <td><?php echo $channel["name"] ?></td>
            <td><?php echo str_replace(".ts", ".m3u8", $channel["link"]) ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>

You can also customize with css:

<style>
    .channel {
        float:left;
    }
</style>

<div id="channels">
<?php foreach($channels as $channel): ?>
    <div class="channel">
        <a href="<?php echo str_replace(".ts", ".m3u8", $channel["link"]) ?>" title="<?php echo $channel["name"] ?>">
            <img src="<?php echo $channel["logo"] ?>" height="75" width="75" alt="<?php echo $channel["name"] ?>" />
        </a>
    </div>
<?php endforeach; ?>
</div>

If you want to replace a value while adding the data in the table, just use preg_replace or str_replace.

  • Caraaa Thank you so much, you just solved my problem, that was fantastic :)

  • Friend, after you edit stopped working what happened ?

  • @Andréluizmardonis just removed the user and password from the URL

  • Sorry kkk I just saw this, buddy see if you can help me out on one more thing, realize the links are. ts has some way of checking this and when it is . ts replace for . m3u8 ?

  • @Andréluizmardonis, I edited my answer with this option.

  • Thank you very much friend, now I can continue :)

  • how I could make a table structure this way here: http://prntscr.com/i1r4n3 with the logo the name below and finally the link ?

  • @Andréluizmardonis, I edited my answer. As I work a lot with front-end, I did something very basic, just to get a sense.

  • Thank you @Valdeir, to finish with your help(I promise kk) as I would to click on the logo to open an iframe above the channels by passing to this iframe the link of the channel clicked and receiving in the iframe file that is the player.php, so that I can play this channel ? inside the.php player I have a <script> where I should receive the channel link in source:

  • As it is a question different from the post, I decided to post in a separate place. https://pastebin.com/TxS2vYaL Then link to the website to watch =D

  • I’ll put my question here because it might help a colleague. Redirected links are not working ai vc said to use curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); but even using this line the problem remains :/

  • @Valdir Psr -- man, I have a problem opening the channel popup, just stopped working from yesterday to today, can help ?

Show 8 more comments

-1

Face only vc generate with the m3u8 same, copies every channel list plays in the notepad click on find and replace the . m3u8 by . ts

Browser other questions tagged

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