当前位置: 首页>>代码示例>>PHP>>正文


PHP Playlist::add_songs方法代码示例

本文整理汇总了PHP中Playlist::add_songs方法的典型用法代码示例。如果您正苦于以下问题:PHP Playlist::add_songs方法的具体用法?PHP Playlist::add_songs怎么用?PHP Playlist::add_songs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Playlist的用法示例。


在下文中一共展示了Playlist::add_songs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import_playlist

 /**
  * 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.'));
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:81,代码来源:catalog.class.php

示例2: _updatePlaylist

 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();
         }
     }
 }
开发者ID:bl00m,项目名称:ampache,代码行数:30,代码来源:subsonic_api.class.php

示例3: intval

         $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']);
开发者ID:cheese1,项目名称:ampache,代码行数:31,代码来源:playlist.php

示例4: playlist_add_song

 /**
  * 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');
     }
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:16,代码来源:api.class.php

示例5: foreach

             $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:
开发者ID:cheese1,项目名称:ampache,代码行数:31,代码来源:playlist.ajax.php

示例6: foreach

         $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;
开发者ID:axelsimon,项目名称:ampache,代码行数:31,代码来源:playlist.php

示例7: foreach

                $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;
}
开发者ID:axelsimon,项目名称:ampache,代码行数:31,代码来源:playlist.ajax.php


注:本文中的Playlist::add_songs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。