Receive data from a url (m3u)

Asked

Viewed 71 times

-2

I have the following doubt:

I have this URL:

http://servidor.com8000/get.php?username=NOME&password=SENHA&type=m3u_plus

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

I wanted to extract the information and save in a txt file

Imagem, Nome, URL, Categoria = 0, Legenda = 0, Qualidade = 0, Infor = 0, Infor2 = 0

1st Observation: I know that in link with m3u servers do not have what are inside "= 0", That would just be to add even you know.

2nd Observation: The information comes like this:

#EXTINF:-1 tvg-id="" tvg-name="Bruce Lee - A Fúria do Dragão (1972)" tvg-logo="https://i2.wp.com/asiamundi.com.br/wp-content/uploads/2015/02/A-F%C3%BAria-do-Drag%C3%A3o-1972.jpg?fit=674%2C1000&ssl=1" group-title="Ação & Aventura",Bruce Lee - A Fúria do Dragão (1972)
http://xsrv.me:8080/movie/claudio/claudio/64869.mp4

1 answer

-1

Dividing the problem into three steps, it can be said that Voce needs to use only the following PHP functions:

Step 1: Getting the . m3u using file_get_contents
Step 2: Capturing content using preg_match
Step 3: Saving the information in . txt using file_put_contents

The code below exemplifies how they can be used:

<?php
// $conteudo = file_get_contents("http://servidor.com:8000/get.php?username=NOME&password=SENHA&type=m3u_plus");
$conteudo = '#EXTINF:-1 tvg-id="" tvg-name="Bruce Lee - A Fúria do Dragão (1972)" tvg-logo="https://i2.wp.com/asiamundi.com.br/wp-content/uploads/2015/02/A-F%C3%BAria-do-Drag%C3%A3o-1972.jpg?fit=674%2C1000&ssl=1" group-title="Ação & Aventura",Bruce Lee - A Fúria do Dragão (1972) http://xsrv.me:8080/movie/claudio/claudio/64869.mp4';

preg_match('/tvg-name="(.*?)"/', $conteudo, $resultadosDoNome);
preg_match('/tvg-logo="(.*?)"/', $conteudo, $resultadosDaImagem);
preg_match('/\s(http:|https:)+[^\s]+[\w]/', $conteudo, $resultadosDaUrl);

$nomeDoArquivo = 'informacoes.txt';

$conteudoDoArquivo = "Imagem = " . $resultadosDaImagem[1] . PHP_EOL
 . "Nome = " . $resultadosDoNome[1] . PHP_EOL
 . "URL = " . trim($resultadosDaUrl[0]) . PHP_EOL
 . "Categoria = 0" . PHP_EOL
 . "Legenda = 0" . PHP_EOL
 . "Qualidade = 0" . PHP_EOL
 . "Infor = 0" . PHP_EOL
 . "Infor2 = 0";
 
file_put_contents($nomeDoArquivo, $conteudoDoArquivo);

This code would generate a file called "informacoes.txt" with the following content:

Imagem = https://i2.wp.com/asiamundi.com.br/wp-content/uploads/2015/02/A-F%C3%BAria-do-Drag%C3%A3o-1972.jpg?fit=674%2C1000&ssl=1
Nome = Bruce Lee - A Fúria do Dragão (1972)
URL = http://xsrv.me:8080/movie/claudio/claudio/64869.mp4
Categoria = 0
Legenda = 0
Qualidade = 0
Infor = 0
Infor2 = 0

And to check if the regular expressions are correctly capturing the text you want, Voce can use the Regexr.

  • I did it here and it worked super well, but it only returned me a value. How and what I do for it return me various values. ?

  • Do you want to write information from different movies in the same file? If yes, just have the list of all URL’s. m3u and go, item by item, doing these steps above, using https://www.php.net/manual/en/function.file-get-contents.php instead of using a static string. Here’s the documentation on how to browse a list using For: https://www.php.net/manual/en/control-structures.for.php

Browser other questions tagged

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