Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * 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.'));
 }
Exemple #3
0
 /**
  * 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']));
 }
Exemple #4
0
 /**
  * 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);
 }
 /**
  * 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);
 }