function displayNowPlaying($baseurl = "")
{
    global $xbmcimgpath;
    if (!empty($_GET['style']) && $_GET['style'] == 'm' && !empty($_GET['cmd'])) {
        processCommand($_GET['cmd']);
    }
    echo "<div id=\"nowplaying\">\n";
    //json rpc call procedure
    $results = jsonmethodcall("Player.GetActivePlayers");
    //video Player
    if ($results['result']['video'] == 1) {
        $jsonVersion = jsonmethodcall("JSONRPC.Version");
        //pull the JSON version # from XBMC
        //get playlist items
        if ($jsonVersion['result']['version'] == '2') {
            // For the old version
            $results = jsonmethodcall("VideoPlaylist.GetItems");
            //Pull the current "playlist"
            if (!empty($results['result']['items'])) {
                $items = $results['result']['items'][0];
            }
            //If there's anything there, get the current item
            //The older interface doesn't explicitly return a "type"
            if (isset($items['episode'])) {
                if (!empty($items['showtitle'])) {
                    $line1 = $items['showtitle'];
                }
                if (!empty($items['season'])) {
                    $line1 = $line1 . " - S" . sprintf("%02d", $items['season']);
                }
                if (empty($items['season'])) {
                    $line1 = $line1 . " - S00";
                }
                if (!empty($items['episode'])) {
                    $line1 = $line1 . "E" . sprintf("%02d", $items['episode']);
                }
                if (!empty($items['title'])) {
                    $line2 = '"' . $items['title'] . '"';
                }
                if (empty($items['plot'])) {
                    $line3 = "Plot Summary Unavailable";
                    $plot = "Plot Summary Unavailable";
                }
                if (!empty($items['plot'])) {
                    $line3 = $items['plot'];
                    $plot = $items['plot'];
                }
            }
            if (!isset($items['episode'])) {
                if (!empty($items['title'])) {
                    $line1 = $items['title'];
                }
                if (!empty($items['year'])) {
                    $line1 = $line1 . ' (' . $items['year'] . ')';
                }
                if (!empty($items['director'])) {
                    $line1 = $line1 . " | Directed by " . $items['director'];
                }
                if (empty($line1)) {
                    // In this lame case, we can fall back to the file name
                    $line1 = substr($items['file'], strrpos($items['file'], '/'));
                }
                $line2 = '';
                // set this variable so that PHP won't error if it remains unset
                if (!empty($items['tagline'])) {
                    $line2 = $items['tagline'];
                }
                if (empty($items['plot'])) {
                    $line3 = "Plot Summary Unavailable";
                    $plot = "Plot Summary Unavailable";
                }
                if (!empty($items['plot'])) {
                    $line3 = $items['plot'];
                    $plot = $items['plot'];
                }
            }
        }
        if ($jsonVersion['result']['version'] == '3') {
            $results = jsonmethodcall("VideoPlaylistV3.GetItems");
            //Pull the current "playlist"
            if (!empty($results['result']['items'])) {
                $items = $results['result']['items'][0];
            }
            //If there's anything there, get the current item
            if ($items['type'] == 'episode') {
                //its a TV show!
                if (!empty($items['showtitle'])) {
                    $line1 = $items['showtitle'];
                }
                if (!empty($items['season'])) {
                    $line1 = $line1 . " - S" . sprintf("%02d", $items['season']);
                }
                if (!empty($items['episode'])) {
                    $line1 = $line1 . "E" . sprintf("%02d", $items['episode']);
                }
                if (!empty($items['title'])) {
                    $line2 = '"' . $items['title'] . '"';
                }
                if (empty($items['plot'])) {
                    $line3 = "Plot Summary Unavailable";
                    $plot = "Plot Summary Unavailable";
                }
                if (!empty($items['plot'])) {
                    $line3 = $items['plot'];
                    $plot = $items['plot'];
                }
            } else {
                if ($items['type'] == 'movie') {
                    //it's a movie
                    if (!empty($items['title'])) {
                        $line1 = $items['title'];
                    }
                    if (!empty($items['year'])) {
                        $line1 = $line1 . ' (' . $items['year'] . ')';
                    }
                    if (!empty($items['director'])) {
                        $line1 = $line1 . " | Directed by " . $items['director'];
                    }
                    if (!empty($items['tagline'])) {
                        $line2 = $items['tagline'];
                    }
                    if (empty($items['plot'])) {
                        $line3 = "Plot Summary Unavailable";
                        $plot = "Plot Summary Unavailable";
                    }
                    if (!empty($items['plot'])) {
                        $line3 = $items['plot'];
                        $plot = $items['plot'];
                    }
                }
            }
        }
        if (!empty($items['thumbnail'])) {
            $thumb = $items['thumbnail'];
        } else {
            if (!empty($items['fanart'])) {
                $thumb = $items['fanart'];
            }
        }
        if (strlen($thumb) > 0) {
            echo "\t<div id=\"thumbblock\" class=\"thumbblockvideo\">\n";
            if (!empty($baseurl)) {
                echo "\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" alt=\"" . htmlentities($plot, ENT_QUOTES) . "\" />";
            } else {
                echo "\t\t <b>" . $line1 . "</b><a href=\"" . $xbmcimgpath . $thumb . "\" class=\"highslide\" onclick=\"return hs.expand(this)\">\n";
                echo "\t\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" title=\"Click to enlarge\" alt=\"" . htmlentities($plot, ENT_QUOTES) . "\" />";
                echo "\t\t</a>\n";
            }
            echo "\t</div>\n";
        }
        echo "\t\t<p><i>" . $line2 . "</i></p>\n";
        echo "\t\t<p>" . $line3 . "</p>\n";
        //progress time
        $results = jsonmethodcall("VideoPlayer.GetTime");
        $time = $results['result']['time'];
        // Current time (in seconds)
        $total = $results['result']['total'];
        // Total time (in seconds)
        $timeFormatted = '';
        //Instantiate the "timeFormatted" variable so we don't get errors
        //The way time is formatted and returned is different in the old and new JSON interfaces, so we fork here to handle each case.
        if ($jsonVersion['result']['version'] == '2') {
            $timeFormatted = formattimes($time, $total);
            echo "{$timeFormatted}</p>\n";
        }
        if ($jsonVersion['result']['version'] == '3') {
            if ($time['hours'] != 0) {
                $timeFormatted = $time['hours'] . ":";
            }
            //If there's actually any "hours" value, we format and add them to the string
            $timeFormatted = "\t\t<p>" . $timeFormatted . sprintf("%02d", $time['minutes']) . ':' . sprintf("%02d", $time['seconds']) . ' / ';
            if ($total['hours'] != 0) {
                $timeFormatted = $timeFormatted . $total['hours'] . ":";
            }
            $timeFormatted = $timeFormatted . sprintf("%02d", $total['minutes']) . ":" . sprintf("%02d", $total['seconds']);
            echo "{$timeFormatted}</p>\n";
        }
        if (!empty($results['result']['paused']) && $results['result']['paused']) {
            echo "\t\t<p>Paused</p>\n";
        }
        //progress bar
        $results = jsonmethodcall("VideoPlayer.GetPercentage");
        $percentage = $results['result'];
        echo "\t\t<div class='progressbar'><div class='progress' style='width:" . $percentage . "%'></div></div>";
        if (!empty($_GET['style']) && $_GET['style'] == 'm') {
            widgetNowPlayingControls($baseurl);
        }
    } elseif ($results['result']['audio'] == 1) {
        //get playlist items
        $results = jsonmethodcall("AudioPlaylist.GetItems");
        $items = $results['result']['items'];
        $current = $results['result']['current'];
        $thumb = $items[$current]['thumbnail'];
        $artist = $items[$current]['artist'];
        $title = $items[$current]['title'];
        $album = $items[$current]['album'];
        if (strlen($thumb) > 0) {
            echo "\t<div id=\"thumbblock\" class=\"thumbblockaudio\">\n";
            if (!empty($baseurl)) {
                echo "\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" alt=\"" . htmlentities($artist . " - " . $album . " - " . $title, ENT_QUOTES) . "\" />";
            } else {
                echo "\t\t<a href=\"" . $xbmcimgpath . $thumb . "\" class=\"highslide\" onclick=\"return hs.expand(this)\">\n";
                echo "\t\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" title=\"Click to enlarge\" alt=\"" . htmlentities($artist . " - " . $album . " - " . $title, ENT_QUOTES) . "\" />";
                echo "\t\t</a>\n";
            }
            echo "\t</div>\n";
        }
        echo "\t<p>" . $artist . "</p>\n";
        echo "\t<p>" . $title . "</p>\n";
        echo "\t<p>" . $album . "</p>\n";
        //progress time
        $results = jsonmethodcall("AudioPlayer.GetTime");
        $time = $results['result']['time'];
        $total = $results['result']['total'];
        echo "\t<p>" . formattimes($time, $total) . "</p>\n";
        if ($results['result']['paused']) {
            echo "\t<p>Paused</p>\n";
        }
        echo "</div>\n";
        //progress bar
        $results = jsonmethodcall("AudioPlayer.GetPercentage");
        $percentage = $results['result'];
        echo "<div class=\"progressbar\"><div class=\"progress\" style=\"width:" . $percentage . "%\"></div></div>\n";
        if (!empty($_GET['style']) && $_GET['style'] == 'm') {
            widgetNowPlayingControls($baseurl);
        }
    } else {
        echo "\t<p>Nothing Playing</p>\n";
    }
    echo "</div>\n";
}
示例#2
0
function displayNowPlaying($baseurl = "")
{
    global $xbmcimgpath;
    if (!empty($_GET['style']) && $_GET['style'] == 'm' && !empty($_GET['cmd'])) {
        processCommand($_GET['cmd']);
    }
    echo "<div id=\"nowplaying\">\n";
    //json rpc call procedure
    $results = jsonmethodcall("Player.GetActivePlayers");
    //video Player
    if ($results['result']['video'] == 1) {
        //get playlist items
        $results = jsonmethodcall("VideoPlaylist.GetItems");
        if (!empty($results['result']['items'])) {
            $items = $results['result']['items'];
            $current = !empty($results['result']['current']) ? $results['result']['current'] : 0;
            if (!empty($items[$current]['thumbnail'])) {
                $thumb = $items[$current]['thumbnail'];
            } else {
                $thumb = !empty($items[$current]['fanart']) ? $items[$current]['fanart'] : "";
            }
            if (!empty($items[$current]['title'])) {
                $title = $items[$current]['title'];
            } else {
                $title = !empty($items[$current]['label']) ? $items[$current]['label'] : "";
            }
            if (!empty($items[$current]['showtitle'])) {
                $show = $items[$current]['showtitle'];
            } else {
                $show = $title;
                $title = "";
            }
            $season = !empty($items[$current]['season']) ? $items[$current]['season'] : "";
            $episode = !empty($items[$current]['episode']) ? $items[$current]['episode'] : "";
            if (strlen($season) > 0 && strlen($episode) > 0) {
                $title = $season . "x" . str_pad($episode, 2, '0', STR_PAD_LEFT) . " " . $title;
            }
            if (strlen($show) == 0) {
                $info = pathinfo($items[$current]['file']);
                $show = $info['filename'];
            }
            if (!empty($items[$current]['plot'])) {
                $plot = $items[$current]['plot'];
            } else {
                $plot = "";
            }
            if (strlen($thumb) > 0) {
                echo "\t<div id=\"thumbblock\" class=\"thumbblockvideo\">\n";
                if (!empty($baseurl)) {
                    echo "\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" alt=\"" . htmlentities($plot, ENT_QUOTES) . "\" />";
                } else {
                    echo "\t\t<a href=\"" . $xbmcimgpath . $thumb . "\" class=\"highslide\" onclick=\"return hs.expand(this)\">\n";
                    echo "\t\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" title=\"Click to enlarge\" alt=\"" . htmlentities($plot, ENT_QUOTES) . "\" />";
                    echo "\t\t</a>\n";
                }
                echo "\t</div>\n";
            }
            echo "\t\t<p>" . $show . "</p>\n";
            echo "\t\t<p>" . $title . "</p>\n";
        }
        //progress time
        $results = jsonmethodcall("VideoPlayer.GetTime");
        $time = $results['result']['time'];
        $total = $results['result']['total'];
        echo "\t\t<p>" . formattimes($time, $total) . "</p>\n";
        if (!empty($results['result']['paused']) && $results['result']['paused']) {
            echo "\t\t<p>Paused</p>\n";
        }
        //progress bar
        $results = jsonmethodcall("VideoPlayer.GetPercentage");
        $percentage = $results['result'];
        echo "\t\t<div class='progressbar'><div class='progress' style='width:" . $percentage . "%'></div></div>";
        if (!empty($_GET['style']) && $_GET['style'] == 'm') {
            widgetNowPlayingControls($baseurl);
        }
    } elseif ($results['result']['audio'] == 1) {
        //get playlist items
        $results = jsonmethodcall("AudioPlaylist.GetItems");
        $items = $results['result']['items'];
        $current = $results['result']['current'];
        $thumb = $items[$current]['thumbnail'];
        $artist = $items[$current]['artist'];
        $title = $items[$current]['title'];
        $album = $items[$current]['album'];
        if (strlen($thumb) > 0) {
            echo "\t<div id=\"thumbblock\" class=\"thumbblockaudio\">\n";
            if (!empty($baseurl)) {
                echo "\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" alt=\"" . htmlentities($artist . " - " . $album . " - " . $title, ENT_QUOTES) . "\" />";
            } else {
                echo "\t\t<a href=\"" . $xbmcimgpath . $thumb . "\" class=\"highslide\" onclick=\"return hs.expand(this)\">\n";
                echo "\t\t\t<img src=\"" . $xbmcimgpath . $thumb . "\" title=\"Click to enlarge\" alt=\"" . htmlentities($artist . " - " . $album . " - " . $title, ENT_QUOTES) . "\" />";
                echo "\t\t</a>\n";
            }
            echo "\t</div>\n";
        }
        echo "\t<p>" . $artist . "</p>\n";
        echo "\t<p>" . $title . "</p>\n";
        echo "\t<p>" . $album . "</p>\n";
        //progress time
        $results = jsonmethodcall("AudioPlayer.GetTime");
        $time = $results['result']['time'];
        $total = $results['result']['total'];
        echo "\t<p>" . formattimes($time, $total) . "</p>\n";
        if ($results['result']['paused']) {
            echo "\t<p>Paused</p>\n";
        }
        echo "</div>\n";
        //progress bar
        $results = jsonmethodcall("AudioPlayer.GetPercentage");
        $percentage = $results['result'];
        echo "<div class=\"progressbar\"><div class=\"progress\" style=\"width:" . $percentage . "%\"></div></div>\n";
        if (!empty($_GET['style']) && $_GET['style'] == 'm') {
            widgetNowPlayingControls($baseurl);
        }
    } else {
        echo "\t<p>Nothing Playing</p>\n";
    }
    echo "</div>\n";
}