Example #1
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 #2
0
 /**
  * hls
  * Create an HLS playlist.
  * Takes the file id in parameter with optional max bit rate.
  */
 public static function hls($input)
 {
     self::check_version($input, "1.7.0", true);
     $fileid = self::check_parameter($input, 'id', true);
     $bitRate = $input['bitRate'];
     $media = array();
     $media['object_type'] = 'song';
     $media['object_id'] = Subsonic_XML_Data::getAmpacheId($fileid);
     $medias = array();
     $medias[] = $media;
     $stream = new Stream_Playlist();
     $additional_params = '';
     if ($bitRate) {
         $additional_params .= '&bitrate=' . $bitRate;
     }
     //$additional_params .= '&transcode_to=ts';
     $stream->add($medias, $additional_params);
     header('Content-Type: application/vnd.apple.mpegurl;');
     $stream->create_m3u();
 }
Example #3
0
 public function create_fake_playlist()
 {
     $playlist = new Stream_Playlist(-1);
     $medias = array();
     switch ($this->object_type) {
         case 'album':
         case 'playlist':
             $object = new $this->object_type($this->object_id);
             $songs = $object->get_medias('song');
             foreach ($songs as $song) {
                 $medias[] = $song;
             }
             break;
         default:
             $medias[] = array('object_type' => $this->object_type, 'object_id' => $this->object_id);
             break;
     }
     $playlist->add($medias, '&share_id=' . $this->id . '&share_secret=' . $this->secret);
     return $playlist;
 }
Example #4
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 #5
0
 /**
  * hls
  * Create an HLS playlist.
  * Takes the file id in parameter with optional max bit rate.
  */
 public static function hls($input)
 {
     self::check_version($input, "1.7.0", true);
     $fileid = self::check_parameter($input, 'id', true);
     $bitRate = $input['bitRate'];
     // Not supported.
     $media = array();
     $media['object_type'] = 'song';
     $media['object_id'] = Subsonic_XML_Data::getAmpacheId($fileid);
     $medias = array();
     $medias[] = $media;
     $stream = new Stream_Playlist();
     $stream->add($medias);
     header('Content-Type: application/vnd.apple.mpegurl;');
     $stream->create_m3u();
 }