Nextrek
@ 772
Nextrek / Web / epg / load_epg.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
<html> <body> <pre> <?php require_once 'utils.php'; require_once 'database.php'; /* http://guidatv.sky.it/app/guidatv/contenuti/data/grid/grid_digitale_channels.js http://guidatv.sky.it/app/guidatv/contenuti/data/grid/13_01_19/ch_6601.js */ function mappatura($genre, $subgenre, $description) { if ($genre == 'film') return $genre.' '.$subgenre; if ($subgenre == 'altri') $subgenre = $genre; if ($subgenre == 'sit com') $subgenre = 'telefilm'; if ($subgenre == 'telenovela') $subgenre = 'telefilm'; if ($subgenre == 'soap opera') $subgenre = 'telefilm'; if ($subgenre == 'fiction') $subgenre = 'telefilm'; if ($subgenre == 'docu-fiction') $subgenre = 'telefilm'; if ($subgenre == 'news') $subgenre = 'notiziario'; if ($subgenre == 'spettacolo') $subgenre = 'show'; if ($subgenre == 'gioco') $subgenre = 'show'; if ($subgenre == 'lifestyle') $subgenre = 'moda'; if ($subgenre == 'animazione') $subgenre = 'cartoni animati'; return $subgenre; } function carica_palinsesto( &$channels, $time_reference ) { println('recupero dati EPG per il giorno: '.date('y_m_d', $time_reference)); $curl_calls = array(); //create the multiple cURL handle $mh = curl_multi_init(); foreach($channels as $channel_id => $channel) { $ch = prepare_wget('http://guidatv.sky.it/app/guidatv/contenuti/data/grid/'.date('y_m_d', $time_reference).'/ch_'.$channel_id.'.js'); $curls_calls[] = $ch; curl_multi_add_handle($mh,$ch); } $active = null; //execute the handles do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } println('preparazione query insert'); //close the handles foreach($curls_calls as $ch) { $error = curl_error($ch); if(empty($error)) { $data = json_decode(curl_multi_getcontent( $ch ), true); $channel_id = $data['channel']; $channel_name = $channels[$channel_id]['nome']; $plan = $data['plan']; $amg = date('Ymd', $time_reference); $last_starttime="0000"; $epg = &$channels[$channel_id]['epg']; for($index = 0; $index < count($plan); $index++) { $program = $plan[$index]; if ($program['id']!=-1) { $starttime = str_replace(':','',$program['starttime']); $durata = $program['dur']; $titolo = $program['title']; /* * MAPPATURA GENRE / SUBGENRE / DESC -> DESCRIZIONE */ $descrizione = mappatura($program['genre'],$program['subgenre'],$program['desc']); if ($starttime<$last_starttime) { $reference = mktime(0,0,0,date('m',$time_reference),date('d',$time_reference)+1,date('Y',$time_reference)); $amg = date('Ymd', $reference); } $timestamp = $amg.$starttime; $last_starttime = $starttime; //println(','.$channel_id.','.$channel_name.','.$timestamp.','.$durata.','.str_replace(',',' ',$titolo).','.str_replace(',',' ',$descrizione)); $epg[$timestamp] = array( $timestamp, $channel_name, $titolo, $descrizione, $durata ); } } } else { println($error); } curl_multi_remove_handle($mh, $ch); } curl_multi_close($mh); } if (sql_connect()) { println('recupero lista canali'); $scraped_channels = json_decode(wget('http://guidatv.sky.it/app/guidatv/contenuti/data/grid/grid_digitale_channels.js'), true); println('recupero dati canali'); $channels = array(); for($index = 0; $index < count($scraped_channels); $index++) { $scraped_channel = &$scraped_channels[$index]; $id = $scraped_channel['id']; $name = $scraped_channel['name']; $name = trim(str_replace('(DTT)','',$name)); $channels[$id] = array( 'nome' => $name, 'logo' => $scraped_channel['channelvisore'], 'epg' => array() ); /* $imageObject = imagecreatefromgif($channels[$id]['logo']); imagepng($imageObject, 'logo/'.$name.'.png');*/ } carica_palinsesto( $channels, mktime(0,0,0,date("m"),date("d"),date("Y")) ); carica_palinsesto( $channels, mktime(0,0,0,date("m"),date("d")+1,date("Y")) ); println('caricamento su DB'); sql_begin(); foreach($channels as $channel_id => $channel) { println($channel_id . ' -> ' . $channel['nome']); $epg = array_values($channel['epg']); sql_delete('palinsesto', '`canale`=\''.sql_escape($channel['nome']).'\''); sql_insert_bulk('palinsesto', array('timestamp','canale','programma','tipo','durata'),$epg); } sql_commit(); //print_r($channels); println('fatto'); sql_disconnect(); } else { println(sql_last_error()); } ?> </pre> </body> </html> |
Commits for Nextrek/Web/epg/load_epg.php
Revision | Author | Commited | Message |
---|---|---|---|
9 | DRuega | Mon 06 May, 2013 21:54:02 +0000 | Ripristinato EPG |