예제 #1
0
 public static function display_ui_links($object_type, $object_id)
 {
     echo "<ul>";
     echo "<li><a onclick=\"handleShareAction('" . AmpConfig::get('web_path') . "/share.php?action=show_create&type=" . $object_type . "&id=" . $object_id . "')\">" . UI::get_icon('share', T_('Advanced Share')) . " &nbsp;" . T_('Advanced Share') . "</a></li>";
     if (AmpConfig::get('download')) {
         $dllink = "";
         if ($object_type == "song" || $object_type == "video") {
             $dllink = AmpConfig::get('web_path') . "/play/index.php?action=download&type=" . $object_type . "&oid=" . $object_id . "&uid=-1";
         } else {
             if (Access::check_function('batch_download') && check_can_zip($object_type)) {
                 $dllink = AmpConfig::get('web_path') . "/batch.php?action=" . $object_type . "&id=" . $object_id;
             }
         }
         if (!empty($dllink)) {
             if (AmpConfig::get('require_session')) {
                 // Add session information to the link to avoid authentication
                 $dllink .= "&ssid=" . Stream::get_session();
             }
             echo "<li><a rel=\"nohtml\" href=\"" . $dllink . "\">" . UI::get_icon('download', T_('Temporary direct link')) . " &nbsp;" . T_('Temporary direct link') . "</a></li>";
         }
     }
     echo "<li style='padding-top: 8px; text-align: right;'>";
     $plugins = Plugin::get_plugins('external_share');
     foreach ($plugins as $plugin_name) {
         echo "<a onclick=\"handleShareAction('" . AmpConfig::get('web_path') . "/share.php?action=external_share&plugin=" . $plugin_name . "&type=" . $object_type . "&id=" . $object_id . "')\" target=\"_blank\">" . UI::get_icon('share_' . strtolower($plugin_name), $plugin_name) . "</a>&nbsp;";
     }
     echo "</li>";
     echo "</ul>";
 }
    // Hide few UI information on listening mode
    $('.jp-previous').css('visibility', 'hidden');
    $('.jp-play').css('visibility', 'hidden');
    $('.jp-pause').css('visibility', 'hidden');
    $('.jp-next').css('visibility', 'hidden');
    $('.jp-stop').css('visibility', 'hidden');
    $('.jp-toggles').css('visibility', 'hidden');
    $('.jp-playlist').css('visibility', 'hidden');
    $('#broadcast').css('visibility', 'hidden');

    $('.jp-seek-bar').css('pointer-events', 'none');

    brconn.onopen = function(e) {
        sendBroadcastMessage('AUTH_SID', '<?php 
echo Stream::get_session();
?>
');
        sendBroadcastMessage('REGISTER_LISTENER', broadcast_id);
    };
}

function listenBroadcast()
{
    if (brconn != null) {
        stopBroadcast();
    }

    brconn = new WebSocket('<?php 
echo Broadcast_Server::get_address();
?>
예제 #3
0
파일: stream.php 프로젝트: nioc/ampache
            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) || isset($urls)) {
    if ($stream_type != 'democratic') {
        if (!User::stream_control($media_ids)) {
            debug_event('UI::access_denied', 'Stream control failed for user ' . $GLOBALS['user']->username, 3);
            UI::access_denied();
            exit;
        }
    }
    if ($GLOBALS['user']->id > -1) {
        Session::update_username(Stream::get_session(), $GLOBALS['user']->username);
    }
    $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);
}
예제 #4
0
파일: index.php 프로젝트: ivan801/ampache
} else {
    debug_event('play', 'Starting stream of ' . $media->file . ' with size ' . $media->size, 5);
}
if (!isset($_REQUEST['segment'])) {
    if ($media->time) {
        header('X-Content-Duration: ' . $media->time);
    }
    // Stats registering must be done before play. Do not move it.
    // It can be slow because of scrobbler plugins (lastfm, ...)
    if ($start > 0) {
        debug_event('play', 'Content-Range doesn\'t start from 0, stats should already be registered previously; not collecting stats', 5);
    } else {
        if (!$share_id) {
            if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
                debug_event('play', 'Registering stream stats for {' . $media->get_stream_name() . '}...', 5);
                $sessionkey = $sid ?: Stream::get_session();
                $agent = Session::agent($sessionkey);
                $location = Session::get_geolocation($sessionkey);
                $GLOBALS['user']->update_stats($type, $media->id, $agent, $location, isset($_REQUEST['noscrobble']));
            }
        }
    }
}
if ($transcode || $demo_id) {
    header('Accept-Ranges: none');
} else {
    header('Accept-Ranges: bytes');
}
$mime = $media->mime;
if ($transcode && isset($transcoder)) {
    $mime = $media->type_to_mime($transcoder['format']);
예제 #5
0
 /**
  *
  * @param \Ratchet\ConnectionInterface $from
  * @param int $song_id
  */
 protected function notifySong(ConnectionInterface $from, $song_id)
 {
     if ($this->isBroadcaster($from)) {
         $broadcast = $this->broadcasters[$from->resourceId];
         $clients = $this->getListeners($broadcast);
         Session::extend(Stream::get_session(), 'stream');
         $broadcast->update_song($song_id);
         $this->broadcastMessage($clients, self::BROADCAST_SONG, base64_encode($this->getSongJS($song_id)));
         if ($this->verbose) {
             echo "[" . time() . "][info]Broadcast " . $broadcast->id . " now playing song " . $song_id . "." . "\r\n";
         }
     } else {
         debug_event('broadcast', 'Action unauthorized.', '3');
     }
 }
예제 #6
0
 private static function _itemVideo($video, $parent)
 {
     $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false;
     $art_url = Art::url($video->id, 'video', $api_session);
     $fileTypesByExt = self::_getFileTypes();
     $arrFileType = $fileTypesByExt[$video->type];
     return array('id' => $parent . '/' . $video->id, 'parentID' => $parent, 'restricted' => '1', 'dc:title' => self::_replaceSpecialSymbols($video->f_title), 'upnp:class' => isset($arrFileType['class']) ? $arrFileType['class'] : 'object.item.unknownItem', 'upnp:albumArtURI' => $art_url, 'upnp:genre' => Tag::get_display($video->tags, false, 'video'), 'res' => Video::play_url($video->id, '', 'api'), 'protocolInfo' => $arrFileType['mime'], 'size' => $video->size, 'duration' => $video->f_time_h . '.0');
 }
예제 #7
0
 /**
  * media_object_to_url
  */
 public static function media_object_to_url($object, $additional_params = '', $urltype = 'web')
 {
     $surl = null;
     $url = array();
     $type = strtolower(get_class($object));
     $url['type'] = $type;
     // Don't add disabled media objects to the stream playlist
     // Playing a disabled media return a 404 error that could make failed the player (mpd ...)
     if (!isset($object->enabled) || make_bool($object->enabled)) {
         if ($urltype == 'file') {
             $url['url'] = $object->file;
             // Relative path
             if (!empty($additional_params) && strpos($url['url'], $additional_params) === 0) {
                 $url['url'] = substr($url['url'], strlen($additional_params));
                 if (strlen($url['url']) < 1) {
                     return null;
                 }
                 if ($url['url'][0] == DIRECTORY_SEPARATOR) {
                     $url['url'] = substr($url['url'], 1);
                 }
             }
         } else {
             //FIXME: play_url shouldn't be static
             $url['url'] = $type::play_url($object->id, $additional_params);
         }
         $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false;
         // Set a default which can be overridden
         $url['author'] = 'Ampache';
         $url['time'] = $object->time;
         switch ($type) {
             case 'song':
                 $url['title'] = $object->title;
                 $url['author'] = $object->f_artist_full;
                 $url['info_url'] = $object->f_link;
                 $url['image_url'] = Art::url($object->album, 'album', $api_session, AmpConfig::get('ajax_load') ? 3 : 4);
                 $url['album'] = $object->f_album_full;
                 $url['track_num'] = $object->f_track;
                 break;
             case 'video':
                 $url['title'] = 'Video - ' . $object->title;
                 $url['author'] = $object->f_artist_full;
                 $url['resolution'] = $object->f_resolution;
                 break;
             case 'live_stream':
                 $url['title'] = 'Radio - ' . $object->name;
                 if (!empty($object->site_url)) {
                     $url['title'] .= ' (' . $object->site_url . ')';
                 }
                 $url['codec'] = $object->codec;
                 break;
             case 'song_preview':
                 $url['title'] = $object->title;
                 $url['author'] = $object->f_artist_full;
                 break;
             case 'channel':
                 $url['title'] = $object->name;
                 break;
             case 'random':
                 $url['title'] = 'Random URL';
                 break;
             default:
                 $url['title'] = 'URL-Add';
                 $url['time'] = -1;
                 break;
         }
         $surl = new Stream_URL($url);
     }
     return $surl;
 }
예제 #8
0
 /**
  * media_to_urlarray
  * Formats the URL and media information and adds it to the object
  */
 public static function media_to_urlarray($media, $additional_params = '')
 {
     $urls = array();
     foreach ($media as $medium) {
         $url = array();
         if ($medium['custom_play_action']) {
             $additional_params .= "&custom_play_action=" . $medium['custom_play_action'];
         }
         if ($_SESSION['iframe']['subtitle']) {
             $additional_params .= "&subtitle=" . $_SESSION['iframe']['subtitle'];
         }
         $type = $medium['object_type'];
         $object_id = $medium['object_id'];
         $url['type'] = $type;
         $object = new $type($object_id);
         $object->format();
         // Don't add disabled media objects to the stream playlist
         // Playing a disabled media return a 404 error that could make failed the player (mpd ...)
         if (!isset($object->enabled) || make_bool($object->enabled)) {
             //FIXME: play_url shouldn't be static
             $url['url'] = $type::play_url($object->id, $additional_params);
             $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false;
             // Set a default which can be overridden
             $url['author'] = 'Ampache';
             $url['time'] = $object->time;
             switch ($type) {
                 case 'song':
                     $url['title'] = $object->title;
                     $url['author'] = $object->f_artist_full;
                     $url['info_url'] = $object->f_link;
                     $url['image_url'] = Art::url($object->album, 'album', $api_session, AmpConfig::get('ajax_load') ? 3 : 4);
                     $url['album'] = $object->f_album_full;
                     break;
                 case 'video':
                     $url['title'] = 'Video - ' . $object->title;
                     $url['author'] = $object->f_artist_full;
                     $url['resolution'] = $object->f_resolution;
                     break;
                 case 'live_stream':
                     $url['title'] = 'Radio - ' . $object->name;
                     if (!empty($object->site_url)) {
                         $url['title'] .= ' (' . $object->site_url . ')';
                     }
                     $url['codec'] = $object->codec;
                     break;
                 case 'song_preview':
                     $url['title'] = $object->title;
                     $url['author'] = $object->f_artist_full;
                     break;
                 case 'channel':
                     $url['title'] = $object->name;
                     break;
                 case 'random':
                     $url['title'] = 'Random URL';
                     break;
                 default:
                     $url['title'] = 'URL-Add';
                     $url['time'] = -1;
                     break;
             }
             $urls[] = new Stream_URL($url);
         }
     }
     return $urls;
 }
예제 #9
0
 private static function _itemPodcastEpisode($episode, $parent)
 {
     $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false;
     $art_url = Art::url($episode->podcast, 'podcast', $api_session);
     $fileTypesByExt = self::_getFileTypes();
     $arrFileType = !empty($episode->type) ? $fileTypesByExt[$episode->type] : array();
     $ret = array('id' => 'amp://music/podcasts/' . $episode->podcast . '/' . $episode->id, 'parentID' => $parent, 'restricted' => '1', 'dc:title' => self::_replaceSpecialSymbols($episode->f_title), 'upnp:album' => self::_replaceSpecialSymbols($episode->f_podcast), 'upnp:class' => isset($arrFileType['class']) ? $arrFileType['class'] : 'object.item.unknownItem', 'upnp:albumArtURI' => $art_url);
     if (isset($arrFileType['mime'])) {
         $ret['res'] = Podcast_Episode::play_url($episode->id, '', 'api');
         $ret['protocolInfo'] = $arrFileType['mime'];
         $ret['size'] = $episode->size;
         $ret['duration'] = $episode->f_time_h . '.0';
     }
     return $ret;
 }