diff --git a/RaiReplay/RaiReplay.php b/RaiReplay/RaiReplay.php index e4c4b64..e89bf91 100644 --- a/RaiReplay/RaiReplay.php +++ b/RaiReplay/RaiReplay.php @@ -2,91 +2,82 @@ include_once '/usr/share/umsp/funcs-log.php'; global $logLevel; global $logIdent; -$logLevel = L_ALL; +$logLevel = L_INFO; $logIdent = 'RaiReplayPlugIn'; -$f = file_get_contents("http://nixxo.altervista.org/umsp-plugins/rai_url_extractor.php"); -file_put_contents("/tmp/RaiReplay-temp.php", " $f, 'args' => $args), '', '&'); +function _pluginMain($prmQuery) +{ + _logDebug("plugin start"); + if (strpos($prmQuery, '&') !== false) { + $prmQuery = str_replace('&', '&', $prmQuery); + } + parse_str($prmQuery, $params); + if (isset($params['f']) && function_exists($params['f'])) { + if (isset($params['args'])) { + return call_user_func_array($params['f'], $params['args']); + } else { + return call_user_func($params['f']); + } + } + return rai_main_menu(); } -function build_umsp_url($f, $args = array()) { - return 'umsp://plugins/' . basename(dirname(__FILE__)) . '/' . basename(__FILE__, '.php') . '?' . build_query($f, $args); +function build_query($f, $args = array()) +{ + return http_build_query(array('f' => $f, 'args' => $args), '', '&'); } -function build_server_url($args) { - return 'http://' . $_SERVER['HTTP_HOST'] . '/umsp/plugins/' . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . '?' . http_build_query($args); +function build_umsp_url($f, $args = array()) +{ + return 'umsp://plugins/' . basename(dirname(__FILE__)) . '/' . basename(__FILE__, '.php') . '?' . build_query($f, $args); } -function create_item($title, $thumb, $sortBy, $category = null, $genre = null, $platform = null) { - return array( - 'id' => build_umsp_url('videos', array($sortBy, $category, $genre, $platform)), - 'dc:title' => $title, - 'upnp:album_art' => $thumb, - 'upnp:class' => 'object.container', - ); +function build_server_url($args) +{ + return 'http://' . $_SERVER['HTTP_HOST'] . '/umsp/plugins/' . basename(dirname(__FILE__)) . '/' . basename(__FILE__) . '?' . http_build_query($args); } -function createPlayItem($res, $title, $desc, $album_art, $class, $protocolInfo) { - return array( - 'id' => build_umsp_url('play', array($res, $title, $desc, $album_art, $class, $protocolInfo)), - 'res' => $res, - 'dc:title' => $title, - 'desc' => $desc, - 'upnp:album_art' => $album_art, - 'upnp:class' => $class, - 'protocolInfo' => $protocolInfo, - ); +function create_item($title, $thumb, $sortBy, $category = null, $genre = null, $platform = null) +{ + return array( + 'id' => build_umsp_url('videos', array($sortBy, $category, $genre, $platform)), + 'dc:title' => $title, + 'upnp:album_art' => $thumb, + 'upnp:class' => 'object.container', + ); } -function getConfigValue($key, $default_value) { - $conf_dir = function_exists('_getUMSPConfPath') ? _getUMSPConfPath() : '/conf'; - $config = file_get_contents($conf_dir . '/config'); - if (preg_match("/RAIREPLAY_$key='(.+)'/", $config, $matches)) { - return trim($matches[1]); - } - return $default_value; +function createPlayItem($res, $title, $desc, $album_art, $class, $protocolInfo) +{ + return array( + 'id' => build_umsp_url('play', array($res, $title, $desc, $album_art, $class, $protocolInfo)), + 'res' => $res, + 'dc:title' => $title, + 'desc' => $desc, + 'upnp:album_art' => $album_art, + 'upnp:class' => $class, + 'protocolInfo' => $protocolInfo, + ); } -function putConfigValue($key, $value) { - exec("sudo config_tool -c RAIREPLAY_$key='$value' >/dev/null 2>&1"); +function getConfigValue($key, $default_value) +{ + $conf_dir = function_exists('_getUMSPConfPath') ? _getUMSPConfPath() : '/conf'; + $config = file_get_contents($conf_dir . '/config'); + if (preg_match("/RAIREPLAY_$key='(.+)'/", $config, $matches)) { + return trim($matches[1]); + } + return $default_value; } -if (isset($_GET['video'])) { - _logDebug("video: " . $_GET['video']); - $url = ''; - $ids = explode('@', $_GET['video']); - - foreach ($ids as $id) { - $url = rai_getLink($id); - if ($url) { - break; - } - } - - _logDebug('playing: ' . $url); - ob_start(); - header('Location: ' . $url); - ob_flush(); - exit(); +function putConfigValue($key, $value) +{ + exec("sudo config_tool -c RAIREPLAY_$key='$value' >/dev/null 2>&1"); } -?> \ No newline at end of file diff --git a/RaiReplay/RaiReplay_wec.php b/RaiReplay/RaiReplay_wec.php index bdb154a..42f7abd 100644 --- a/RaiReplay/RaiReplay_wec.php +++ b/RaiReplay/RaiReplay_wec.php @@ -4,70 +4,67 @@ // Does this WEC version support custom hooks? if ((defined('WECVERSION')) && (WECVERSION >= 3)) { + include_once $_SERVER['DOCUMENT_ROOT'] . '/umsp/funcs-config.php'; + // Insert badge if we have one + if ((isset($pluginInfo['thumb'])) && ($pluginInfo['thumb'] != '')) { + $desc = '
logo
' + . '
' . $pluginInfo['name'] . " v" . $pluginInfo['version'] . " (" . $pluginInfo['date'] . ") by " + . $pluginInfo['author'] . ".
" . $pluginInfo['desc'] . "
Information: " . $pluginInfo['url'] . "" + . '
'; + } elseif ((isset($pluginInfo['art'])) && ($pluginInfo['art'] != '')) { + $desc = '
logo
' + . '
' . $pluginInfo['name'] . " v" . $pluginInfo['version'] . " (" . $pluginInfo['date'] . ") by " + . $pluginInfo['author'] . ".
" . $pluginInfo['desc'] . "
Information: " . $pluginInfo['url'] . "" + . '
'; + } else { + $desc = $pluginInfo['name'] . ' v' . $pluginInfo['version'] . ' (' . $pluginInfo['date'] . ') by ' + . $pluginInfo['author'] . '.
' . $pluginInfo['desc'] . "
Information: " . $pluginInfo['url'] . ''; + } - include_once $_SERVER['DOCUMENT_ROOT'] . '/umsp/funcs-config.php'; - // Insert badge if we have one - if ((isset($pluginInfo['thumb'])) && ($pluginInfo['thumb'] != '')) { - $desc = '
logo
' - . '
' . $pluginInfo['name'] . " v" . $pluginInfo['version'] . " (" . $pluginInfo['date'] . ") by " - . $pluginInfo['author'] . ".
" . $pluginInfo['desc'] . "
Information: " . $pluginInfo['url'] . "" - . '
'; - } elseif ((isset($pluginInfo['art'])) && ($pluginInfo['art'] != '')) { - $desc = '
logo
' - . '
' . $pluginInfo['name'] . " v" . $pluginInfo['version'] . " (" . $pluginInfo['date'] . ") by " - . $pluginInfo['author'] . ".
" . $pluginInfo['desc'] . "
Information: " . $pluginInfo['url'] . "" - . '
'; - } else { - $desc = $pluginInfo['name'] . ' v' . $pluginInfo['version'] . ' (' . $pluginInfo['date'] . ') by ' - . $pluginInfo['author'] . '.
' . $pluginInfo['desc'] . "
Information: " . $pluginInfo['url'] . ''; - } + $key = strtoupper("{$pluginInfo['id']}_DESC"); + $wec_options[$key] = array( + 'configname' => $key, + 'configdesc' => $desc, + 'longdesc' => '', + 'group' => $pluginInfo['name'], + 'type' => WECT_DESC, + 'page' => WECP_UMSP, + 'displaypri' => -50, + 'availval' => array(), + 'availvalname' => array(), + 'defaultval' => '', + 'currentval' => '', + ); - $key = strtoupper("{$pluginInfo['id']}_DESC"); - $wec_options[$key] = array( - 'configname' => $key, - 'configdesc' => $desc, - 'longdesc' => '', - 'group' => $pluginInfo['name'], - 'type' => WECT_DESC, - 'page' => WECP_UMSP, - 'displaypri' => -50, - 'availval' => array(), - 'availvalname' => array(), - 'defaultval' => '', - 'currentval' => '', - ); + $wec_options[$pluginInfo['id']] = array( + 'configname' => $pluginInfo['id'], + 'configdesc' => 'Enable ' . $pluginInfo['name'] . ' UMSP plugin', + 'longdesc' => '', + 'group' => $pluginInfo['name'], + 'type' => WECT_BOOL, + 'page' => WECP_UMSP, + 'displaypri' => -45, + 'availval' => array('off', 'on'), + 'availvalname' => array(), + 'defaultval' => '', + 'currentval' => '', + 'readhook' => wec_umspwrap_read, + 'writehook' => wec_umspwrap_write, + 'backuphook' => null, + 'restorehook' => null, + ); - $wec_options[$pluginInfo['id']] = array( - 'configname' => $pluginInfo['id'], - 'configdesc' => 'Enable ' . $pluginInfo['name'] . ' UMSP plugin', - 'longdesc' => '', - 'group' => $pluginInfo['name'], - 'type' => WECT_BOOL, - 'page' => WECP_UMSP, - 'displaypri' => -45, - 'availval' => array('off', 'on'), - 'availvalname' => array(), - 'defaultval' => '', - 'currentval' => '', - 'readhook' => wec_umspwrap_read, - 'writehook' => wec_umspwrap_write, - 'backuphook' => NULL, - 'restorehook' => NULL, - ); - - $wec_options['RAIREPLAY_PREFER_HD'] = array( - 'configname' => 'RAIREPLAY_PREFER_HD', - 'configdesc' => 'Prefer HD quality', - 'longdesc' => '', - 'group' => $pluginInfo['name'], - 'type' => WECT_BOOL, - 'page' => WECP_UMSP, - 'displaypri' => -20, - 'availval' => array('0', '1'), - 'availvalname' => array(), - 'defaultval' => '1', - 'currentval' => '', - ); + $wec_options['RAIREPLAY_PREFER_HD'] = array( + 'configname' => 'RAIREPLAY_PREFER_HD', + 'configdesc' => 'Prefer HD quality', + 'longdesc' => '', + 'group' => $pluginInfo['name'], + 'type' => WECT_BOOL, + 'page' => WECP_UMSP, + 'displaypri' => -20, + 'availval' => array('0', '1'), + 'availvalname' => array(), + 'defaultval' => '1', + 'currentval' => '', + ); } - -?> diff --git a/RaiReplay/config.php b/RaiReplay/config.php index 87eb34f..13e76e4 100644 --- a/RaiReplay/config.php +++ b/RaiReplay/config.php @@ -4,32 +4,28 @@ # _DONT_RUN_CONFIG_ gets set by external scripts that just want to get the pluginInfo array via include() without running any code. Better solution? if (!defined('_DONT_RUN_CONFIG_')) { + include_once $_SERVER['DOCUMENT_ROOT'] . '/umsp/funcs-config.php'; - include_once $_SERVER['DOCUMENT_ROOT'] . '/umsp/funcs-config.php'; + # Check for a form submit that changes the plugin status: + if (isset($_GET['pluginStatus'])) { + $writeResult = _writePluginStatus($pluginInfo['id'], $_GET['pluginStatus']); + } - # Check for a form submit that changes the plugin status: - if (isset($_GET['pluginStatus'])) { - $writeResult = _writePluginStatus($pluginInfo['id'], $_GET['pluginStatus']); - } + # Read the current status of the plugin ('on'/'off') from conf + $pluginStatus = _readPluginStatus($pluginInfo['id']); - # Read the current status of the plugin ('on'/'off') from conf - $pluginStatus = _readPluginStatus($pluginInfo['id']); + # New or unknown plugins return null. Add special handling here: + if ($pluginStatus === null) { + $pluginStatus = 'off'; + } - # New or unknown plugins return null. Add special handling here: - if ($pluginStatus === null) { - $pluginStatus = 'off'; - } + # _configMainHTML generates a standard plugin dialog based on the pluginInfo array: + $retHTML = _configMainHTML($pluginInfo, $pluginStatus); + echo $retHTML; - # _configMainHTML generates a standard plugin dialog based on the pluginInfo array: - $retHTML = _configMainHTML($pluginInfo, $pluginStatus); - echo $retHTML; + # Add additonal HTML or code here - # Add additonal HTML or code here - - # _configMainHTML doesn't return end tags so add them here: - echo ''; - echo ''; + # _configMainHTML doesn't return end tags so add them here: + echo ''; + echo ''; } - -?> - diff --git a/RaiReplay/info.php b/RaiReplay/info.php index 25ca1f6..cd78cc0 100644 --- a/RaiReplay/info.php +++ b/RaiReplay/info.php @@ -1,10 +1,10 @@ 'Rai Replay', - 'desc' => 'Rivedi la programmazione dell\'ultima settimana dei canali Rai direttamente dal tuo WDTV.', - 'author' => 'nixxo', - 'date' => '2019-06-10', - 'version' => '1.0', - 'url' => 'http://forum.wdlxtv.com/viewtopic.php?f=53&t=9305', - 'id' => 'RaiReplay', - 'thumb' => 'https://upload.wikimedia.org/wikipedia/commons/c/ca/RaiPlay.svg', - 'art' => 'https://upload.wikimedia.org/wikipedia/commons/c/ca/RaiPlay.svg', + 'name' => 'Rai Play', + 'desc' => 'Rivedi la programmazione dell\'ultima settimana dei canali Rai direttamente dal tuo WDTV.', + 'author' => 'nixxo', + 'date' => '2019-10-31', + 'version' => '1.1', + 'url' => 'http://forum.wdlxtv.com/viewtopic.php?f=53&t=9305', + 'id' => 'RaiReplay', + 'thumb' => 'https://upload.wikimedia.org/wikipedia/commons/c/ca/RaiPlay.svg', + 'art' => 'https://upload.wikimedia.org/wikipedia/commons/c/ca/RaiPlay.svg', ); - -?> diff --git a/RaiReplay/rai_url_extractor.php b/RaiReplay/rai_url_extractor.php index 1d5aff2..14641ca 100644 --- a/RaiReplay/rai_url_extractor.php +++ b/RaiReplay/rai_url_extractor.php @@ -1,175 +1,469 @@ -function rai_main_menu() { - _logDebug('main menu 16.07.21'); - $items = array(); - $channels = array("RaiUno", "RaiDue", "RaiTre", "RaiCinque", "RaiPremium", "RaiGulp", "RaiYoyo"); - $logos = array( - "http://www.rai.tv/dl/replaytv/images/logo_raiuno.png", - "http://www.rai.tv/dl/replaytv/images/logo_raidue.png", - "http://www.rai.tv/dl/replaytv/images/logo_raitre.png", - "http://www.rai.tv/dl/replaytv/images/logo_raicinque.png", - "http://img.ctrlv.in/img/15/11/23/56530eba364e3.png", - "http://img.ctrlv.in/img/15/11/23/56530e9a21fb6.png", - "http://img.ctrlv.in/img/15/11/23/56530ecf81af6.png", - ); - - for ($i = 0; $i < count($channels); $i++) { - $items[] = array( - 'id' => build_umsp_url('rai_channel', array($channels[$i])), - 'dc:title' => $channels[$i], - 'upnp:album_art' => $logos[$i], - 'upnp:class' => 'object.container', - ); - } - $items[] = array( - 'id' => build_umsp_url('rai_config'), - 'dc:title' => 'Configura Plugin', - 'upnp:album_art' => 'http://lh5.googleusercontent.com/-xsH3IJAYXd0/TvwfRdc7DMI/AAAAAAAAAFk/NmvkjuqP_eo/s220/Settings.png', - 'upnp:class' => 'object.container', - ); - return $items; + build_umsp_url('rai_channel', array($channels[$i])), + 'dc:title' => $channels[$i], + 'upnp:album_art' => $logos[$i], + 'upnp:class' => 'object.container', + ); + } + + $sections = array( + "Programmi", + "Fiction", + "Film", + "Teatro", + "Documentari", + "Musica", + "Bambini e ragazzi", + ); + + $section_urls = array(); + + for ($i = 0; $i < count($sections); $i++) { + $section_urls[$i] = "https://www.raiplay.it/" . strtolower($sections[$i]) . "/?json"; + } + + $sections_logos = array( + "https://www.raiplay.it/dl/doc/1528106939639_ico-programmi.svg", + "https://www.raiplay.it/dl/doc/1528106983569_ico-fiction.svg", + "https://www.raiplay.it/dl/doc/1528107032466_ico-film.svg", + "https://www.raiplay.it/dl/doc/1528115315609_ico-teatro.svg", + "https://www.raiplay.it/dl/doc/1528107054296_ico-documentari.svg", + "https://www.raiplay.it/dl/doc/1528107079722_ico-musica.svg", + "https://www.raiplay.it/dl/doc/1528806533924_ico-kids.svg", + ); + + for ($i = 0; $i < count($sections); $i++) { + $items[] = array( + 'id' => build_umsp_url('rai_section', array($section_urls[$i])), + 'dc:title' => $sections[$i], + 'upnp:album_art' => $sections_logos[$i], + 'upnp:class' => 'object.container', + ); + } + + $items[] = array( + 'id' => build_umsp_url('rai_config'), + 'dc:title' => 'Configura Plugin', + 'upnp:album_art' => 'http://lh5.googleusercontent.com/-xsH3IJAYXd0/TvwfRdc7DMI/AAAAAAAAAFk/NmvkjuqP_eo/s220/Settings.png', + 'upnp:class' => 'object.container', + ); + return $items; } -function clean_title($tit) { - return preg_replace("@'@i", "'", $tit); +function clean_title($tit) +{ + return preg_replace("@'@i", "'", $tit); } -function rai_channel($id) { - _logDebug("channel $id"); - - $mesi = array(1 => 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'); - $giorni = array('Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'); - - $items = array(); - for ($i = 1; $i <= 7; $i++) { - $days_ago = date('Y_m_d', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); - list($g, $gg, $m) = explode('-', date('w-d-n', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y")))); - $items[] = array( - 'id' => build_umsp_url('rai_day', array($id . "_" . $days_ago)), - 'dc:title' => $giorni[$g] . " $gg " . $mesi[$m], - 'upnp:class' => 'object.container', - ); - } - return $items; +function rai_channel($id) +{ + _logDebug("channel $id"); + + $mesi = array(1 => 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'); + $giorni = array('Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'); + + $items = array(); + if ($id == "RaiNews24") { + $ff = file_get_contents("https://studio24.blog.rainews.it/"); + if (preg_match_all("@(.+?)<\/a>@", $ff, $mm)) { + _logDebug(print_r($mm, true)); + foreach ($mm[0] as $k => $v) { + $items[] = createPlayItem( + build_server_url(array('video_page' => $mm[1][$k])), + clean_title($mm[2][$k]), + urlencode($mm[1][$k]), + null, + 'object.item.videoitem', + 'http-get:*:video/mp4:*' + ); + } + } + } elseif ($id == "RaiNews24new") { + $ff = file_get_contents("https://studio24.blog.rainews.it/rss"); + preg_match_all("@src=\"(.+?\?iframe)\&@", $ff, $mm); + preg_match_all("@\s*(.+?)@", $ff, $mt); + if ($mm && $mt) { + _logDebug(print_r($mm, true)); + _logDebug(print_r($mt, true)); + foreach ($mm[0] as $k => $v) { + $items[] = createPlayItem( + build_server_url(array('video_page' => $mm[1][$k])), + clean_title($mt[1][$k]), + urlencode($mm[1][$k]), + null, + 'object.item.videoitem', + 'http-get:*:video/mp4:*' + ); + } + } + } else { + for ($i = 0; $i <= 7; $i++) { + $days_ago = date('d-m-Y', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); + list($g, $gg, $m) = explode('-', date('w-d-n', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y")))); + $items[] = array( + 'id' => build_umsp_url('rai_day', array($id, $days_ago)), + 'dc:title' => $giorni[$g] . " $gg " . $mesi[$m], + 'upnp:class' => 'object.container', + ); + } + } + return $items; } -function rai_day($id) { - _logDebug("day $id"); - $items = array(); - $ff = file_get_contents('http://www.rai.tv/dl/portale/html/palinsesti/replaytv/static/' . $id . '.html'); - $jd = json_decode($ff, true); - - foreach (array_pop($jd) as $dy => $arr) { - foreach ($arr as $k => $v) { - $phd = getConfigValue('PREFER_HD', 1); - $ids = ''; - if ($phd && preg_match('@relinkerServlet\.htm\?cont=(.+)$@', $v['h264_1800'], $m)) { - _logDebug('vid_id[1800]: ' . $m[1]); - $ids = $m[1]; - } elseif (!$phd && preg_match('@relinkerServlet\.htm\?cont=(.+)$@', $v['h264_800'], $m)) { - _logDebug('vid_id[800]: ' . $m[1]); - $ids = $m[1]; - } elseif (preg_match('@relinkerServlet\.htm\?cont=(.+)$@', $v['h264'], $m)) { - _logDebug('vid_id[h264]: ' . $m[1]); - $ids = $m[1]; - } elseif (preg_match('@relinkerServlet\.htm\?cont=(.+)$@', $v['urlTablet'], $m)) { - _logDebug('vid_id[urlTablet]: ' . $m[1]); - $ids = $m[1]; - } else { - _logDebug('url not found.'); - continue; - } - - if (preg_match('@relinkerServlet\.htm\?cont=(.+)$@', $v['r'], $m)) { - if ($m[1] != $ids) { - _logDebug('vid_id[r]: ' . $m[1]); - $ids = $ids . '@' . $m[1]; - } else { - _logDebug('vid[r] not needed.'); - } - } - $v['image'] = preg_match('@^http:\/\/@', trim($v['image'])) ? trim($v['image']) : "http://" . trim($v['image']); - $items[] = createPlayItem( - build_server_url(array('video' => $ids)), - clean_title($k . ' - ' . $v['t']), - $v['d'], - $v['image'] ? $v['image'] : 'http://www.rai.tv/dl/replaytv/images/tappo_rai.png', - 'object.item.videoitem', - 'http-get:*:video/mp4:*'); - } - } - return $items; +function rai_section($id) +{ + _logDebug("section $id"); + $items = array(); + + $itm_type = array( + "Rai Lancio Item" => "rai_section", + "PLR programma configuratore palinsesto Item" => "rai_program", + ); + + $f = file_get_contents($id); + $j = json_decode($f); + $j = $j->{'blocchi'}[0]->{'lanci'}; + + for ($i = 0; $i < count($j); $i++) { + $tmp = preg_replace("@^/(raiplay|dl)/@", "https://www.raiplay.it/$1/", $j[$i]->{'PathID'}); + $items[] = array( + 'id' => build_umsp_url($itm_type[$j[$i]->{'original-type'}], array($tmp)), + //'id' => build_umsp_url('rai_section', array($tmp)), + 'dc:title' => $j[$i]->{'name'}, + 'upnp:album_art' => str_replace("[RESOLUTION]", "480x480", $j[$i]->{'images'}->{'landscape'}), + 'upnp:class' => 'object.container', + ); + } + + return $items; + exit; } -function rai_config($key = null, $value = null) { - if ($key != null) { - putConfigValue($key, $value); - } - - $prefer_hd = getConfigValue('PREFER_HD', 1); - - $Items[] = array( - 'id' => build_umsp_url('config', array('PREFER_HD', !$prefer_hd)), - 'dc:title' => 'HD ' . ($prefer_hd ? 'on' : 'off') . ' - Seleziona per ' . ($prefer_hd ? 'disattivarlo' : 'attivarlo'), - 'upnp:album_art' => 'http://lh4.googleusercontent.com/-hsbvm1bQllg/Tvwgvvk5BnI/AAAAAAAAAFs/DHQp5lKE7-4/s220/HD-icon.png', - 'upnp:class' => 'object.container', - ); - $Items[] = array( - 'id' => build_umsp_url('main_menu'), - 'dc:title' => 'Indietro', - 'upnp:album_art' => 'http://lh3.googleusercontent.com/-dsT4ZvjCth4/TvwihbvNZLI/AAAAAAAAAF0/1Jp9s8dLNlY/s220/back_button_icon.png', - 'upnp:class' => 'object.container', - ); - return $Items; +function rai_sub_section($id) +{ + _logDebug("sub section $id"); + $items = array(); + + //old: implementation based on the web page [DEPRECATED] + $f = file_get_contents($id); + + preg_match_all("@
\s*(.+?)\s*<\/div>@", $f, $tit); + preg_match_all("@ build_umsp_url('rai_program', array($ul[$i])), + 'dc:title' => $tit[$i], + 'upnp:album_art' => $art[$i], + 'upnp:class' => 'object.container', + ); + } + + return $items; } -function rai_createLink($url) { - _logDebug("creating link from: $url"); - $phd = getConfigValue('PREFER_HD', 1); - if (preg_match('@replaytv\/(.+?\/\d{4,8})[\/_]@', $url, $m)) { - for ($i = 1; $i <= 4; $i++) { - $u = "http://creativemedia$i.rai.it/Italy/podcastmhp/replaytv/" . $m[1] . ($phd ? '_1800' : '_800') . ".mp4"; - $h = get_headers($u); - _logDebug("test: $u > " . $h[0]); - if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { - return $u; - } - } - } elseif (preg_match('@replaytv_world\/(.+?\/\d{4,8})[\/_]@', $url, $m)) { - for ($i = 1; $i <= 4; $i++) { - $u = "http://creativemedia$i.rai.it/podcastmhp/replaytv_world/" . $m[1] . ($phd ? '_1800' : '_800') . ".mp4"; - $h = get_headers($u); - _logDebug("test: $u > " . $h[0]); - if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { - return $u; - } - } - } else { - _logDebug("***********\r\n UNSUPPORTED LINK: $url\r\n***********"); - } - return null; +function rai_program($id) +{ + $id = preg_match("@^\/r@", $id) ? "http://www.raiplay.it" . $id : $id; + _logDebug("program $id"); + $items = array(); + + $f = file_get_contents($id); + //_logDebug(print_r($f, true)); + + $j = json_decode($f, true); + if (isset($j['Blocks'])) { + _logDebug("BLOCKS"); + //_logDebug(print_r($j['Blocks'], true)); + foreach ($j['Blocks'] as $bb) { + foreach ($bb['Sets'] as $b) { + $tt = $bb['Name'] == $b['Name'] ? $bb['Name'] : $bb['Name'] . ' - ' . $b['Name']; + $tt = strpos($tt, $j['Name']) ? $tt : $j['Name'] . " " . $tt; + $items[] = array( + 'id' => build_umsp_url('rai_program', array($b['url'])), + 'dc:title' => $tt, + 'upnp:album_art' => '', + 'upnp:class' => 'object.container', + ); + } + } + if (count($items) == 1) { + _logDebug("auto enter"); + return rai_program($j['Blocks'][0]['Sets'][0]['url']); + } + } elseif (isset($j['items'])) { + _logDebug("ITEMS"); + //_logDebug(print_r($j['items'][0], true)); + foreach ($j['items'] as $b) { + if ($b['type'] == 'RaiTv Media Video Item') { + $tt = isset($b['titoloEpisodio']) ? $b['titoloEpisodio'] : $b['name']; + $tt = $tt ? $tt : $b['name']; + $items[] = createPlayItem( + build_server_url(array('video_page' => $b['pathID'])), + //$b['titoloEpisodio'] ? $b['titoloEpisodio'] : $b['nomeProgramma'], + $tt, + $b['subtitle'], + str_replace("[RESOLUTION]", "480x480", $b['images']['landscape']), + 'object.item.videoitem', + 'http-get:*:video/mp4:*' + ); + } + } + } else { + $items[] = array( + 'id' => build_umsp_url('rai_program', array()), + 'dc:title' => '- ERRORE -', + 'upnp:album_art' => '', + 'upnp:class' => 'object.container', + ); + } + + return $items; + exit; } -function rai_getLink($id) { - $prefix = 'http://mediapolisvod.rai.it/relinker/relinkerServlet.htm?cont='; - $url = $prefix . $id; - $h = get_headers($url, 1); - _logDebug("test: $url > " . $h[0]); - if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { - return rai_createLink(file_get_contents($url)); - } elseif (preg_match('@HTTP\/1\.[01] *302@', $h[0])) { - _logDebug("direct mp4?"); - if (preg_match('@\.mp4$@', $h['Location'])) { - $u = $h['Location']; - $h = get_headers($u); - _logDebug("test: $u > " . $h[0]); - if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { - return $u; - } - } else { - return rai_createLink($h['Location']); - } - } - return null; +function rai_day($ch, $day) +{ + $ch = strtolower($ch); + $ch = str_replace("rai", "rai-", $ch); + + _logDebug(">> $ch > $day"); + $items = array(); + //old $ff = file_get_contents("https://www.raiplay.it/guidatv/index.html?canale=$ch&giorno=$day&new"); + + $ff = file_get_contents("https://www.raiplay.it/palinsesto/guidatv/lista/$ch/$day.html"); + if (preg_match_all("@@", $ff, $lis)) { + foreach ($lis[0] as $li) { + if (preg_match("/data-ora=\"(.+?)\"/", $li, $ora)) { + if (preg_match("/data-img=\"(.+?)\"/", $li, $img)) { + if (preg_match("/data-href=\"(.+?)\"/", $li, $href)) { + if (preg_match("/\"info\">(.+?)<\/[\w\W]+?\"descProgram\">([\s\S]+?)<\/[\w\W]+?\/i>(.+?)<\/[\w\W]+?\"time\">(.+?)<\/[\w\W]+?<\/li>/", $li, $mm)) { + /* + 4 tit 1 + 5 desc + 6 tit 2 + 7 time + */ + + $img = preg_match("/^http/", $img[1])?$img[1]:"https://www.rai.it".$img[1]; + $href = preg_match("/^http/", $href[1])?$href[1]:"https://www.raiplay.it".$href[1]; + $items[] = createPlayItem( + build_server_url(array('video_page' => $href)), + clean_title($ora[1] . ' - ' . $mm[1]), + urlencode(trim($mm[2])), + $img, + 'object.item.videoitem', + 'http-get:*:video/mp4:*' + ); + } else { + _logDebug("skipped."); + } + } + } + } + } + } else { + _logError(__FUNCTION__." day reg-ex not found."); + } + + return $items; } -?> \ No newline at end of file +function rai_config($key = null, $value = null) +{ + if ($key != null) { + putConfigValue($key, $value); + } + + $prefer_hd = getConfigValue('PREFER_HD', 1); + + $Items[] = array( + 'id' => build_umsp_url('config', array('PREFER_HD', !$prefer_hd)), + 'dc:title' => 'HD ' . ($prefer_hd ? 'on' : 'off') . ' - Seleziona per ' . ($prefer_hd ? 'disattivarlo' : 'attivarlo'), + 'upnp:album_art' => 'http://lh4.googleusercontent.com/-hsbvm1bQllg/Tvwgvvk5BnI/AAAAAAAAAFs/DHQp5lKE7-4/s220/HD-icon.png', + 'upnp:class' => 'object.container', + ); + $Items[] = array( + 'id' => build_umsp_url('main_menu'), + 'dc:title' => 'Indietro', + 'upnp:album_art' => 'http://lh3.googleusercontent.com/-dsT4ZvjCth4/TvwihbvNZLI/AAAAAAAAAF0/1Jp9s8dLNlY/s220/back_button_icon.png', + 'upnp:class' => 'object.container', + ); + return $Items; +} + +function rai_createLink($url) +{ + _logDebug("creating link from: $url"); + $phd = getConfigValue('PREFER_HD', 1); + if (preg_match('@relinkerServlet\.htm@', $url)) { + $sc = stream_context_create(array( + 'http' => array( + 'method' => 'GET', + 'header' => 'User-Agent: aria2', + ), + )); + $f = file_get_contents($url, false, $sc, 0, 0); + foreach ($http_response_header as $v) { + if (preg_match("@Location:\s*(.+?)$@", $v, $m)) { + $f = $m[1]; + } + } + preg_match("@akamaihd\.net/i/(.+?)\/(\d{5,7})_([\d,]+)\.mp4@", $f, $m); + for ($i = 1; $i <= 4; $i++) { + $u = "http://creativemedia$i.rai.it/" . $m[1] . "/" . $m[2] . ($phd ? '_1800' : '_800') . ".mp4"; + $h = get_headers($u); + _logDebug("test: $u > " . $h[0]); + if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { + return $u; + } + } + exit; + //DEPERECATED + } elseif (preg_match('@replaytv\/(.+?\/\d{4,8})[\/_]@', $url, $m)) { + for ($i = 1; $i <= 4; $i++) { + $u = "http://creativemedia$i.rai.it/Italy/podcastmhp/replaytv/" . $m[1] . ($phd ? '_1800' : '_800') . ".mp4"; + $h = get_headers($u); + _logDebug("test: $u > " . $h[0]); + if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { + return $u; + } + } + } elseif (preg_match('@replaytv_world\/(.+?\/\d{4,8})[\/_]@', $url, $m)) { + for ($i = 1; $i <= 4; $i++) { + $u = "http://creativemedia$i.rai.it/podcastmhp/replaytv_world/" . $m[1] . ($phd ? '_1800' : '_800') . ".mp4"; + $h = get_headers($u); + _logDebug("test: $u > " . $h[0]); + if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { + return $u; + } + } + } elseif (preg_match('@^(.+?rai\.it)\/(.+?)\/(\d+?)\/(\d+?)\.ism@', $url, $m)) { + for ($i = 1; $i <= 4; $i++) { + $tmp = preg_match("@geoprotetto@i", $m[2]) ? "Italy/" . $m[2] : $m[2]; + $u = preg_replace('@\d@', $i, $m[1]) . "/" . preg_replace('@podcastmhp@', 'podcastcdn', $tmp) . "/" . $m[3] . ($phd ? '_1800' : '_800') . ".mp4"; + $h = get_headers($u); + _logDebug("test: $u > " . $h[0]); + if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { + return $u; + } + } + } else { + _logDebug("***********\r\n UNSUPPORTED LINK: $url\r\n***********"); + } + return null; +} + +function rai_getRelinker($page) +{ + //try json first + $u = str_replace(".html?json", ".json", $page); + $u = str_replace(".html", ".json", $u); + + $ff = file_get_contents($u); + $jj = json_decode($ff, true); + + if (isset($jj['video']['content_url'])) { + if (preg_match("/relinkerServlet\.htm\?cont=(.+?)$/", $jj['video']['content_url'], $mm)) { + return $mm[1]; + } + } + + //get from webpage if json fails + $ff = file_get_contents($page); + if (preg_match("/(data-video-url|videoURL)\s*=\s*\".+?relinkerServlet\.htm\?cont=(.+?)\"/", $ff, $mm)) { + return $mm[2]; + } + return null; +} + +function rai_getLink($id) +{ + $prefix = 'http://mediapolisvod.rai.it/relinker/relinkerServlet.htm?cont='; + $url = $prefix . $id; + $h = get_headers($url, 1); + _logDebug("test: $url > " . $h[0]); + if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { + return rai_createLink(file_get_contents($url)); + } elseif (preg_match('@HTTP\/1\.[01] *302@', $h[0])) { + _logDebug("direct mp4?"); + if (preg_match('@\.mp4$@', $h['Location'])) { + $u = $h['Location']; + preg_match("@_(\d{3,4})\.mp4@", $u, $m); + if (isset($m[1])) { + _logDebug("replacing $m[1] with 1800"); + $u = str_replace("_$m[1].", "_1800.", $u); + } + + $h = get_headers(str_replace(' ', '%20', $u)); + _logDebug("test: $u > " . $h[0]); + if (preg_match('@HTTP\/1\.[01] *200 *OK@', $h[0])) { + return $u; + } elseif (preg_match('@HTTP\/1\.0 504 Gateway Time-out@', $h[0])) { + return rai_createLink($u); + } + } else { + //return rai_createLink($url); + return rai_createLink($h['Location']); + } + } + return null; +} + +if (isset($_GET['video_page'])) { + $page = $_GET['video_page']; + if (preg_match("@studio24|labussola@", $page)) { + $ff = file_get_contents($page); + if (preg_match("@src=\"(.+?\?iframe)\&@", $ff, $mm)) { + $page = $mm[1]; + } + } + $id = null; + if (!preg_match("@relinkerServlet\.htm\?cont\=(.+?Equal)$@", $page, $id)) { + $page = preg_match("@^\/\/@", $page) ? "https:" . $page : $page; + $page = preg_match("@^\/@", $page) ? "https://www.raiplay.it" . $page : $page; + _logDebug("video_page: " . $page); + $id = rai_getRelinker($page); + if ($id == null) { + exit(); + } + } else { + $id = $id[1]; + } + + _logDebug("id: " . $id); + $url = rai_getLink($id); + + _logDebug('playing: ' . $url); + ob_start(); + header('Location: ' . $url); + ob_flush(); + exit(); +}