How To Install The Internet TV Script

How To Install The Internet TV Script


You will need the following Server Configuration to run the Internet TV Script:
PHP 5 and above
Mysql 5 and above
PhpMyAdmin 2.11 and above

1, If you havent done so already download the script tv script and save the file to your hard drive.

2, Next you need an FTP program so you can upload the script to your site. If you dont have one try doing a search on Google for FileZilla or alternative.

3, Next extract the contents of the archive you downloaded earlier remembering the directory you extract it to.

4, Next on the websites control panel select MySql Databases and create a database and add a user & password to it.

5, Next on the websites control panel select PhpMyAdmin and locate and select the database you just created, and select Import Tab along the top, now when the Import page displays find "File to import" and click the Browse button to the right and locate and select the file sql.txt from within the tv script file you downloaded earlier.

6, Now select G0 from bottom right and wait. If all went well the database should now be uploaded successfully. If not go back and review steps 4-6.

Now it time edit the config.php file that was in the download.

7, Find in config.php the following:

$email="me@myemail.com";

// Database info
$dbhost="localhost"; // Should not need to alter
$dbuser=""; // <- DB Username
$dbpass=""; // <- DB Password
$dbname=""; // <- DB Name

8, Change what found to reflect your actual info eg:

$email="myemail@mydomain.com";

// Database info
$dbhost="localhost"; // Should not need to alter
$dbuser="tvpcscript"; // <- DB Username
$dbpass="G543jyY1kJ23Q"; // <- DB Password
$dbname="tvchannels"; // <- DB Name

The above is an example and you should use your actual data instead.

9, If all the above has been done without problems it is time to upload the script.

10, Using your FTP program or FileZilla in step 2 above Upload the enire root directory that is all file and directories that are in the same directory as config.php, you do not need to set any write properties.

11, If all went well and no problems navigate to the url for the script and it should display and work.

12, If it does not work then you have done something wrong if this is the case go and review steps 1-12.

Configuring The Internet TV Script


Once you have Uploaded and Installed the Internet TV Script and it is running as expected, its time to customize it a bit

To begin with yo will probably want to change the name to match your site. This can be done by opening index.php and changing what is between <title>...</title> tags.

Next changing title or elements within the header image. The header template image is in the templates directory within the archive and is called header.png this header was created in fireworks and is fully editable.

Once finished editing export the file to images/header.jpg

Also in the templates directory is connect.png this is for the small animation that appears before a stream starts playing this was also created in fireworks and is fully editable.

Once finished editing export the file to online/connect.gif

In the templates directory you will also find the following:

nav_blue.png
nav_brown.png
nav_green.png

These files are for the channels navigation menus colour sceme, these also were created in fireworks and are fully editable.

Once finished editing export the files to css/ directory.

If you want to change the position of the Categories or Countries channel selection menus. Locate the following in index.php:

This one has the Categories channel selection:-

<div class="title"><b>&nbsp;Categories</b></div>
<div style="padding:2px; height:470px; overflow:auto">
<div class="accordion"><div class="accordion1"><?=$categories ?></div></div>
</div>

and This one has the Countries channel selection:-

<div class="title"><b> &nbsp;Countries</b></div>
<div style="padding:2px; height:470px; overflow:auto">
<div class="accordion"><div class="accordion2"><?=$countries ?></div></div>
</div>

If you move either of the above this would allow you to place the channel selection navigation menus to where you would like them.

The player and associated components are located in the following:

<div style="background:#000000; padding:2px; min-height:320px"><div id='player'></div></div>

Editing The Scripts Database

To edit the scripts database. The admin directory contains all the script to maintain the database. To load the menu goto the following:

admin/admin.php this displays the following menu.

Add New Channel
Edit / Update Channel
Delete Channel
Display Database

Add New Channel

This is where you add your new channel by giving a channel name, country, category, stream URL, player type (windows media player or flash player) and finally give a discription then press Add Channel.

Edit / Update Channel

First select the channel you want to edit from the drop down list.

You can now channel by editing the channel name, country, category, stream URL, player type (windows media player or flash player) and finally give a discription then press Update Channel.

Delete Channel

First select the channel you want to delete from the drop down list.

You can then review various info about the channel to make sure it is the one you want to delete. then if it is press Delete Channel.

Display Database

Selecting this displays a list of 25 channels and at the top of the page you can page through the database at 25 channels a page.



Technical Details of The Script

Although the Internet TV Script needs all the files the following are the main ones used from a programming point of view.

config.php
index.php
serverA.php

config.php
This file contains various configuration options such as variables that contain email address and database configuration.

index.php
include("config.php");

$dbz=mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname, $dbz) or die (mysql_error());

The above loads and executes the contents of config.php. In this case it initializes the database variables and sets the email variable.

Next is setting up the Categories and Countries stream selection menu, heres the code for setting up the Categories.

$query1 = "SELECT SQL_CACHE DISTINCT category FROM tvchannels WHERE category != 'Adults' AND category != '' ORDER BY category ASC";

$result1 = mysql_query($query1,$dbz) or die (mysql_error());
while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }
$categories=""; 
foreach ($records1 as $rec){
$categories.="<h3 onclick=\"GetCat('".getSI($rec['category'])."')\">".$rec['category']."</h3>";
$categories.="<div class='menuz'><ul id='".getSI($rec['category'])."'></ul></div>";
}

The code above first sets up a mysql query to get all the categories available.it then loops throgh the results and creates the categories that are displayed when you load the script into your browser.

Each category member when setup uses a javascript function GetCat("category") so when a user clicks on one of the categories the function is called and this in turn populates that category with a sub menu of channels that belong to that category.

Further down the page there will be some HTML similar to this:

<div class="accordion"><div class="accordion1"><?=$categories ?></div></div>

The code <?=$categories ?> holds the actual categories code that gets displayed, and the DIVs that surround that are the menu appearence and functionality containers.

Heres the code for setting up the Countries.

$query2 = "SELECT SQL_CACHE DISTINCT country FROM tvchannels WHERE country != '' ORDER BY country ASC";

$result2 = mysql_query($query2,$dbz) or die (mysql_error());
while ($record2 = mysql_fetch_array($result2) ) { $records2[] = $record2; }
$countries=""; 
foreach ($records2 as $rec){
$countries.="<h3 onclick=\"GetCntry('".getSI($rec['country'])."')\">".$rec['country']."</h3>";
$countries.="<div class='menuz'><ul id='".getSI($rec['country'])."'></ul></div>";
}

The code above first sets up a mysql query to get all the countries available.it then loops throgh the results and creates the countries that are displayed when you load the script into your browser.

Each country member when setup uses a javascript function GetCntry("country") so when a user clicks on one of the countries the function is called and this in turn populates that country with a sub menu of channels that belong to that country.

Further down the page there will be some HTML similar to this:

<div class="accordion"><div class="accordion2"><?=$countries ?></div></div>

The code <?=$countries ?> holds the actual countries code that gets displayed, and the DIVs that surround that are the menu appearence and functionality containers.

Near the bottom of the page there is some javascript.

<script type="text/javascript">
$(document).ready(function(){
$(".accordion1 div:first").hide();
$(".accordion1 div:not(:first)").hide();

$(".accordion1 h3").click(function(){
$(this).next("div").slideToggle("slow")
.siblings("div:visible").slideUp("slow");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});

$(".accordion2 div:first").hide();
$(".accordion2 div:not(:first)").hide();

$(".accordion2 h3").click(function(){
$(this).next("div").slideToggle("slow")
.siblings("div:visible").slideUp("slow");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});
$(".menuz li").click(function(){
$("li").removeClass("active");
$(this).toggleClass("active");
});
});

function GetCat(category){
$.get("serverA.php?what=catchanns&cat="+category, function(response) {
document.getElementById(category).innerHTML=response;
//$("#"+category).html(response);
});
}
function GetCntry(country){
$.get("serverA.php?what=cntrychanns&cat="+country, function(response) {
document.getElementById(country).innerHTML=response;
//$("#"+country).html(response);
});
}
function Play(tvid){
$.get("serverA.php?what=play&cat="+tvid, function(response) {
document.getElementById('player').innerHTML=response;
});
}

<? if(isset($_GET['play']) and is_numeric($_GET['play'])){ ?>
Play(<?=$_GET['play'] ?>);
<? } ?>
</script>

In the above code the first part is for the channel selection menu functionality and its appearence.
After that we have the GetCat() javascript function this calls serverA.php to retrieve the categories.
After that we have the GetCntry() javascript function this calls serverA.php to retrieve the countries.
After that we have the Play() javascript function this calls serverA.php to retrieve the the stream info to play it.

serverA.php

This file does all the work for index.php. It creates and returns the channels for both categories and countries when someone clicks on either a actual ctegory or country.

Below is how the channels are displayed if someone clicks on a category:

...elseif($what=='catchanns'){
$dbz=mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname, $dbz) or die (mysql_error());

$query1 = "SELECT SQL_CACHE * FROM tvchannels WHERE category = '".$cat."' AND channel != '' AND enabled = 1 AND chanworking = 1 ORDER BY channel";
$result1 = mysql_query($query1,$dbz) or die (mysql_error());
while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }
foreach ($records1 as $rec){
echo "<li onclick=\"Play('".getSI($rec['tvid'])."')\" title=\"".$rec['discription']."\">".$rec['channel']."</li>";
}
}elseif...

This sets up mysql to get all channels that are in the category held in the variable $cat so long as the channel is not empty and the channel is enabled and also working.

Then after retrieving the channels it then loops through them creating the code for the channels links that are displayed and also sets up the javascript to play the channels.

Also below is how the channels are displayed if someone clicks on a country:

...elseif($what=='cntrychanns'){
$dbz=mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname, $dbz) or die (mysql_error());

$query1 = "SELECT SQL_CACHE * FROM tvchannels WHERE country = '".$cat."' AND channel != '' AND enabled = 1 AND chanworking = 1 ORDER BY channel";
$result1 = mysql_query($query1,$dbz) or die (mysql_error());
while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }
foreach ($records1 as $rec){
echo "<li onclick=\"Play('".getSI($rec['tvid'])."')\" title=\"".$rec['discription']."\">".$rec['channel']."</li>";
}
}elseif...

This sets up mysql to get all channels that are in the category held in the variable $cat so long as the channel is not empty and the channel is enabled and also working.

Then after retrieving the channels it then loops through them creating the code for the channels links that are displayed and also sets up the javascript to play the channels.

Below is the code that looks after playing a channel:

...elseif($what=='play'){
$dbz=mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname, $dbz) or die (mysql_error());

$query1 = "SELECT SQL_CACHE * FROM tvchannels WHERE tvid = '".$cat."'";
$result1 = mysql_query($query1,$dbz) or die (mysql_error());
while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }
$rec=$records1[0];

$st=str_replace("&logo=http://i43.tinypic.com/xmqq9t.gif", "", $rec['streamurl']);
echo "<div align='left' style='padding: 4px; color:#FFFFFF;'><b>".$rec['channel']."</b></div>";
//echo "<div align='left' style='padding: 4px; padding-top: 0px; color:#FFFFFF;'>".$rec['discription']."</div>";
if($rec['chanworking']==0){
$plr="<p style='font-size:20px; color:#FFFFFF;'><br><br><br><br><b>".$rec['channel']."</b><br>This Channel is currently not working.<br><br><b>Please try again later.</b></p>";
echo $plr;

}else{
$d=$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
if (dirname($_SERVER['PHP_SELF'])=="/") $d=$_SERVER['HTTP_HOST'];

if($rec['player']=="fp"){
$plr="<embed src=\"".$st."\" width=\"490\" height=\"320\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"autostart=true&repeat=list&width=490&height=320&logo=\"></embed>";
}else{
$plr="<embed type=\"application/x-mplayer2\" width=\"490\" height=\"320\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" autostart=\"1\" showcontrols=\"1\" mute=\"false\" volume=\"100\" autoplay=\"1\" uimode=\"full\" enablefullscreencontrols=\"true\" autosize=\"1\" showtracker=\"1\" transparentatstart=\"1\" showstatusbar=\"1\" showdisplay=\"0\" stretchToFit=\"1\" displaybackcolor=\"000000\" src=\"http://".$d."/play.php?tvid=".getSI($rec['tvid'])."\"></embed>";
}
echo $plr;

echo "<div align='center' style='padding: 4px; color:#FFFFFF;'><b>Please allow some time for the stream to start playing</b></div>";
$eml="mailto:".$email;
$eml.="?Subject=Channel Not Working (".$_SERVER['HTTP_HOST'].")";
$eml.="&Body=Channel Info:".urlencode("\n\n")."Channel ID: ".getSI($rec['tvid']).urlencode("\n")."Channel: ".$rec['channel'].urlencode("\n")."Category: ".$rec['category'].urlencode("\n")."Discription: ".$rec['discription'];

echo "<div style='margin:auto'><a align=\"center\" href=\"".$eml."\" style='color:#99FFFF; font-weight:bold'>Channel Not Working? Report It</a></div>";

echo "<div align='left' style='padding:4px; color:#99FFFF'>&nbsp;&nbsp;&nbsp;&nbsp;Direct URL to this Channel:</div>";
echo "<div style='padding-bottom:4px'><input type='text' value='http://".$d."/?play=".$rec['tvid']."' size='74' style='color:#cccccc; background:#444444' /></div>";
echo "<div align='left' style='padding:4px; color:#99FFFF'>&nbsp;&nbsp;&nbsp;&nbsp;Embed in your website/blog:</div>";
echo "<div style='padding-bottom:4px'><input type='text' value='".$plr."' size='74' style='color:#cccccc; background:#444444' /></div>";
}
}

This then when clicked on gets the channel to play when clicked on.

First it call mysql to get all info for the channel that has tvid held in $cat, then it builds the embed code for either windows media player or flash player, it finds which one by looking at the value held in field player in the returned mysql data, if its wm it windows media if its fp its flash player.

With this info the correct player embed code is selected and the stream url is added.

after the embed code and url is added then info about the channel is added along with perma link url and embed code itself, This is all added in order and displayed.