コード例 #1
0
 /**
  * play_url
  * This function takes all the song information and correctly formats a
  * a stream URL taking into account the downsmapling mojo and everything
  * else, this is the true function
  */
 public static function play_url($oid, $additional_params = '', $player = null, $local = false)
 {
     $song = new Song_Preview($oid);
     $user_id = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1';
     $type = $song->type;
     $song_name = rawurlencode($song->get_artist_name() . " - " . $song->title . "." . $type);
     $url = Stream::get_base_url($local) . "type=song_preview&oid=" . $song->id . "&uid=" . $user_id . "&name=" . $song_name;
     return Stream_URL::format($url . $additional_params);
 }
コード例 #2
0
ファイル: video.class.php プロジェクト: axelsimon/ampache
 /**
  * play_url
  * This returns a "PLAY" url for the video in question here, this currently feels a little
  * like a hack, might need to adjust it in the future
  */
 public static function play_url($oid, $additional_params = '', $sid = '', $force_http = '')
 {
     $video = new Video($oid);
     if (!$video->id) {
         return false;
     }
     $uid = intval($GLOBALS['user']->id);
     $oid = intval($video->id);
     $url = Stream::get_base_url() . "type=video&uid=" . $uid . "&oid=" . $oid;
     return Stream_URL::format($url . $additional_params);
 }
コード例 #3
0
ファイル: catalog.class.php プロジェクト: axelsimon/ampache
 /**
  * playlist_import
  * Attempts to create a Public Playlist based on the playlist file
  */
 public static function import_playlist($playlist)
 {
     $data = file_get_contents($playlist);
     if (substr($playlist, -3, 3) == 'm3u') {
         $files = self::parse_m3u($data);
     } elseif (substr($playlist, -3, 3) == 'pls') {
         $files = self::parse_pls($data);
     } elseif (substr($playlist, -3, 3) == 'asx') {
         $files = self::parse_asx($data);
     } elseif (substr($playlist, -4, 4) == 'xspf') {
         $files = self::parse_xspf($data);
     }
     $songs = array();
     $pinfo = pathinfo($playlist);
     if (isset($files)) {
         foreach ($files as $file) {
             $file = trim($file);
             // Check to see if it's a url from this ampache instance
             if (substr($file, 0, strlen(AmpConfig::get('web_path'))) == AmpConfig::get('web_path')) {
                 $data = Stream_URL::parse($file);
                 $sql = 'SELECT COUNT(*) FROM `song` WHERE `id` = ?';
                 $db_results = Dba::read($sql, array($data['id']));
                 if (Dba::num_rows($db_results)) {
                     $songs[] = $data['id'];
                 }
             } else {
                 // Remove file:// prefix if any
                 if (strpos($file, "file://") !== false) {
                     $file = urldecode(substr($file, 7));
                     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                         // Removing starting / on Windows OS.
                         if (substr($file, 0, 1) == '/') {
                             $file = substr($file, 1);
                         }
                         // Restore real directory separator
                         $file = str_replace("/", DIRECTORY_SEPARATOR, $file);
                     }
                 }
                 debug_event('catalog', 'Add file ' . $file . ' to playlist.', '5');
                 // First, try to found the file as absolute path
                 $sql = "SELECT `id` FROM `song` WHERE `file` = ?";
                 $db_results = Dba::read($sql, array($file));
                 $results = Dba::fetch_assoc($db_results);
                 if (isset($results['id'])) {
                     $songs[] = $results['id'];
                 } else {
                     // Not found in absolute path, create it from relative path
                     $file = $pinfo['dirname'] . DIRECTORY_SEPARATOR . $file;
                     // Normalize the file path. realpath requires the files to exists.
                     $file = realpath($file);
                     if ($file) {
                         $sql = "SELECT `id` FROM `song` WHERE `file` = ?";
                         $db_results = Dba::read($sql, array($file));
                         $results = Dba::fetch_assoc($db_results);
                         if (isset($results['id'])) {
                             $songs[] = $results['id'];
                         }
                     }
                 }
             }
             // if it's a file
         }
     }
     debug_event('import_playlist', "Parsed " . $playlist . ", found " . count($songs) . " songs", 5);
     if (count($songs)) {
         $name = $pinfo['extension'] . " - " . $pinfo['filename'];
         $playlist_id = Playlist::create($name, 'public');
         if (!$playlist_id) {
             return array('success' => false, 'error' => T_('Failed to create playlist.'));
         }
         /* Recreate the Playlist */
         $playlist = new Playlist($playlist_id);
         $playlist->add_songs($songs, true);
         return array('success' => true, 'id' => $playlist_id, 'count' => count($songs));
     }
     return array('success' => false, 'error' => T_('No valid songs found in playlist file.'));
 }
コード例 #4
0
ファイル: upnp.controller.php プロジェクト: bl00m/ampache
 /**
  * status
  * This returns bool/int values for features, loop, repeat and any other features
  * that this localplay method supports.
  * This works as in requesting the upnp properties
  */
 public function status()
 {
     debug_event('upnp', 'status', 5);
     if (!$this->_upnp) {
         return false;
     }
     $item = $this->_upnp->GetCurrentItem();
     $status = array();
     $status['state'] = $this->_upnp->GetState();
     $status['volume'] = $this->_upnp->GetVolume();
     $status['repeat'] = false;
     $status['random'] = false;
     $status['track'] = $item['link'];
     $status['track_title'] = $item['name'];
     $url_data = Stream_URL::parse($item['link']);
     if ($url_data != null) {
         $song = new Song($url_data['id']);
         if ($song != null) {
             $status['track_artist'] = $song->get_artist_name();
             $status['track_album'] = $song->get_album_name();
         }
     }
     return $status;
 }
コード例 #5
0
ファイル: api.class.php プロジェクト: axelsimon/ampache
 /**
  * url_to_song
  *
  * This takes a url and returns the song object in question
  */
 public static function url_to_song($input)
 {
     // Don't scrub, the function needs her raw and juicy
     $data = Stream_URL::parse($input['url']);
     ob_end_clean();
     echo XML_Data::songs(array($data['id']));
 }
コード例 #6
0
ファイル: webplayer.class.php プロジェクト: ivan801/ampache
 /**
  * Get media javascript parameters.
  * @param \playable_item $item
  * @param string $force_type
  * @return string
  */
 public static function get_media_js_param($item, $force_type = '')
 {
     $js = array();
     foreach (array('title', 'author') as $member) {
         if ($member == "author") {
             $kmember = "artist";
         } else {
             $kmember = $member;
         }
         $js[$kmember] = $item->{$member};
     }
     $url = $item->url;
     $types = self::get_types($item, $force_type);
     $media = null;
     $urlinfo = Stream_URL::parse($url);
     $url = $urlinfo['base_url'];
     if ($urlinfo['id'] && Core::is_media($urlinfo['type'])) {
         $media = new $urlinfo['type']($urlinfo['id']);
     } else {
         if ($urlinfo['id'] && $urlinfo['type'] == 'song_preview') {
             $media = new Song_Preview($urlinfo['id']);
         } else {
             if (isset($urlinfo['demo_id'])) {
                 $democratic = new Democratic($urlinfo['demo_id']);
                 if ($democratic->id) {
                     $song_id = $democratic->get_next_object();
                     if ($song_id) {
                         $media = new Song($song_id);
                     }
                 }
             }
         }
     }
     if ($media != null) {
         $media->format();
         if ($urlinfo['type'] == 'song') {
             $js['artist_id'] = $media->artist;
             $js['album_id'] = $media->album;
             $js['replaygain_track_gain'] = $media->replaygain_track_gain;
             $js['replaygain_track_peak'] = $media->replaygain_track_peak;
             $js['replaygain_album_gain'] = $media->replaygain_album_gain;
             $js['replaygain_album_peak'] = $media->replaygain_album_peak;
         }
         $js['media_id'] = $media->id;
         if ($media->type != $types['real']) {
             $url .= '&transcode_to=' . $types['real'];
         }
         //$url .= "&content_length=required";
     }
     $js['filetype'] = $types['player'];
     $js['url'] = $url;
     if ($urlinfo['type'] == 'song') {
         $js['poster'] = $item->image_url;
     }
     debug_event("webplayer.class.php", "Return get_media_js_param {" . json_encode($js) . "}", 5);
     return json_encode($js);
 }
コード例 #7
0
ファイル: democratic.class.php プロジェクト: cheese1/ampache
 /**
  * play_url
  * This returns the special play URL for democratic play, only open to ADMINs
  */
 public function play_url()
 {
     $link = Stream::get_base_url() . 'uid=' . scrub_out($GLOBALS['user']->id) . '&demo_id=' . scrub_out($this->id);
     return Stream_URL::format($link);
 }
コード例 #8
0
 /**
  * create_democratic
  *
  * This 'votes' on the songs; it inserts them into a tmp_playlist with user
  * set to -1.
  */
 public function create_democratic()
 {
     $democratic = Democratic::get_current_playlist();
     $democratic->set_parent();
     $items = array();
     foreach ($this->urls as $url) {
         $data = Stream_URL::parse($url->url);
         $items[] = array($data['type'], $data['id']);
     }
     $democratic->add_vote($items);
 }
コード例 #9
0
 /**
  * create_download
  * This prompts for a download of the song
  */
 private function create_download()
 {
     // There should only be one here...
     if (count($this->urls) != 1) {
         debug_event('stream_playlist', 'Download called, but $urls contains ' . json_encode($this->urls), 2);
     }
     // Header redirect baby!
     $url = current($this->urls);
     $url = Stream_URL::add_options($url->url, '&action=download');
     header('Location: ' . $url);
     exit;
 }
コード例 #10
0
ファイル: song.class.php プロジェクト: nioc/ampache
 /**
  * Generate generic play url.
  * @param string $object_type
  * @param int $object_id
  * @param string $additional_params
  * @param boolean $local
  * @return string
  */
 public static function generic_play_url($object_type, $object_id, $additional_params, $player = null, $local = false)
 {
     $media = new $object_type($object_id);
     if (!$media->id) {
         return null;
     }
     $uid = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1';
     $type = $media->type;
     // Checking if the media is gonna be transcoded into another type
     // Some players doesn't allow a type streamed into another without giving the right extension
     $transcode_cfg = AmpConfig::get('transcode');
     $valid_types = Song::get_stream_types_for_type($type, $player);
     if ($transcode_cfg == 'always' || $transcode_cfg != 'never' && !in_array('native', $valid_types)) {
         $transcode_settings = $media->get_transcode_settings(null);
         if ($transcode_settings) {
             debug_event("media", "Changing play url type from {" . $type . "} to {" . $transcode_settings['format'] . "} due to encoding settings...", 5);
             $type = $transcode_settings['format'];
         }
     }
     $media_name = $media->get_stream_name() . "." . $type;
     $media_name = str_replace("/", "-", $media_name);
     $media_name = str_replace("?", "", $media_name);
     $media_name = str_replace("#", "", $media_name);
     $media_name = rawurlencode($media_name);
     $url = Stream::get_base_url($local) . "type=" . $object_type . "&oid=" . $object_id . "&uid=" . $uid . $additional_params;
     if ($player) {
         $url .= "&player=" . $player;
     }
     $url .= "&name=" . $media_name;
     return Stream_URL::format($url);
 }
コード例 #11
0
ファイル: song.class.php プロジェクト: axelsimon/ampache
 /**
  * play_url
  * This function takes all the song information and correctly formats a
  * a stream URL taking into account the downsmapling mojo and everything
  * else, this is the true function
  */
 public static function play_url($oid, $additional_params = '')
 {
     $song = new Song($oid);
     $user_id = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1';
     $type = $song->type;
     // Checking if the song is gonna be transcoded into another type
     // Some players doesn't allow a type streamed into another without giving the right extension
     $transcode_cfg = AmpConfig::get('transcode');
     $transcode_mode = AmpConfig::get('transcode_' . $type);
     if ($transcode_cfg == 'always' || $transcode_cfg != 'never' && $transcode_mode == 'required') {
         $transcode_settings = $song->get_transcode_settings(null);
         if ($transcode_settings) {
             debug_event("song.class.php", "Changing play url type from {" . $type . "} to {" . $transcode_settings['format'] . "} due to encoding settings...", 5);
             $type = $transcode_settings['format'];
         }
     }
     $song_name = $song->get_artist_name() . " - " . $song->title . "." . $type;
     $song_name = str_replace("/", "-", $song_name);
     $song_name = str_replace("?", "", $song_name);
     $song_name = str_replace("#", "", $song_name);
     $song_name = rawurlencode($song_name);
     $url = Stream::get_base_url() . "type=song&oid=" . $song->id . "&uid=" . $user_id . $additional_params . "&name=" . $song_name;
     return Stream_URL::format($url);
 }