summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2012-09-21 10:48:37 -0400
committerPaul Arthur <paul.arthur@flowerysong.com>2012-09-21 10:52:47 -0400
commita24b711143080d3819034e831aaed6c44cb5b9b0 (patch)
treefdf0f16400ebeb7d2abdf1c51f2a9cb182415334
parentc9dab7bf4e63ae29d40e6252c3e4fbf810f34315 (diff)
downloadampache-a24b711143080d3819034e831aaed6c44cb5b9b0.tar.gz
ampache-a24b711143080d3819034e831aaed6c44cb5b9b0.tar.bz2
ampache-a24b711143080d3819034e831aaed6c44cb5b9b0.zip
Some cleanup of the playlist import code
Global variables are ugly and unnecessary.
-rw-r--r--lib/class/catalog.class.php32
-rw-r--r--playlist.php24
2 files changed, 33 insertions, 23 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 9367c925..1d33da76 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -1245,7 +1245,8 @@ class Catalog extends database_object {
// Foreach Playlists we found
foreach ($this->_playlists as $full_file) {
- if ($this->import_m3u($full_file)) {
+ $result = $this->import_m3u($full_file);
+ if ($result['success']) {
$file = basename($full_file);
if ($verbose) {
echo "&nbsp;&nbsp;&nbsp;" . T_('Added Playlist From') . " $file . . . .<br />\n";
@@ -2263,7 +2264,6 @@ class Catalog extends database_object {
* listed in the m3u
*/
public function import_m3u($filename) {
- global $reason, $playlist_id;
$m3u_handle = fopen($filename,'r');
@@ -2307,30 +2307,34 @@ class Catalog extends database_object {
} // end foreach line
- debug_event('m3u_parse',"Parsing $filename - Found: " . count($songs) . " Songs",'5');
+ debug_event('m3u_parse', "Parsed $filename, found " . count($songs) . " songs", 5);
if (count($songs)) {
$name = "M3U - " . basename($filename,'.m3u');
$playlist_id = Playlist::create($name,'public');
if (!$playlist_id) {
- $reason = T_('Playlist creation error.');
- return false;
+ return array(
+ 'success' => false,
+ 'error' => 'Failed to create playlist.',
+ );
}
/* Recreate the Playlist */
$playlist = new Playlist($playlist_id);
$playlist->add_songs($songs, true);
- $reason = sprintf(T_ngettext('Playlist Import and Recreate Successful. Total: %d Song',
- 'Playlist Import and Recreate Successful. Total: %d Songs',
- count($songs)), count($songs));
- return true;
+
+ return array(
+ 'success' => true,
+ 'id' => $playlist_id,
+ 'count' => count($songs)
+ );
}
- /* HINT: filename */
- $reason = sprintf(T_ngettext('Parsing %s - Not Found: %d Song. Please check your m3u file.',
- 'Parsing %s - Not Found: %d Songs. Please check your m3u file.',
- count($songs)), $filename, count($songs));
- return false;
+
+ return array(
+ 'success' => false,
+ 'error' => 'No valid songs found in M3U.'
+ );
} // import_m3u
diff --git a/playlist.php b/playlist.php
index c15918b8..990f96bf 100644
--- a/playlist.php
+++ b/playlist.php
@@ -103,18 +103,24 @@ switch ($_REQUEST['action']) {
$catalog = new Catalog();
$result = $catalog->import_m3u($filename);
- if($result == false) {
- $url = Config::get('web_path') . '/playlist.php?action=show_import_playlist';
- $title = T_('Playlist Not Imported');
- $body = $reason;
- } else {
- $url = Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id='.$playlist_id;
+ if($result['success']) {
+ $url = 'show_playlist&amp;playlist_id=' . $result['id'];
$title = T_('Playlist Imported');
$body = basename($_FILES['filename']['name']);
- $body .= "<br />";
- $body .= $reason;
+ $body .= '<br />' .
+ sprintf(
+ T_ngettext(
+ 'Successfully imported playlist with %d song.',
+ 'Successfully imported playlist with %d songs.',
+ $result['count']),
+ $result['count']);
}
- show_confirmation($title,$body,$url);
+ else {
+ $url = 'show_import_playlist';
+ $title = T_('Playlist Not Imported');
+ $body = T_($result['error']);
+ }
+ show_confirmation($title, $body, Config::get('web_path') . '/playlist.php?action=' . $url);
break;
case 'set_track_numbers':
/* Make sure they have permission */