summaryrefslogtreecommitdiffstats
path: root/lib/class/catalog.class.php
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2008-05-15 05:35:22 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2008-05-15 05:35:22 +0000
commitf274fc8b6d0340c706179730a202f1a9204e2743 (patch)
treea6e2359160f5d7c26065c730ba1d31b034db4861 /lib/class/catalog.class.php
parent2f74d724f74a2d3a13a8c5598fc57d87c08081c4 (diff)
downloadampache-f274fc8b6d0340c706179730a202f1a9204e2743.tar.gz
ampache-f274fc8b6d0340c706179730a202f1a9204e2743.tar.bz2
ampache-f274fc8b6d0340c706179730a202f1a9204e2743.zip
fix the m3u parsing on catalog creation
Diffstat (limited to 'lib/class/catalog.class.php')
-rw-r--r--lib/class/catalog.class.php55
1 files changed, 35 insertions, 20 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 84cc09a7..94fd74ef 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -2146,47 +2146,62 @@ class Catalog {
} //check_local_mp3
- /*!
- @function import_m3u
- @discussion this takes m3u filename and then attempts
- to create a Public Playlist based on the filenames
- listed in the m3u
+ /**
+ * import_m3u
+ * this takes m3u filename and then attempts to create a Public Playlist based on the filenames
+ * listed in the m3u
*/
- function import_m3u($filename) {
+ public function import_m3u($filename) {
- $m3u_handle = @fopen($filename,'r');
+ $m3u_handle = fopen($filename,'r');
- $data = @fread($m3u_handle,filesize($filename));
+ $data = fread($m3u_handle,filesize($filename));
$results = explode("\n",$data);
- $pattern = "/\.(" . conf('catalog_file_pattern');
- $pattern .= ")$/i";
+ $pattern = '/\.(' . Config::get('catalog_file_pattern') . ')$/i';
+ // Foreach what we're able to pull out from the file
foreach ($results as $value) {
+
// Remove extra whitespace
$value = trim($value);
if (preg_match($pattern,$value)) {
+
/* Translate from \ to / so basename works */
$value = str_replace("\\","/",$value);
$file = basename($value);
+
/* Search for this filename, cause it's a audio file */
- $sql = "SELECT id FROM song WHERE file LIKE '%" . sql_escape($file) . "'";
- $db_results = mysql_query($sql, dbh());
- $results = mysql_fetch_assoc($db_results);
- $song_id = $results['id'];
- if ($song_id) { $songs[] = $song_id; }
+ $sql = "SELECT `id` FROM `song` WHERE `file` LIKE '%" . Dba::escape($file) . "'";
+ $db_results = Dba::query($sql);
+ $results = Dba::fetch_assoc($db_results);
+
+ if (isset($results['id'])) { $songs[] = $results['id']; }
+
} // if it's a file
+ // Check to see if it's a url from this ampache instance
+ elseif (substr($value,0,strlen(Config::get('web_path'))) == Config::get('web_path')) {
+ $song_id = intval(Song::parse_song_url($value));
+
+ $sql = "SELECT COUNT(*) FROM `song` WHERE `id`='$song_id'";
+ $db_results = Dba::query($sql);
+
+ if (Dba::num_rows($db_results)) {
+ $songs[] = $song_id;
+ }
+
+ } // end if it's an http url
} // end foreach line
debug_event('m3u_parse',"Parsing $filename - Found: " . count($songs) . " Songs",'5');
+
if (count($songs)) {
- $playlist = new Playlist();
- $value = str_replace("\\","/",$filename);
- $playlist_name = "M3U - " . basename($filename,'.m3u');
-
- $playlist_id = $playlist->create($playlist_name,'public');
+ $name = "M3U - " . basename($filename,'.m3u');
+ $playlist_id = Playlist::create($name,'public');
+
+ if (!$playlist_id) { return false; }
/* Recreate the Playlist */
$playlist = new Playlist($playlist_id);