davidzentner Posted June 23, 2017 Share Posted June 23, 2017 Hi All, I am new to this and need some basic help and would appreciate any assistance I have a m3u file I would like to share with some friends for online streaming that contains 'username' and 'password' in the links I need to make it so the URL to download the file will auto replace the strings "username" and "password" with the desired user and pass I have seen this done before using get.php?username=xxx&password=xxx in the URL. The filename in this case is channels.m3u Thanks in advanced! Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 23, 2017 Share Posted June 23, 2017 I don't understand what you are trying to accomplish. If you are going to replace the username and password in the URL with the correct values - then why are you using a username and password at all? Perhaps you need to provide some more specifics. Are you trying to generate the links on a page with the correct values embedded? Are you getting the links from some external source and want to inject the username/password into those links? Quote Link to comment Share on other sites More sharing options...
davidzentner Posted June 23, 2017 Author Share Posted June 23, 2017 Hi, Thanks for the reply The channels.m3u file is a custom list of paid IPTV channels I have created for Kodi with a several different streams embedded in the file A few of my friends who also have the same paid IPTV wish to be able to use my channels.m3u list, as it ties in with a custom guide I have made. Problem is, if I host my channels file, it will contain my password and username, rather than their own details. So, I figure the easier solution would be to host the file with "username" and "password" listed in the links and then have it so if they download the file, it will automatically populate with the username and password they desire (essentially replace all instances of the string "username" and "password" in the file when the go to the URL for download Would be great if they could have the username and password they wish to use in the url, so it populates prior to downloading the file I hope this helps explain it better Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 23, 2017 Share Posted June 23, 2017 It helps a little, but still fuzzy on a couple of points. So you have a playlist file that you want to share with others. The links in the file contain your username and password, correct? That seems odd, I would think you could log in to the site and then run your playlist without the credentials in the links using sessions. So, what you are really after is a way to allow the user to enter their username and password into a form and then download the playlist with those values replaced into the file. Is that correct? Quote Link to comment Share on other sites More sharing options...
davidzentner Posted June 23, 2017 Author Share Posted June 23, 2017 So, what you are really after is a way to allow the user to enter their username and password into a form and then download the playlist with those values replaced into the file. Is that correct? <--- spot on ideally, rather than having a form to input there username and password, would be better if they could enter there values into the actual URL (as this way the URL can be entered in kodi client). Rather than having to manually enter the details to download, but otherwise spot on from some quick google research, not sure if I am on the right track, but looks like I need to use PHP to refer to the file channels.m3u and then use str_replace to replace the string "username" and "password" with the values they have input The providers I download the original raw data from user get.php?username=xxx&passsword=xxx in the download URL, keeping this kind of format would be ideal Thanks again Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 23, 2017 Share Posted June 23, 2017 ideally, rather than having a form to input there username and password, would be better if they could enter there values into the actual URL (as this way the URL can be entered in kodi client). Rather than having to manually enter the details to download, but otherwise spot on . . . The providers I download the original raw data from user get.php?username=xxx&passsword=xxx in the download URL, keeping this kind of format would be ideal So, now you are getting more confusing. So, you want each user to enter a URL into their client with their username & password in the parameters. Then the client provides them that link in some way and when they click it, it will download the playlist from your server? This all sounds like a very bad idea, but I needed a time killer. I give absolutely no warranties on this code. You are going to be dealing with credentials in plaintext that could easily end up getting compromised. <?php //Path and name of playlist file $playlist_file = "test_cases/test.m3u"; //Values in file to be replaced $username_rep = "[USERNAME]"; $password_rep = "[PASSWORD]"; //Check if user passed credentials if(isset($_GET['username']) && isset($_GET['username'])) { //Get name of the file $playlist_name = basename($playlist_file); //Get username & password from POST data $username_val = trim($_GET['username']); $password_val = trim($_GET['password']); //Get contents of the playlist $playlist = file_get_contents($playlist_file); //Replace the placeholder values with submitted values $playlist = str_replace([$username_rep, $password_rep], [$username_val, $password_val], $playlist); //Output the results to user as a download header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Disposition: attachment; filename=\"{$playlist_name}\""); echo $playlist; } else { echo "No username and/or password provided"; } ?> Quote Link to comment Share on other sites More sharing options...
davidzentner Posted June 23, 2017 Author Share Posted June 23, 2017 I think we are heading in the right direction. I am not to concerned about security, as its just for a few friends and relatives to use, so I doubt they will try and do anything harmful I will be hosting the m3u file, it looks a little like this, as below. Each user has already been provided with their own unique username and password. I am simply trying to make it, so if they have the correct URL in the Kodi simple client it will refer to the M3U file and populate their username and password into the steams as it downloads the m3u file, hence they will be able to now stream the channel in Kodi. At the moment I have had to manually change the file to reflect the correct username & password, but this can be a pain, as if I have 5 or 6 mates using the streams, I have to manually edit and share the file for each individually. The idea here is I will only need to keep one m3u file up to date with the latest streams and there client will automatically download the updates when it loads. (Sorry if I am not explaining in an easy enough way to understand) - Appreciate all the input so far ! I am hoping they will then be able to access the information by having kodi simple client set up with the URL in the format of "host.com/get.php?username=xxxx&password=xxx" or something similar EXTM3U #EXTINF:-1 group-title="USA", Channel 1 http://linktoshare/live/password/username/stream1.ts #EXTINF:-1 group-title="USA", Channel 2 http://linktoshare/live/password/username/stream2.ts Quote Link to comment Share on other sites More sharing options...
davidzentner Posted June 23, 2017 Author Share Posted June 23, 2017 EXTM3U #EXTINF:-1 group-title="USA", Channel 1 http://linktoshare/live/username/password/stream1.ts #EXTINF:-1 group-title="USA", Channel 2 http://linktoshare/llive/username/password/stream2.ts is the m3u layout sorry Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 23, 2017 Share Posted June 23, 2017 The idea of messing with the file content through blind search-and-replace is very hacky. I wouldn't even recommend that for a hobby application. M3U is a proper file format, so it should be treated as such. When you upload your original file, parse it with an M3U library and optionally cache the data in database, so that you don't have to process the same file over and over again. When one of your friends requests your playlist, you generate it dynamically from the data you've previously extracted, adding their credentials to the URLs. There are several M3U libraries for PHP (like this one). Parsing is very simple: <?php # composer autoloader require_once __DIR__.'/vendor/autoload.php'; $m3uParser = new \M3uParser\M3uParser(); $channels = $m3uParser->parseFile('/path/to/your.m3u'); foreach ($channels as $channel) { $channelInfo = $channel->getExtTags()[0]; echo 'Title: <br>'; var_dump($channelInfo->getTitle()); echo 'Group title: <br>'; var_dump($channelInfo->getAttribute('group-title')); echo 'URL: <br>'; var_dump($channel->getPath()); } Generating a new playlist: <?php # composer autoloader require_once __DIR__.'/vendor/autoload.php'; $playlist = new \M3uParser\Data(); # test entry $channel = new \M3uParser\Entry(); $channel->setPath('http://url/of/channel/with/credentials'); $channelInfo = new \M3uParser\Tag\ExtInf(); $channelInfo ->setDuration(-1) ->setTitle('Title of Channel') ->setAttribute('group-title', 'USA') ; $channel->addExtTag($channelInfo); $playlist->append($channel); var_dump((string) $playlist); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.