📜 ⬆️ ⬇️

Creating a program guide for IPTV channel based on the Flussonic media server

Let's start with a small prologue.

What are server playlists and why are they needed? (from offsite flussonic)
Server playlists today are not recommended for use on the Internet.

This technology is growing roots of television equipment and software, which allowed to run video under the control of the operator. In the updated form, playlists are needed today, since practice shows that it is more pleasant for users to watch what they are offered, and not to look for themselves.
')
Instead of server playlists today it is recommended to use client playlists due to the following problems:

the inability to target advertising;
the inability to consider advertising through adriver and other similar networks;
complexity to make multi-bit delivery: different files may have a different number of different bit rates;
it is technically unjustifiably difficult to unwind, and this is one of the main advantages of Internet delivery compared to over-the-air delivery;
pause is just too difficult to implement.

In fact, the impossibility of implementing an adequate advertising accounting system negates all the desire to use server playlists.

But we, taking into account our peculiarities, still risk advertising in favor of the program guide.

Before you write how to make a program guide, let's prepare the files and place them at the root of your site.
Files for translation usually put in the folder / media / liv
Be sure to create a playlist file playlist.txt (put in the / pls folder) with approximately the following content:

liv/i_out.mp4 liv/ss1.mp4 liv/i_out.mp4 liv/c1g.mp4 liv/i_out.mp4 liv/vv.mp4 liv/i_out.mp4 liv/tr1be.mp4 liv/i_out.mp4 liv/sg1.mp4 


The flussonic.conf configuration file for our task looks like this:

 # Global settings: http 80; http 8080; rtsp 554; rtmp 1935; loglevel error; logrequests true; auth http://yourchannel.ru:8080/tv/auth; pulsedb /var/run/flussonic; edit_auth login password; # DVRs: # Remote sources: # Ingest streams: stream playlist1 { url playlist://http://yourchannel.tv/pls/playlist.txt; auth false; allowed_countries ru; disallowed_countries us; domains yourchannel.tv; meta comment "yourchannel.tv server channel"; } stream tunneling { url rtmp://yourchannel.tv:1935/static/playlist1; auth false; allowed_countries ru; disallowed_countries us; domain yourchannel.tv; transcoder vb=copy; } # Dynamic rewrites: # Publish locations: # Disk file caches: # VOD locations: file vod { path priv; auth true; domain yourchannel.ru; } file liv { path /home/yourchannel/data/www/yourchannel.tv/media/liv; } # Plugins: plugin iptv { database sqlite:///opt/flussonic/priv/iptv.db; } # Includes: 


Let's look at how we can make a program guide using Flussonic media server data provided in a JSON request as an HTTP API - flussonic / flussonic / api / playlist / playlist1

It should be noted that access to the treasured line passes with mandatory HTTP authentication and output data to the external script will not succeed. Let's solve with this “crutch”:

File result.php

 <? $contents = file_get_contents('http://login:password@yourchannel.tv:8080/flussonic/api/playlist/playlist1'); print $contents; ?> 


We get an answer like this:

 {"current_entry":"liv/c1g.mp4","current_type":"file","duration":null,"position":1739946.5416666667} 


where we are interested in the following: current_entry (current playing media file) and position (position by time in the file).

We proceed to the creation of a prototype program guide with the extraction of all parameters and comparison with existing data:

1) Create a table of media database:

 CREATE TABLE IF NOT EXISTS `media` ( `id` int(11) NOT NULL, `name` varchar(255) NOT NULL, `media` varchar(50) NOT NULL, `duration` time NOT NULL, `next_duration` varchar(20) NOT NULL, `description` text NOT NULL, `cc` enum('yes','no') NOT NULL, `shedule_time` varchar(20) NOT NULL ) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; 


2) Let's create the following program listing:

Data.php file

View source
 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <? //        include ('db.php'); $userstable = "media"; $query = "SELECT * FROM $userstable ORDER by id ASC"; $result = MYSQL_QUERY($query); $number = MYSQL_NUMROWS($result); $i = 0; if ($number == 0) { print "<center><P>   ..</center>"; } elseif ($number > 0) { print "<div class=\"container-fluid\"><div class=\"row\"><h4> :</h4>"; while ($i < $number) { $namer = mysql_result($result,$i,"name"); $media = mysql_result($result,$i,"media"); $duration = mysql_result($result,$i,"duration"); $description = mysql_result($result,$i,"description"); $shedule_time = mysql_result($result,$i,"shedule_time"); $contents = file_get_contents('http://yourchannel.tv/result.php'); $my_file = 'infotrack.txt'; $pfile = 'playinfo.txt'; $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); $data = $contents; fwrite($handle, $data); $info = json_decode($contents); $name = $info->current_entry; $time = $info->position; // liv/       $fullname = substr($name, 4); //       $second = $time / 1000; sscanf($duration, "%d:%d:%d", $hour, $minutes, $seconds); //    $ms = $seconds * 1000 + $minutes * 60 * 1000 + $hour * 30 * 60 * 1000; $ostatok = ($ms - $second); if ($fullname == $media) { print "<a href=\"#\" class=\"list-group-item active\" title=\"".$description."\"><h4 class=\"list-group-item-heading\"><span class=\"label label-success\"> !</span> ".$namer."</h4>"; echo "<h4><i class=\"fa fa-play-circle-o\"></i>"; $estimated = gmdate("H:i:s", $second); echo $estimated; $elapsed = gmdate("H:i:s", $ostatok-25500); $conv_total_time = strtotime($duration); $conv_est_time = strtotime($estimated); $calc_time = $conv_total_time - $conv_est_time; $calctime = gmdate("H:i", $calc_time); $nowtime = time(); $next_time = $nowtime + $calc_time; $res_time = date("H:i", $next_time); echo " | <i class=\"fa fa fa-clock-o\"></i> ".$duration." <br><i class=\"fa fa-cc fa-2x\" title=\" \"></i></h4>"; echo "  : ".$calctime."<br>"; echo "   : ".$res_time."<br>"; print "</a> <div class=\"list-group\"> <div class=\"progress\"> <div class=\"progress-bar progress-bar-success progress-bar-striped active\" role=\"progressbar\" aria-valuenow=\"100\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 100%\"></div></div></div>"; } else { $conv_duration = strtotime($duration); $conv_res_time = strtotime($res_time); $res_final_time = $conv_duration + $conv_res_time; $res_time2 = date("H:i",$res_final_time+3600); print "<div class=\"list-group\"><a href=\"#\" class=\"list-group-item\" title=\"".$description."\"> <h4 class=\"list-group-item-heading\"><span class=\"label label-default\">".$res_time."</span> ".$namer."</h4> <p class=\"list-group-item-text\"><h5>: ".$duration." <i class=\"fa fa-cc fa-2x\" title=\" \"></i></h5></a></div>"; } $i++; } print "</center></div></div>"; } ?> 



We get this look:
image

Now we need to make the program update updated after a certain period of time (set 15 seconds).

We write a small script:

 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> var jq = $.noConflict(); //        Jquery,     jq(document).ready(function() { var auto_refresh = setInterval(function () { jq('#info').load('data.php'); }, 15000); //   15  }); </script> <div id="info">  , ..<br><center><i class="fa fa-refresh fa-spin fa-4x"></i></center></div> </body> </html> 


While the necessary functionality is enough, the program pleases the eyes:

image

I will be glad to your opinion and ideas on the modernization of the program schedule.

Additional Information:
Server playlists
Preparing a file for broadcasting
Video publishing to server

Source: https://habr.com/ru/post/262755/


All Articles