Example #1
0
 private static function video_transcode($params)
 {
     $n = count($params);
     if ($n == 2) {
         $transcode_to = $params[0];
         $action = $params[1];
         $id = '';
         $path = $_GET['path'];
         $protocol = $_GET['protocol'];
         $offset = $_GET['offset'];
         // Transcode arguments.
         $videoQuality = $_GET['videoQuality'];
         $videoResolution = $_GET['videoResolution'];
         $maxVideoBitrate = $_GET['maxVideoBitrate'];
         $subtitleSize = $_GET['subtitleSize'];
         $audioBoost = $_GET['audioBoost'];
         $additional_params = '&vsettings=';
         if ($videoResolution) {
             $additional_params .= 'resolution-' . $videoResolution . '-';
         }
         if ($maxVideoBitrate) {
             $additional_params .= 'maxbitrate-' . $maxVideoBitrate . '-';
         }
         if ($videoQuality) {
             $additional_params .= 'quality-' . $videoQuality . '-';
         }
         if ($offset) {
             $additional_params .= '&frame=' . $offset;
         }
         // Several Media and Part per Video is not supported
         //$mediaIndex = $_GET['mediaIndex'];
         //$partIndex = $_GET['partIndex'];
         // What's that?
         //$fastSeek = $_GET['fastSeek'];
         //$directPlay = $_GET['directPlay'];
         //$directStream = $_GET['directStream'];
         $uriroot = '/library/metadata/';
         $upos = strrpos($path, $uriroot);
         if ($upos !== false) {
             $id = substr($path, $upos + strlen($uriroot));
         }
         $session = $_GET['session'];
         if ($action == "stop") {
             // We should kill associated transcode session here
         } elseif (strpos($action, "start") === 0) {
             if (empty($protocol) || $protocol == "hls") {
                 header('Content-Type: application/vnd.apple.mpegurl');
                 $videoResolution = $_GET['videoResolution'];
                 $maxVideoBitrate = $_GET['maxVideoBitrate'];
                 if (!$maxVideoBitrate) {
                     $maxVideoBitrate = 8175;
                 }
                 echo "#EXTM3U\n";
                 echo "#EXT-X-STREAM-INF:PROGRAM-ID=1";
                 if ($maxVideoBitrate) {
                     echo ",BANDWIDTH=" . $maxVideoBitrate * 1000;
                 }
                 if ($videoResolution) {
                     echo ",RESOLUTION=" . $videoResolution;
                 }
                 echo "\n";
                 echo "hls.m3u8?" . substr($_SERVER['QUERY_STRING'], strpos($_SERVER['QUERY_STRING'], '&') + 1);
             } elseif ($protocol == "http") {
                 $url = null;
                 if ($transcode_to == 'universal') {
                     $additional_params .= '&transcode_to=webm';
                     if (AmpConfig::get('encode_args_webm')) {
                         debug_event('plex', 'Universal transcoder requested but `webm` transcode settings not configured. This will probably failed.', 3);
                     }
                 }
                 if ($id) {
                     if (Plex_XML_Data::isSong($id)) {
                         $url = Song::play_url(Plex_XML_Data::getAmpacheId($id), $additional_params, 'api');
                     } elseif (Plex_XML_Data::isVideo($id)) {
                         $url = Video::play_url(Plex_XML_Data::getAmpacheId($id), $additional_params, 'api');
                     }
                     if ($url) {
                         self::stream_url($url);
                     }
                 }
             }
         } elseif ($action == "hls.m3u8") {
             if ($id) {
                 $pl = new Stream_Playlist();
                 $media = null;
                 if (Plex_XML_Data::isSong($id)) {
                     $media = array('object_type' => 'song', 'object_id' => Plex_XML_Data::getAmpacheId($id));
                 } elseif (Plex_XML_Data::isVideo($id)) {
                     $media = array('object_type' => 'video', 'object_id' => Plex_XML_Data::getAmpacheId($id));
                 }
                 if ($media != null) {
                     $pl->add(array($media), $additional_params);
                 }
                 $pl->generate_playlist('hls');
             }
         }
     }
 }
Example #2
0
// end action switch
// See if we need a special streamtype
switch ($_REQUEST['action']) {
    case 'download':
        $stream_type = 'download';
        break;
    case 'democratic':
        // Don't let them loop it
        // FIXME: This looks hacky
        if (AmpConfig::get('play_type') == 'democratic') {
            AmpConfig::set('play_type', 'stream', true);
        }
    default:
        $stream_type = AmpConfig::get('play_type');
        if ($stream_type == 'stream') {
            $stream_type = AmpConfig::get('playlist_type');
        }
        break;
}
debug_event('stream.php', 'Stream Type: ' . $stream_type . ' Media IDs: ' . json_encode($media_ids), 5);
if (count(media_ids)) {
    $playlist = new Stream_Playlist();
    $playlist->add($media_ids);
    if (isset($urls)) {
        $playlist->add_urls($urls);
    }
    // Depending on the stream type, will either generate a redirect or actually do the streaming.
    $playlist->generate_playlist($stream_type, true);
} else {
    debug_event('stream.php', 'No item. Ignoring...', 5);
}
Example #3
0
    if (!Access::check_network('stream', $GLOBALS['user']->id, '25') and !Access::check_network('network', $GLOBALS['user']->id, '25')) {
        debug_event('UI::access_denied', "Streaming Access Denied: " . $_SERVER['REMOTE_ADDR'] . " does not have stream level access", '3');
        UI::access_denied();
        exit;
    }
}
// access_control is enabled
// Handle playlist downloads
if ($type == 'playlist' && isset($playlist_type)) {
    $playlist = new Stream_Playlist($oid);
    // Some rudimentary security
    if ($uid != $playlist->user) {
        UI::access_denied();
        exit;
    }
    $playlist->generate_playlist($playlist_type, false);
    exit;
}
/**
 * If we've got a tmp playlist then get the
 * current song, and do any other crazyness
 * we need to
 */
if ($demo_id) {
    $democratic = new Democratic($demo_id);
    $democratic->set_parent();
    // If there is a cooldown we need to make sure this song isn't a repeat
    if (!$democratic->cooldown) {
        /* This takes into account votes etc and removes the */
        $oid = $democratic->get_next_object();
    } else {