1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 19:41:55 +02:00

Fix album batch download. Fix browse catalog (bug with mediaTable). Update some syntax on batch.

This commit is contained in:
SUTJael 2014-03-26 21:58:15 +01:00
parent 8e604cac5b
commit dd63f44c93
4 changed files with 81 additions and 61 deletions

View file

@ -62,7 +62,7 @@ function get_song_files($media_ids)
* @param string $name name of the zip file to be created * @param string $name name of the zip file to be created
* @param string $song_files array of full paths to songs to zip create w/ call to get_song_files * @param string $song_files array of full paths to songs to zip create w/ call to get_song_files
*/ */
function send_zip( $name, $song_files ) function send_zip($name, $song_files)
{ {
// Check if they want to save it to a file, if so then make sure they've // Check if they want to save it to a file, if so then make sure they've
// got a defined path as well and that it's writable. // got a defined path as well and that it's writable.
@ -75,37 +75,37 @@ function send_zip( $name, $song_files )
$in_memory = '0'; $in_memory = '0';
$basedir = AmpConfig::get('tmp_dir_path'); $basedir = AmpConfig::get('tmp_dir_path');
} }
} else { } else {
$in_memory = '1'; $in_memory = '1';
} // if file downloads } // if file downloads
/* Require needed library */ /* Require needed library */
require_once AmpConfig::get('prefix') . '/modules/archive/archive.lib.php'; require_once AmpConfig::get('prefix') . '/modules/archive/archive.lib.php';
$arc = new zip_file( $name . ".zip" ); $arc = new zip_file($name . ".zip" );
$options = array( $options = array(
'inmemory' => $in_memory, // create archive in memory 'inmemory' => $in_memory, // create archive in memory
'basedir' => $basedir, 'basedir' => $basedir,
'storepaths' => 0, // only store file name, not full path 'storepaths' => 0, // only store file name, not full path
'level' => 0, // no compression 'level' => 0, // no compression
'comment' => AmpConfig::get('file_zip_comment') 'comment' => AmpConfig::get('file_zip_comment'),
); 'type' => "zip"
);
$arc->set_options( $options ); $arc->set_options( $options );
foreach ($song_files as $dir => $files) { foreach ($song_files as $dir => $files) {
$arc->add_files( $files, $dir ); $arc->add_files($files, $dir);
} }
if (count($arc->error)) { if (count($arc->error)) {
debug_event('archive',"Error: unable to add songs",'3'); debug_event('archive',"Error: unable to add songs",'3');
return false; return false;
} // if failed to add songs } // if failed to add songs
if (!$arc->create_archive()) { if (!$arc->create_archive()) {
debug_event('archive',"Error: unable to create archive",'3'); debug_event('archive',"Error: unable to create archive",'3');
return false; return false;
} // if failed to create archive } // if failed to create archive
$arc->download_file(); $arc->download_file();
} // send_zip } // send_zip

View file

@ -44,8 +44,11 @@ class archive {
public function set_options($options) { public function set_options($options) {
foreach ($options as $key => $value) foreach ($options as $key => $value) {
$this->options[$key] = $value; $this->options[$key] = $value;
debug_event("archive.lib.php", "Setting option ".$key."[".$value."]...", "5");
}
if (!empty ($this->options['basedir'])) if (!empty ($this->options['basedir']))
{ {
$this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']); $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
@ -92,8 +95,9 @@ class archive {
return 0; return 0;
} }
} }
else else {
$this->archive = ""; $this->archive = "";
}
switch ($this->options['type']) switch ($this->options['type'])
{ {
@ -139,8 +143,9 @@ class archive {
if ($this->options['inmemory'] == 0) if ($this->options['inmemory'] == 0)
{ {
fclose($this->archive); fclose($this->archive);
if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip") if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip") {
unlink($this->options['basedir'] . "/" . $this->options['tmpname'] . ".tmp"); unlink($this->options['basedir'] . "/" . $this->options['tmpname'] . ".tmp");
}
} }
return true; return true;
@ -217,34 +222,39 @@ class archive {
foreach ($list as $current) foreach ($list as $current)
{ {
debug_event("archive.lib.php", "Listing file {".$current."}...", "5");
$current = str_replace("\\", "/", $current); $current = str_replace("\\", "/", $current);
$current = preg_replace("/\/+/", "/", $current); $current = preg_replace("/\/+/", "/", $current);
$current = preg_replace("/\/$/", "", $current); $current = preg_replace("/\/$/", "", $current);
if (substr($current, 0, 1) == "/" ) { $current = "/" . $current; } if (substr($current, 0, 1) == "/" ) { $current = "/" . $current; }
if (strstr($current, "*")) if (strstr($current, "*")) {
{
$regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current); $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
$regex = str_replace("*", ".*", $regex); $regex = str_replace("*", ".*", $regex);
$dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : "."; $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
$temp = $this->parse_dir($dir); $temp = $this->parse_dir($dir);
foreach ($temp as $current2) foreach ($temp as $current2) {
if (preg_match("/^{$regex}$/i", $current2['name'])) if (preg_match("/^{$regex}$/i", $current2['name'])) {
$files[] = $current2; $files[] = $current2;
}
}
unset ($regex, $dir, $temp, $current); unset ($regex, $dir, $temp, $current);
} }
else if (@is_dir($current)) else if (@is_dir($current)) {
{
$temp = $this->parse_dir($current); $temp = $this->parse_dir($current);
foreach ($temp as $file) foreach ($temp as $file) {
$files[] = $file; $files[] = $file;
}
unset ($temp, $file); unset ($temp, $file);
} }
else if (@file_exists($current)) else if (@file_exists($current)) {
$files[] = array ('name' => $current, 'name2' => $this->options['prepend'] . $files[] = array ('name' => $current,
preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ? 'name2' => $this->options['prepend'] . preg_replace("/(\.+\/+)+/",
substr($current, strrpos($current, "/") + 1) : $current), "",
($this->options['storepaths'] == 0 && strstr($current, "/")) ? substr($current, strrpos($current, "/") + 1) : $current),
'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0, 'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current)); 'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
}
} }
chdir($pwd); chdir($pwd);
@ -256,33 +266,37 @@ class archive {
function parse_dir($dirname) function parse_dir($dirname)
{ {
if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname)) if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname)) {
$files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] . $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ? preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname))); substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
else }
else {
$files = array (); $files = array ();
}
$dir = @opendir($dirname); $dir = @opendir($dirname);
while ($file = @readdir($dir)) while ($file = @readdir($dir))
{ {
$fullname = $dirname . "/" . $file; $fullname = $dirname . "/" . $file;
if ($file == "." || $file == "..") if ($file == "." || $file == "..") {
continue; continue;
else if (@is_dir($fullname)) }
{ else if (@is_dir($fullname)) {
if (empty ($this->options['recurse'])) if (empty ($this->options['recurse']))
continue; continue;
$temp = $this->parse_dir($fullname); $temp = $this->parse_dir($fullname);
foreach ($temp as $file2) foreach ($temp as $file2)
$files[] = $file2; $files[] = $file2;
} }
else if (@file_exists($fullname)) else if (@file_exists($fullname)) {
$files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] . $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ? preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
substr($fullname, strrpos($fullname, "/") + 1) : $fullname), substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0, 'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname)); 'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
}
} }
@closedir($dir); @closedir($dir);
@ -313,25 +327,25 @@ class archive {
if ($this->options['inmemory'] == 0) { if ($this->options['inmemory'] == 0) {
$full_arc_name = $this->options['basedir']."/".$this->options['tmpname']; $full_arc_name = $this->options['basedir']."/".$this->options['tmpname'];
if (file_exists($full_arc_name)) { if (file_exists($full_arc_name)) {
$fsize = filesize($full_arc_name); $fsize = filesize($full_arc_name);
//Send some headers which can be useful... //Send some headers which can be useful...
$header = "Content-Disposition: attachment; filename=\""; $header = "Content-Disposition: attachment; filename=\"";
$header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name']; $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
$header .= "\""; $header .= "\"";
header($header); header($header);
header("Content-Length: " . $fsize); header("Content-Length: " . $fsize);
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
header("Cache-Control: no-cache, must-revalidate, max-age=60"); header("Cache-Control: no-cache, must-revalidate, max-age=60");
header("Expires: Sat, 01 Jan 2000 12:00:00 GMT"); header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
readfile($full_arc_name); readfile($full_arc_name);
//Now delete tempory file //Now delete tempory file
unlink($full_arc_name); unlink($full_arc_name);
} }
else { else {
debug_event('ERROR','Archive does not exist, unable to download','1'); debug_event('ERROR','Archive does not exist, unable to download','1');
return false; return false;
@ -617,14 +631,19 @@ class zip_file extends archive
$offset += strlen($temp); $offset += strlen($temp);
unset ($temp); unset ($temp);
} }
else else {
$this->error[] = "Could not open sfx module from {$this->options['sfx']}."; $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
}
$pwd = getcwd(); $pwd = getcwd();
chdir($this->options['basedir']); chdir($this->options['basedir']);
foreach ($this->files as $current) foreach ($this->files as $current)
{ {
foreach ($current as $key => $value) {
debug_event("archive.lib.php", "Processing ".$key."[".$value."]...", "5");
}
if ($current['name'] == $this->options['name']) if ($current['name'] == $this->options['name'])
continue; continue;
@ -683,8 +702,9 @@ class zip_file extends archive
$files++; $files++;
$offset += (30 + strlen($current['name2']) + $size); $offset += (30 + strlen($current['name2']) + $size);
} }
else else {
$this->error[] = "Could not open file {$current['name']} for reading. It was not added."; $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
}
} }
$this->add_data($central); $this->add_data($central);

View file

@ -99,13 +99,13 @@ if (AmpConfig::get('show_played_times')) {
</li> </li>
<?php if (Access::check('interface','75')) { ?> <?php if (Access::check('interface','75')) { ?>
<li> <li>
<a href="<?php echo $web_path; ?>/albums.php?action=clear_art&amp;album_id=<?php echo $album->id; ?>" onclick="return confirm('<?php echo T_('Do you really want to reset album art?'); ?>');"><?php echo UI::get_icon('delete', T_('Reset Album Art')); ?></a> <a href="<?php echo $web_path; ?>/albums.php?action=clear_art&album_id=<?php echo $album->id; ?>" onclick="return confirm('<?php echo T_('Do you really want to reset album art?'); ?>');"><?php echo UI::get_icon('delete', T_('Reset Album Art')); ?></a>
<a href="<?php echo $web_path; ?>/albums.php?action=clear_art&amp;album_id=<?php echo $album->id; ?>" onclick="return confirm('<?php echo T_('Do you really want to reset album art?'); ?>');"><?php echo T_('Reset Album Art'); ?></a> <a href="<?php echo $web_path; ?>/albums.php?action=clear_art&album_id=<?php echo $album->id; ?>" onclick="return confirm('<?php echo T_('Do you really want to reset album art?'); ?>');"><?php echo T_('Reset Album Art'); ?></a>
</li> </li>
<?php } ?> <?php } ?>
<li> <li>
<a href="<?php echo $web_path; ?>/albums.php?action=find_art&amp;album_id=<?php echo $album->id; ?>"><?php echo UI::get_icon('view', T_('Find Album Art')); ?></a> <a href="<?php echo $web_path; ?>/albums.php?action=find_art&album_id=<?php echo $album->id; ?>"><?php echo UI::get_icon('view', T_('Find Album Art')); ?></a>
<a href="<?php echo $web_path; ?>/albums.php?action=find_art&amp;album_id=<?php echo $album->id; ?>"><?php echo T_('Find Album Art'); ?></a> <a href="<?php echo $web_path; ?>/albums.php?action=find_art&album_id=<?php echo $album->id; ?>"><?php echo T_('Find Album Art'); ?></a>
</li> </li>
<!--<?php if ((Access::check('interface','50'))) { ?> <!--<?php if ((Access::check('interface','50'))) { ?>
<li> <li>
@ -135,8 +135,8 @@ if (AmpConfig::get('show_played_times')) {
<?php } ?> <?php } ?>
<?php if (Access::check_function('batch_download')) { ?> <?php if (Access::check_function('batch_download')) { ?>
<li> <li>
<a href="<?php echo $web_path; ?>/batch.php?action=album&amp;id=<?php echo $album->id; ?>"><?php echo UI::get_icon('batch_download', T_('Download')); ?></a> <a href="<?php echo $web_path; ?>/batch.php?action=album&<?php echo $album->get_http_album_query_ids('id'); ?>"><?php echo UI::get_icon('batch_download', T_('Download')); ?></a>
<a href="<?php echo $web_path; ?>/batch.php?action=album&amp;id=<?php echo $album->id; ?>"><?php echo T_('Download'); ?></a> <a href="<?php echo $web_path; ?>/batch.php?action=album&<?php echo $album->get_http_album_query_ids('id'); ?>"><?php echo T_('Download'); ?></a>
</li> </li>
<?php } ?> <?php } ?>
</ul> </ul>

View file

@ -32,7 +32,7 @@
</ul> </ul>
<br/> <br/>
<form method="post" action="<?php echo AmpConfig::get('web_path'); ?>/admin/catalog.php?action=update_from"> <form method="post" action="<?php echo AmpConfig::get('web_path'); ?>/admin/catalog.php?action=update_from">
<table class="tabledata" cellspacing="0" cellpadding="0"> <table class="tabledata2" cellspacing="0" cellpadding="0">
<tr> <tr>
<td><?php /* HINT: /data/myNewMusic */ ?><?php printf (T_('Add from [%s]'), '<span class="information">/data/myNewMusic</span>'); ?></td> <td><?php /* HINT: /data/myNewMusic */ ?><?php printf (T_('Add from [%s]'), '<span class="information">/data/myNewMusic</span>'); ?></td>
<td><input type="text" name="add_path" value="/" /></td> <td><input type="text" name="add_path" value="/" /></td>