📜 ⬆️ ⬇️

Reverse engineering: tvali.ge service

Background (can be skipped)


Situation: there is a large local area network with inaccessible "external" and a free more or less productive machine with unlimited external Internet.
And there is a common desire among students: to watch football on the Internet, due to the inaccessibility of the TV in the hostels.
After much trial and error with the retransmission of TV from the "external" (communication breaks in the evening, any lag of the video source - breaks and "cubes" from everyone inside the local network) were searching for alternative sources of the channel with sports. Satellite dish can not be put. And in the end the site was found - tvali.ge , which works according to the scheme:
Captured video from the channel (5 minutes) -> saved -> gave it to the user in a flash player. All delayed from the original stream in 10 minutes
Demonstration of the player


Under the cat a detailed scheme of the service and the decision how to drag the channel to yourself.

TV viewing scheme

I went to the site (I got a cookie) -> opened the page with the desired channel -> you watch the channel record.
But! Cookie. If you do not have a session from the site, then the player will not load your playlist and display on the screen:
We are trying to look without a session. Access Denied

Well, look further.
The service provides an "insert" on any player site with this channel. Let us examine the "NTV + Sport", namely part of the call player. I will comment on the interesting lines for us from the insert, which gives the service:

var cc=955; // ID    var d = new Date(); var cd = d.getDay()*(24*60)+d.getHours()*60+Math.floor(d.getMinutes()/5)*5-10; //  ""  (    ). var fn = "http://tvali.ge/tv/"+cc+"_list.php?d="+cd; //      . 

')
Parsing a ban on access to a channel without a cookie

Follow the link with the playlist. This is where the cookie is checked.
If we have a “ticket” (expressed in the words of the service developer) from a site visit, then the playlist is correctly generated and gives us links to the files with the channel record. Example of a link to one of the entries:

tvali.ge/c.php?action=010102&vid=010102-06-12-12.mp4

The playlist is generated depending on what we passed to it in the "? D =" parameter. And there - the time in seconds since the beginning of the week (rounded to the minute (5)) and minus 10 minutes (broadcast delay).
Without a cookie, we will get a link to one record, the screenshot of which provided above.
www.tvali.ge/noaccess.flv
As it turned out, cookies are checked and when accessing the file. So without them, we can’t “pull” the file to us.

We start to implement a copy of the service
Download files to yourself

Let's sort the file name - 06-12-35-00
06 - day of the week
12 - hours
35 minutes
00 - seconds
Fine! We are going to write a script that will download files to us.

 <?php set_time_limit(0); function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt($c, CURLOPT_COOKIE, 'CO=cookie_from_service'); curl_setopt($c, CURLOPT_URL, $URL); $contents = curl_exec($c); curl_close($c); if ($contents) { $out_handle = fopen ('/var/www/domain/videos/'.substr($URL, -12), "wb+"); fwrite ($out_handle, $contents); } } // .      2 . 15  -   $mod_time = time() - 2*60*60 - 15*60; $min = floor(date("i", $mod_time)/5)*5; if ($min < 10) $min = '0'.$min; $hours = date("H", $mod_time); $vid = "010102-0".date("w", $mod_time)."-".$hours."-".$min."-00.mp4"; curl_get_file_contents('http://tvali.ge/c.php?action=010102&vid='.$vid); echo 'http://tvali.ge/c.php?action=010102&vid='.$vid; ?> 


And so, we have a script, the execution of which we add to cron (every 5 minutes)
*/5 * * * * /usr/bin/php /var/www/downloader.php

Player

The scheme of the player that on the service itself:
received a playlist -> divided all the records in half and began to show from it.
Writing a playlist generator:
 <?php $mod_time = time() - 2*60*60 - 17*60 - 12*60*60; $links = "<playlist version = \"1\"><trackList>"; $titles = ""; for ($i = 0; $i< 288; $i++) { $min = floor(date("i", $mod_time)/5)*5; if ($min < 10) $min = '0'.$min; $hours = date("H", $mod_time); if ($hours < 22) $title = $hours+2; else $title = $hours-22; $title .= ":".$min; $links .= "<track><title>$title</title><location>http://domain/videos/$hours-$min-00.mp4</location></track> "; $mod_time += 300; } echo $links."</trackList></playlist>"; ?> 

As you can see, the playlist generator, unlike the original, does not take into account the date parameter, it simply does not exist. I decided that this is a better option, to determine the real time on the server, rather than the user, in order to avoid possible errors when working with the player.
Actually everything, be sure to download the flash player of this resource to yourself, change the var fn = ... to the address with the playlist script and watch the sport in excellent quality in the local network.

Maybe someone will say "it is pointless to watch the sport with a delay of 20 minutes," but this is still the only option.
PS It is possible to “pull out” other channels in the same way, but the same “STS” in the evenings they break off, recordings for 1-2 minutes (and should be 5 each).

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


All Articles