Beispiel #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);
}
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
?>
<td class="cel_play">
    <span class="cel_play_content">&nbsp;</span>
    <div class="cel_play_hover">
    <?php 
if (AmpConfig::get('directplay')) {
    ?>
        <?php 
    echo Ajax::button('?page=stream&action=directplay&playtype=artist&artist_id=' . $artist->id, 'play', T_('Play'), 'play_artist_' . $artist->id);
    ?>
        <?php 
    if (Stream_Playlist::check_autoplay_append()) {
        ?>
            <?php 
        echo Ajax::button('?page=stream&action=directplay&playtype=artist&artist_id=' . $artist->id . '&append=true', 'play_add', T_('Play last'), 'addplay_artist_' . $artist->id);
        ?>
        <?php 
    }
}
?>
    </div>
</td>
<td class="cel_artist"><?php 
echo $artist->f_name_link;
?>
</td>
<td class="cel_add">
 /**
  * display_home
  * This display the module in home page
  */
 public function display_home()
 {
     if (AmpConfig::get('userflags')) {
         $userflags = Userflag::get_latest(null, -1, $this->maxitems);
         $i = 0;
         echo '<div class="home_plugin"><table class="tabledata">';
         foreach ($userflags as $userflag) {
             $item = new $userflag['type']($userflag['id']);
             $item->format();
             $user = new User($userflag['user']);
             $user->format();
             if ($item->id) {
                 echo '<tr class="' . ($i % 2 == 0 ? 'even' : 'odd') . '"><td>';
                 echo '<div>';
                 echo '<div style="float: left;">';
                 echo '<span style="font-weight: bold;">' . $item->f_link . '</span> ';
                 echo '<span style="margin-right: 10px;">';
                 if (AmpConfig::get('directplay')) {
                     echo Ajax::button('?page=stream&action=directplay&object_type=' . $userflag['type'] . '&object_id=' . $userflag['id'], 'play', T_('Play'), 'play_' . $userflag['type'] . '_' . $userflag['id']);
                     if (Stream_Playlist::check_autoplay_append()) {
                         echo Ajax::button('?page=stream&action=directplay&object_type=' . $userflag['type'] . '&object_id=' . $userflag['id'] . '&append=true', 'play_add', T_('Play last'), 'addplay_' . $userflag['type'] . '_' . $userflag['id']);
                     }
                 }
                 echo Ajax::button('?action=basket&type=' . $userflag['type'] . '&id=' . $userflag['id'], 'add', T_('Add to temporary playlist'), 'play_full_' . $userflag['id']);
                 echo '</span>';
                 echo '</div>';
                 echo '<div style="float: right; opacity: 0.5;">' . T_('recommended by') . ' ' . $user->f_link . '</div>';
                 echo '</div><br />';
                 echo '<div style="margin-left: 30px;">';
                 echo '<div style="float: left; margin-right: 20px;">';
                 $thumb = UI::is_grid_view('album') ? 2 : 11;
                 $item->display_art($thumb);
                 echo '</div>';
                 echo '<div style="white-space: normal;">' . $item->get_description() . '</div>';
                 echo '</div>';
                 echo '</td></tr>';
                 $i++;
             }
         }
         echo '</table></div>';
     }
 }
 if (AmpConfig::get('directplay')) {
     ?>
             <?php 
     echo Ajax::button('?page=stream&action=directplay&object_type=song&object_id=' . $song->id, 'play', T_('Play'), 'play_song_' . $nb . '_' . $song->id);
     ?>
             <?php 
     if (Stream_Playlist::check_autoplay_append()) {
         ?>
                 <?php 
         echo Ajax::button('?page=stream&action=directplay&object_type=song&object_id=' . $song->id . '&append=true', 'play_add', T_('Play last'), 'addplay_song_' . $nb . '_' . $song->id);
         ?>
             <?php 
     }
     ?>
             <?php 
     if (Stream_Playlist::check_autoplay_next()) {
         ?>
                 <?php 
         echo Ajax::button('?page=stream&action=directplay&object_type=song&object_id=' . $song->id . '&playnext=true', 'play_next', T_('Play next'), 'nextplay_song_' . $nb . '_' . $song->id);
         ?>
             <?php 
     }
     ?>
     <?php 
 }
 ?>
         </div>
     </td>
     <td class="cel_song"><?php 
 echo $song->f_link;
 ?>
Beispiel #5
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');
             }
         }
     }
 }
Beispiel #6
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();
 }
 protected function getSongJS($song_id)
 {
     $media = array();
     $media[] = array('object_type' => 'song', 'object_id' => $song_id);
     $item = Stream_Playlist::media_to_urlarray($media);
     return WebPlayer::get_media_js_param($item[0]);
 }
Beispiel #8
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;
 }
 /**
  * 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();
 }
Beispiel #10
0
}
/*
   If they are using access lists let's make sure
   that they have enough access to play this mojo
*/
if (AmpConfig::get('access_control')) {
    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);
Beispiel #11
0
 /**
  * gc
  *
  * This function is randomly called and it cleans up the spoo
  */
 public static function gc()
 {
     $sql = 'DELETE FROM `session` WHERE `expire` < ?';
     Dba::write($sql, array(time()));
     // Also clean up things that use sessions as keys
     Query::gc();
     Tmp_Playlist::gc();
     Stream_Playlist::gc();
     Song_Preview::gc();
     return true;
 }