Esempio n. 1
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.'));
 }
Esempio n. 2
0
 private static function _updatePlaylist($id, $name, $songsIdToAdd = array(), $songIndexToRemove = array(), $public = true)
 {
     $playlist = new Playlist($id);
     $newdata = array();
     $newdata['name'] = !empty($name) ? $name : $playlist->name;
     $newdata['pl_type'] = $public ? "public" : "private";
     $playlist->update($newdata);
     if ($songsIdToAdd) {
         if (!is_array($songsIdToAdd)) {
             $songsIdToAdd = array($songsIdToAdd);
         }
         if (count($songsIdToAdd) > 0) {
             for ($i = 0; $i < count($songsIdToAdd); ++$i) {
                 $songsIdToAdd[$i] = Subsonic_XML_Data::getAmpacheId($songsIdToAdd[$i]);
             }
             $playlist->add_songs($songsIdToAdd);
         }
     }
     if ($songIndexToRemove) {
         if (!is_array($songIndexToRemove)) {
             $songIndexToRemove = array($songIndexToRemove);
         }
         if (count($songIndexToRemove) > 0) {
             foreach ($songIndexToRemove as $track) {
                 $playlist->delete_track_number($track);
             }
             $playlist->regenerate_track_numbers();
         }
     }
 }
Esempio n. 3
0
         $track = $_GET['offset'] ? intval($_GET['offset']) + 1 : 1;
         foreach ($songs as $song_id) {
             if ($song_id != '') {
                 $playlist->update_track_number($song_id, $track);
                 ++$track;
             }
         }
     }
     break;
 case 'add_song':
     $playlist = new Playlist($_REQUEST['playlist_id']);
     if (!$playlist->has_access()) {
         UI::access_denied();
         break;
     }
     $playlist->add_songs(array($_REQUEST['song_id']), true);
     break;
 case 'prune_empty':
     if (!$GLOBALS['user']->has_access(100)) {
         UI::access_denied();
         break;
     }
     prune_empty_playlists();
     $url = AmpConfig::get('web_path') . '/playlist.php';
     $title = T_('Empty Playlists Deleted');
     $body = '';
     show_confirmation($title, $body, $url);
     break;
 case 'remove_duplicates':
     debug_event('playlist', 'Remove duplicates called.', '5');
     $playlist = new Playlist($_REQUEST['playlist_id']);
Esempio n. 4
0
 /**
  * playlist_add_song
  * This add a song to a playlist
  */
 public static function playlist_add_song($input)
 {
     ob_end_clean();
     $playlist = new Playlist($input['filter']);
     $song = new Playlist($input['song']);
     if (!$playlist->has_access()) {
         echo XML_Data::error('401', T_('Access denied to this playlist.'));
     } else {
         $playlist->add_songs(array($song));
         echo XML_Data::single_string('success');
     }
 }
Esempio n. 5
0
             $songs = $pl->get_songs();
             break;
         default:
             debug_event('playlist', 'Adding all songs of current playlist...', '5');
             $objects = $GLOBALS['user']->playlist->get_items();
             foreach ($objects as $object_data) {
                 $type = array_shift($object_data);
                 if ($type == 'song') {
                     $songs[] = array_shift($object_data);
                 }
             }
             break;
     }
     if (count($songs) > 0) {
         Ajax::set_include_override(true);
         $playlist->add_songs($songs, true);
         /*$playlist->format();
           $object_ids = $playlist->get_items();
           ob_start();
           require_once AmpConfig::get('prefix') . UI::find_template('show_playlist.inc.php');
           $results['content'] = ob_get_contents();
           ob_end_clean();*/
         debug_event('playlist', 'Items added successfully!', '5');
         ob_start();
         display_notification(T_('Added to playlist'));
         $results['rfc3514'] = ob_get_clean();
     } else {
         debug_event('playlist', 'No item to add. Aborting...', '5');
     }
     break;
 default:
Esempio n. 6
0
         $track = 1;
         foreach ($songs as $song_id) {
             if ($song_id != '') {
                 $playlist->update_track_number($song_id, $track);
                 ++$track;
             }
         }
     }
     break;
 case 'add_song':
     $playlist = new Playlist($_REQUEST['playlist_id']);
     if (!$playlist->has_access()) {
         UI::access_denied();
         break;
     }
     $playlist->add_songs(array($_REQUEST['song_id']), 'ORDERED');
     break;
 case 'prune_empty':
     if (!$GLOBALS['user']->has_access(100)) {
         UI::access_denied();
         break;
     }
     prune_empty_playlists();
     $url = AmpConfig::get('web_path') . '/playlist.php';
     $title = T_('Empty Playlists Deleted');
     $body = '';
     show_confirmation($title, $body, $url);
     break;
 default:
     require_once AmpConfig::get('prefix') . '/templates/show_playlist.inc.php';
     break;
Esempio n. 7
0
                $songs[] = $item_id;
                break;
            default:
                debug_event('playlist', 'Adding all songs of current playlist...', '5');
                $objects = $GLOBALS['user']->playlist->get_items();
                foreach ($objects as $object_data) {
                    $type = array_shift($object_data);
                    if ($type == 'song') {
                        $songs[] = array_shift($object_data);
                    }
                }
                break;
        }
        if (count($songs) > 0) {
            Ajax::set_include_override(true);
            $playlist->add_songs($songs, 'ORDERED');
            /*$playlist->format();
              $object_ids = $playlist->get_items();
              ob_start();
              require_once AmpConfig::get('prefix') . '/templates/show_playlist.inc.php';
              $results['content'] = ob_get_contents();
              ob_end_clean();*/
            debug_event('playlist', 'Items added successfully!', '5');
        } else {
            debug_event('playlist', 'No item to add. Aborting...', '5');
        }
        break;
    default:
        $results['rfc3514'] = '0x1';
        break;
}