예제 #1
0
 protected static function get_types($item, $force_type = '')
 {
     $types = array('real' => 'mp3', 'player' => '');
     $browsers = array_keys(self::browser_info());
     $browser = '';
     if (count($browsers) > 0) {
         $browser = $browsers[0];
     }
     if (!empty($force_type)) {
         debug_event("webplayer.class.php", "Forcing type to {" . $force_type . "}", 5);
         $types['real'] = $force_type;
     } else {
         if ($browser == "msie" || $browser == "trident" || $browser == "webkit" || $browser == "safari") {
             $types['real'] = "mp3";
         } else {
             $types['real'] = "ogg";
         }
     }
     $song = null;
     $urlinfo = Stream_URL::parse($item->url);
     if ($urlinfo['id'] && $urlinfo['type'] == 'song') {
         $song = new Song($urlinfo['id']);
     } else {
         if ($urlinfo['id'] && $urlinfo['type'] == 'song_preview') {
             $song = 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) {
                         $song = new Song($song_id);
                     }
                 }
             }
         }
     }
     if ($song != null) {
         $ftype = $song->type;
         $transcode = false;
         $transcode_cfg = AmpConfig::get('transcode');
         // Check transcode is required
         $ftype_transcode = AmpConfig::get('transcode_' . $ftype);
         $valid_types = Song::get_stream_types_for_type($ftype);
         if ($transcode_cfg == 'always' || !empty($force_type) || $ftype_transcode == 'required' || $types['real'] != $ftype && !AmpConfig::get('webplayer_flash')) {
             if ($transcode_cfg == 'always' || $transcode_cfg != 'never' && in_array('transcode', $valid_types)) {
                 // Transcode only if excepted type available
                 $transcode_settings = $song->get_transcode_settings($types['real']);
                 if ($transcode_settings && AmpConfig::get('transcode_player_customize')) {
                     $transcode = true;
                 } else {
                     if (!in_array('native', $valid_types)) {
                         $transcode_settings = $song->get_transcode_settings(null);
                         if ($transcode_settings) {
                             $types['real'] = $transcode_settings['format'];
                             $transcode = true;
                         }
                     }
                 }
             }
         }
         if (!$transcode) {
             $types['real'] = $ftype;
         }
         if ($types['real'] == "flac" || $types['real'] == "ogg") {
             $types['player'] = "oga";
         } else {
             if ($types['real'] == "mp4") {
                 $types['player'] = "m4a";
             }
         }
     } else {
         if ($urlinfo['id'] && $urlinfo['type'] == 'video') {
             $video = new Video($urlinfo['id']);
             $types['real'] = pathinfo($video->file, PATHINFO_EXTENSION);
             if ($types['real'] == "ogg") {
                 $types['player'] = "ogv";
             } else {
                 if ($types['real'] == "webm") {
                     $types['player'] = "webmv";
                 } else {
                     if ($types['real'] == "mp4") {
                         $types['player'] = "m4v";
                     }
                 }
             }
         } else {
             if ($item->type == 'radio') {
                 $types['real'] = $item->codec;
                 if ($types['real'] == "flac" || $types['real'] == "ogg") {
                     $types['player'] = "oga";
                 }
             } else {
                 $ext = pathinfo($item->url, PATHINFO_EXTENSION);
                 if (!empty($ext)) {
                     $types['real'] = $ext;
                 }
             }
         }
     }
     if (empty($types['player'])) {
         $types['player'] = $types['real'];
     }
     debug_event("webplayer.class.php", "Types {" . json_encode($types) . "}", 5);
     return $types;
 }
예제 #2
0
 /**
  * Get types information for an item.
  * @param \playable_item $item
  * @param string $force_type
  * @return array
  */
 protected static function get_types($item, $force_type = '')
 {
     $types = array('real' => 'mp3', 'player' => '');
     $media = null;
     $urlinfo = Stream_URL::parse($item->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) {
         $ftype = $media->type;
         $transcode = false;
         $transcode_cfg = AmpConfig::get('transcode');
         // Check transcode is required
         $valid_types = Song::get_stream_types_for_type($ftype, 'webplayer');
         if ($transcode_cfg == 'always' || !empty($force_type) || !in_array('native', $valid_types) || $types['real'] != $ftype && (!AmpConfig::get('webplayer_flash') || $urlinfo['type'] != 'song')) {
             if ($transcode_cfg == 'always' || $transcode_cfg != 'never' && in_array('transcode', $valid_types)) {
                 // Transcode forced from client side
                 if (!empty($force_type) && AmpConfig::get('transcode_player_customize')) {
                     debug_event("webplayer.class.php", "Forcing type to {" . $force_type . "}", 5);
                     // Transcode only if excepted type available
                     $transcode_settings = $media->get_transcode_settings($force_type, 'webplayer');
                     if ($transcode_settings) {
                         $types['real'] = $transcode_settings['format'];
                         $transcode = true;
                     }
                 }
                 // Transcode is not forced, transcode only if required
                 if (!$transcode) {
                     if (!in_array('native', $valid_types)) {
                         $transcode_settings = $media->get_transcode_settings(null, 'webplayer');
                         if ($transcode_settings) {
                             $types['real'] = $transcode_settings['format'];
                             $transcode = true;
                         }
                     }
                 }
             }
         }
         if (!$transcode) {
             $types['real'] = $ftype;
         }
         if ($urlinfo['type'] == 'song') {
             if ($types['real'] == "ogg" || $types['real'] == "opus") {
                 $types['player'] = "oga";
             } else {
                 if ($types['real'] == "mp4") {
                     $types['player'] = "m4a";
                 }
             }
         } else {
             if ($urlinfo['type'] == 'video') {
                 if ($types['real'] == "ogg") {
                     $types['player'] = "ogv";
                 } else {
                     if ($types['real'] == "webm") {
                         $types['player'] = "webmv";
                     } else {
                         if ($types['real'] == "mp4") {
                             $types['player'] = "m4v";
                         }
                     }
                 }
             }
         }
     } else {
         if ($item->type == 'live_stream') {
             $types['real'] = $item->codec;
             if ($types['real'] == "ogg" || $types['real'] == "opus") {
                 $types['player'] = "oga";
             }
         } else {
             $ext = pathinfo($item->url, PATHINFO_EXTENSION);
             if (!empty($ext)) {
                 $types['real'] = $ext;
             }
         }
     }
     if (empty($types['player'])) {
         $types['player'] = $types['real'];
     }
     debug_event("webplayer.class.php", "Types {" . json_encode($types) . "}", 5);
     return $types;
 }
예제 #3
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 = '')
 {
     $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);
 }