Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 24/08/2014, à 20:38

k3c

TV Europe

Il existe un script qui permet de regarder des TV allemandes, suisses, sportives, italiennes...
http://darbycrash.altervista.org/PHP/WilmaaTV.php.txt

En partant de ce script, j'ai voulu faire un script un peu plus user friendly, dans lequel on clique au lieu de rentrer des valeurs.

Voici la v1, aidé par Hizoka, que je remercie

num=$(zenity --height "600" --width "800" --list --column="Numero" --column="Nom" --hide-column="1" --print-column="1" --hide-header \
0 DASERSTE \
1 ZDF \
2 WDR \
3 SAT1 \
4 RTL \
5 RTL2 \
6 PROSIEBEN \
7 VOX \
8 KABELEINS \
9 DMAX \
10 SIXX \
11 DASVIERTE \
12 NICKCC \
13 SUPERRTL \
14 VIVA \
15 SPORT1 \
16 N24 \
17 NTV \
18 KIKA \
19 SF1 \
20 SF2 \
21 ORF1 \
22 ORF2 \
23 3PLUS \
24 ARTEDE \
25 SFINFO \
26 3SAT \
27 ZDFNEO \
28 SWR \
29 BR3 \
30 PHOENIX \
31 EUROSPORTDE \
32 JOIZ \
33 TZURICH \
34 TSUDOST \
35 EURONEWSDE \
36 CNN \
37 BBCWORLD \
38 RTS1 \
39 RTS2 \
40 TV5MONDE \
41 FRANCE2 \
42 FRANCE3 \
43 FRANCE5 \
44 RTL9 \
45 TF1 \
46 M6 \
47 ARTEFR \
48 RSILA1 \
49 RSILA2 \
50 RAI1 \
51 ROUGE \
52 RTLNITRO \
53 SERVUS \
54 ATV \
55 CN \
56 LATELE \
57 C9 \
58 CAJU \
59 T1 \
60 TM1W \
61 TTTG \
62 TTZH \
63 TTSH \
64 TOST \
65 TM1O \
66 CANE \
67 TTICINO \
68 TBASEL \
69 E4 \
70 LEMANBLEU \
71 FILM4 \
72 TBARN \
73 TBIELINGUE)
status=$?
echo $status
[ 0 -eq $status ] &&  php wilm2.php ${num}

wilm2.php

<?php
/*
   Filename: WilmaaTV.php. Copyright 2013/2014, Darby_Crash - kihol@inwind.it

   This Program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This Program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program. If not, see <http://www.gnu.org/licenses/>.

                   Many thanks to mitm for his help !!
*/

$version = "4.0";

error_reporting(0);
class cURL {
      var $headers ;
      var $user_agent ;
      var $compression ;
      var $cookie_file ;
      var $proxy ;
      function cURL ( $cookies = TRUE , $cookie = 'cookies.txt' , $compression = '' , $proxy = '' ) {
      	       $this -> headers [] = 'X-Forwarded-For: 195.186.145.47' ;
	       	     $this -> user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16' ;
		     	   $this -> compression = $compression ;
			   	 $this -> proxy = $proxy ;
				       $this -> cookies = $cookies ;
				       	     if ( $this -> cookies == TRUE ) $this -> cookie ( $cookie );
					     }
					     function cookie ( $cookie_file ) {
					     	      if ( file_exists ( $cookie_file )) {
						      	   $this -> cookie_file = $cookie_file ;
							   	 } else {
								   	fopen ( $cookie_file , 'w' ) or $this -> error ( 'The cookie file could not be opened. Make sure this directory has the correct permissions' );
									      	$this -> cookie_file = $cookie_file ;
										      	 fclose ( $this -> cookie_file );
											 	}
												}
												function get ( $url ) {
													 $process = curl_init ( $url );
													 	  curl_setopt ( $process , CURLOPT_HTTPHEADER , $this -> headers );
														  	      curl_setopt ( $process , CURLOPT_HEADER , 0 );
															      		  curl_setopt ( $process , CURLOPT_USERAGENT , $this -> user_agent );
																	  	      if ( $this -> cookies == TRUE ) curl_setopt ( $process , CURLOPT_COOKIEFILE , $this -> cookie_file );
																		      	 if ( $this -> cookies == TRUE ) curl_setopt ( $process , CURLOPT_COOKIEJAR , $this -> cookie_file );
																			    curl_setopt ( $process , CURLOPT_ENCODING , $this -> compression );
																			    		curl_setopt ( $process , CURLOPT_TIMEOUT , 30 );
																			    if ( $this -> proxy ) curl_setopt ( $process , CURLOPT_PROXY , $this -> proxy );
																			       curl_setopt ( $process , CURLOPT_RETURNTRANSFER , 1 );
																			       		   curl_setopt ( $process , CURLOPT_FOLLOWLOCATION , 0 );
																			   	       $return = curl_exec ( $process );
																			       	       curl_close ( $process );
																			       		  return $return ;
																			  }
}

strncasecmp(php_uname('s'), "Win", 3) == 0 ? $windows = true : $windows = false;

if ($windows)
{
	if (file_exists("C:\\progra~2\\VideoLAN\\VLC\\vlc.exe"))
	   $vlc = "C:\\progra~2\\VideoLAN\\VLC\\vlc.exe";
	   else
		$vlc = "C:\\progra~1\\VideoLAN\\VLC\\vlc.exe";
}
else
{
	$vlc = "vlc";
}

$cc = new cURL ();
$out = "tmp.ts";
unlink($out);

$canali = array("http://pebbles112-lh.akamaihd.net/i/daserste_1@97481/master.m3u8","http://pebbles112-lh.akamaihd.net/i/zdf_1@97483/master.m3u8","http://pebbles114-lh.akamaihd.net/i/wdr_1@97490/master.m3u8","http://pebbles107-lh.akamaihd.net/i/sat1_1@97461/master.m3u8","http://pebbles106-lh.akamaihd.net/i/rtl_1@97459/master.m3u8","http://pebbles107-lh.akamaihd.net/i/rtl2_1@97460/master.m3u8","http://pebbles106-lh.akamaihd.net/i/prosieben_1@97456/master.m3u8","http://pebbles108-lh.akamaihd.net/i/vox_1@97466/master.m3u8","http://pebbles105-lh.akamaihd.net/i/kabeleins_1@97453/master.m3u8","http://pebbles104-lh.akamaihd.net/i/dmax_1@97398/master.m3u8","http://pebbles107-lh.akamaihd.net/i/sixx_1@97462/master.m3u8","http://pebbles104-lh.akamaihd.net/i/dasvierte_1@97396/master.m3u8","http://pebbles105-lh.akamaihd.net/i/nickcc_1@97455/master.m3u8","http://pebbles107-lh.akamaihd.net/i/superrtl_1@97463/master.m3u8","http://pebbles105-lh.akamaihd.net/i/viva_1@97493/master.m3u8","http://pebbles108-lh.akamaihd.net/i/sport1_1@97464/master.m3u8","http://pebbles104-lh.akamaihd.net/i/n24_1@97406/master.m3u8","http://pebbles104-lh.akamaihd.net/i/ntv_1@97405/master.m3u8","http://pebbles113-lh.akamaihd.net/i/kika_1@97487/master.m3u8","http://pebbles110-lh.akamaihd.net/i/sf1_1@97474/master.m3u8","http://pebbles110-lh.akamaihd.net/i/sf2_1@97475/master.m3u8","http://pebbles113-lh.akamaihd.net/i/orf1_1@97573/master.m3u8","http://pebbles113-lh.akamaihd.net/i/orf2_1@97574/master.m3u8","http://pebbles114-lh.akamaihd.net/i/3plus_1@97489/master.m3u8","http://pebbles107-lh.akamaihd.net/i/artede_1@97463/master.m3u8","http://pebbles104-lh.akamaihd.net/i/sfinfo_1@97408/master.m3u8","http://pebbles112-lh.akamaihd.net/i/3sat_1@97480/master.m3u8","http://pebbles111-lh.akamaihd.net/i/zdfneo_1@97479/master.m3u8","http://pebbles113-lh.akamaihd.net/i/swr_1@97485/master.m3u8","http://pebbles107-lh.akamaihd.net/i/br3_1@97517/master.m3u8","http://pebbles111-lh.akamaihd.net/i/phoenix_1@97476/master.m3u8","http://pebbles105-lh.akamaihd.net/i/eurosportde_1@97452/master.m3u8","http://pebbles118-lh.akamaihd.net/i/joiz_1@135266/master.m3u8","http://pebbles119-lh.akamaihd.net/i/tzurich_1@135275/master.m3u8","http://pebbles119-lh.akamaihd.net/i/tsudost_1@135274/master.m3u8","http://pebbles104-lh.akamaihd.net/i/euronewsde_1@97402/master.m3u8","http://pebbles105-lh.akamaihd.net/i/cnn_1@97501/master.m3u8","http://pebbles105-lh.akamaihd.net/i/bbcworld_1@97498/master.m3u8","http://pebbles109-lh.akamaihd.net/i/rts1_1@97469/master.m3u8","http://pebbles109-lh.akamaihd.net/i/rts2_1@97470/master.m3u8","http://pebbles103-lh.akamaihd.net/i/tv5monde_1@97380/master.m3u8","http://pebbles101-lh.akamaihd.net/i/france2_1@97347/master.m3u8","http://pebbles100-lh.akamaihd.net/i/france3_1@97329/master.m3u8","http://pebbles102-lh.akamaihd.net/i/france5_1@97351/master.m3u8","http://pebbles102-lh.akamaihd.net/i/rtl9_1@97354/master.m3u8","http://pebbles109-lh.akamaihd.net/i/tf1_1@97468/master.m3u8","http://pebbles108-lh.akamaihd.net/i/m6_1@97467/master.m3u8","http://pebbles101-lh.akamaihd.net/i/artefr_1@97346/master.m3u8","http://pebbles110-lh.akamaihd.net/i/rsila1_1@97472/master.m3u8","http://pebbles110-lh.akamaihd.net/i/rsila2_1@97473/master.m3u8","http://pebbles103-lh.akamaihd.net/i/rai1_1@97382/master.m3u8","http://pebbles102-lh.akamaihd.net/i/rouge_1@97359/master.m3u8","http://pebbles106-lh.akamaihd.net/i/rtlnitro_1@97458/master.m3u8","http://pebbles114-lh.akamaihd.net/i/servus_1@97488/master.m3u8","http://pebbles114-lh.akamaihd.net/i/atv_1@97491/master.m3u8","http://pebbles100-lh.akamaihd.net/i/cn_1@97368/master.m3u8","http://pebbles100-lh.akamaihd.net/i/latele_1@97375/master.m3u8","http://pebbles117-lh.akamaihd.net/i/c9_1@135252/master.m3u8","http://pebbles117-lh.akamaihd.net/i/caju_1@135253/master.m3u8","http://pebbles118-lh.akamaihd.net/i/t1_1@135267/master.m3u8","http://pebbles108-lh.akamaihd.net/i/tm1w_1@135269/master.m3u8","http://pebbles120-lh.akamaihd.net/i/tttg_1@135278/master.m3u8","http://pebbles119-lh.akamaihd.net/i/ttzh_1@135271/master.m3u8","http://pebbles120-lh.akamaihd.net/i/ttsh_1@135279/master.m3u8","http://pebbles118-lh.akamaihd.net/i/tost_1@135270/master.m3u8","http://pebbles118-lh.akamaihd.net/i/tm1o_1@135268/master.m3u8","http://pebbles117-lh.akamaihd.net/i/cane_1@135254/master.m3u8","http://pebbles117-lh.akamaihd.net/i/tticino_1@135255/master.m3u8","http://pebbles119-lh.akamaihd.net/i/tbasel_1@135273/master.m3u8","http://pebbles105-lh.akamaihd.net/i/e4_1@97502/master.m3u8","http://pebbles102-lh.akamaihd.net/i/lemanbleu_1@97356/master.m3u8","http://pebbles106-lh.akamaihd.net/i/film4_1@97503/master.m3u8","http://pebbles119-lh.akamaihd.net/i/tbarn_1@135272/master.m3u8","http://pebbles120-lh.akamaihd.net/i/tbielingue_1@135280/master.m3u8");
$chn = array();
for ($i=0;$i<count($canali);$i++){
    $xxx = explode("/", $canali[$i]);
    $xxx = explode("_", $xxx[4]);
    $chn[] = strtoupper($xxx[0]);
    }

/*

for ($i=0; $i<count($chn); $i++){
    echo "$i) " . $chn [$i] . ( (( $i + 1 )% 4 == 0 ) ? "\r\n" : str_repeat ( ' ' , 17- strlen ($chn [$i]. $i )) ); // thanks to omepiet
}
*/
$inp = $argv[1];
$quality = "1300";
$temp = $canali[$inp];
$chname = $chn[$inp];
$uri = $cc->get($temp);
echo "\r\n\r\nPlaying " . $chname . "\r\n";
preg_match("|http://(.*)|", $uri, $tmp);
$url = preg_replace("|/index_200_|", "/index_${quality}_", $tmp[0]);
$m3u8man = $cc->get($url);
preg_match("/TARGETDURATION:(.*)/", $m3u8man, $match);
$piecedur = trim($match[1]);
preg_match("/MEDIA-SEQUENCE:(.*)/", $m3u8man, $match);
$pieceseq = trim($match[1]);
preg_match("|http://(.*)|", $m3u8man, $tmp);
$piecepat = preg_replace("/$pieceseq/", '###', $tmp[0]);
function dump_stream($pieceseq, $piecepat, $out) {
	 $pezzo = preg_replace("/###/", "$pieceseq", $piecepat);
	 $cc = new cURL ();
	 $fragment = $cc->get($pezzo);
	 file_put_contents("$out", $fragment, FILE_APPEND);
}
$ciclo = "0";
while(1) {	
	 $sleep = $piecedur;
	 $ciclo++;
	 if ($ciclo == 5) {
	    if (filesize("$out") == 0) {
	       			 echo "\r\n\r\nNo available stream\r\n\r\n";
				      		  break;
							} else {
							       $cmd = $vlc . " --quiet --meta-title=\"" . $chname . " by Darby_Crash\" " . $out;
							       	      if ($windows) {
											pclose(popen("start /B ". $cmd, "r")); // thanks to jairoxyz
													       } else {
															shell_exec($cmd . " > /dev/null 2>/dev/null &");
																	  }
																	   }
																	   } else if ($ciclo < 5) {
																	     $sleep = 0;
																	     }
																	     $bef = time();
																	     dump_stream($pieceseq, $piecepat, $out);
																	     $aft = time();
																	     $delta = $aft - $bef;
																	     $to = $sleep - $delta;
																	     $pieceseq++;
																	     echo "\r\nDltime " . $delta . " sec\r\nSleeping " . $to . " sec\r\n";
																	     sleep($to);
}

Ce script a besoin de php5-cli et php5-curl

J'ai quelques idées pour l'améliorer
- proposer l'enregistrement pour une durée choisie et enregistrer non plus dans un fichier tmp.ts, mais dans un fichier portant le nom de la télé regardée
- indiquer le programme TV au moment où on regarde (de 20 h 40 à 22 h 30 film xxx avec ...)
- le re-écrire en Python vu que je ne cause pas PHP
- re-proposer, comme dans le script d'origine, de choisir la qualité, actuellement je prends directement la meilleure, mais si on a un accès Internet style 512 K, je pense que ça marchera mal.

Dernière modification par k3c (Le 24/08/2014, à 20:49)


Debian 12 sur Thinkpad reconditionné

Hors ligne