Download Album
Download Album
Similar to the feature request to stream each song seperately it would be interesting to be able to download an entire album.
For example as a ZIP file.
For example as a ZIP file.
- wbartels
- netjukebox developer
- Posts: 881
- Joined: Thu Nov 04, 2004 3:12 pm
- Location: Netherlands
- Contact:
Re: Download Album
The zip library in PHP can only be used to extract zip files.xdreamer wrote:Similar to the feature request to stream each song seperately it would be interesting to be able to download an entire album.
For example as a ZIP file.
There is another library that also support compression.
Who knows the name of that library????
You can check these out:
http://www.zend.com/codex.php?id=696&single=1
http://www.phpconcept.net/pclzip/index.en.php (I'd use this).
or you may be thinking of zlib.
http://www.zend.com/codex.php?id=696&single=1
http://www.phpconcept.net/pclzip/index.en.php (I'd use this).
or you may be thinking of zlib.
I believe I now have this function enabled, mind you my php is hacked all to hell and it looks awful, but I think it works... If you would like to know what I did please reply back and I'll add all steps. And if you would like to see a demo of this, check out my website, you can login with anonymous access.
edit: no more urls...
edit: no more urls...
Last edited by lylos on Sun Oct 23, 2005 8:29 am, edited 1 time in total.
- wbartels
- netjukebox developer
- Posts: 881
- Joined: Thu Nov 04, 2004 3:12 pm
- Location: Netherlands
- Contact:
Nice work.lylos wrote:I believe I now have this function enabled, mind you my php is hacked all to hell and it looks awful, but I think it works... If you would like to know what I did please reply back and I'll add all steps. And if you would like to see a demo of this, check out my website, you can login with anonymous access.
edit: no more urls...
Did you use a command line progaram for zipping?
If it looks awful, maybe I can clean it up.
So let me see how you did it.
PS
Nice album from Alfie
Last edited by wbartels on Sun Oct 23, 2005 9:19 am, edited 1 time in total.
I used the lite zip script from http://smiledsoft.com/demos/phpzip/index.shtml.
Added this into the includes folder.
Then in stream.php I added the following to the end of the file...
Also added the following line to stream.php where you check the commands:
PS:
Thanks, I really love the album
Added this into the includes folder.
Then in stream.php I added the following to the end of the file...
Code: Select all
// +---------------------------------------------------------------------------+
// | Download Album |
// +---------------------------------------------------------------------------+
function downloadalbum($album_id)
{
require("include/ss_zip.class.php");
global $cfg;
authenticate('access_download');
ini_set('max_execution_time', $cfg['download_timeout']);
$zip= new ss_zip('',1);
$test = mysql_query('SELECT relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($file = mysql_fetch_array($test))
{
$filename = mysql_query('SELECT artist, title FROM track WHERE relative_file = "' . mysql_real_escape_string($file[0]) .'"');
$name = mysql_fetch_array($filename);
$file2 = $cfg['media_dir'] . $file[0];
$zip->add_file($file2,$file[0]);
};
$albumname = mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$albumname2 = mysql_fetch_array($albumname);
$combined2 = $albumname2[0] ." - ". $albumname2[1] .".zip";
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $combined2 . '"');
$zip->save($combined2, b);
}
Code: Select all
if ($command == 'downloadalbum') downloadalbum($album_id);
Thanks, I really love the album
- wbartels
- netjukebox developer
- Posts: 881
- Joined: Thu Nov 04, 2004 3:12 pm
- Location: Netherlands
- Contact:
I don't want to be picky, but I found to big problems with the ss_zip.class.php
There is no possibility to store the file (the minimum compression level is 1)
Try out for yourself the speed difference between store and compression level 1 with WinRAR or another program.
Downloading albums with files larger that 8 MB doesn't work.
When increasing the memory_limit in php.ini to the largest file in the album it works again.
So I assume it has to store the whole processed file in memory.
I could download albums with files larger than 8 MB from your site.
Have you increased the memory_limit in php.ini?
There is no possibility to store the file (the minimum compression level is 1)
Try out for yourself the speed difference between store and compression level 1 with WinRAR or another program.
Downloading albums with files larger that 8 MB doesn't work.
When increasing the memory_limit in php.ini to the largest file in the album it works again.
So I assume it has to store the whole processed file in memory.
I could download albums with files larger than 8 MB from your site.
Have you increased the memory_limit in php.ini?
- wbartels
- netjukebox developer
- Posts: 881
- Joined: Thu Nov 04, 2004 3:12 pm
- Location: Netherlands
- Contact:
Because of the limitations of the script I have searched the internet for alternatives.
I found other open source php scripts but they all needed to allocate memory to the largest file.
What I found interesting is the 7zip open source command line compressor.
Witch can compress in many different formats and is available for Windows and Linux.
http://www.7-zip.org/
7za a –mx0 –tzip %destination %source
Because of the new login system a temp directory based on session can be created.
So different zip files can be created at the same time
All this gives me a new idea.
When making use of a temp directory it is also possible to transcode the music to an other format before making the zip file.
This makes sense for lossless music.
What do you think of this idea?
I found other open source php scripts but they all needed to allocate memory to the largest file.
What I found interesting is the 7zip open source command line compressor.
Witch can compress in many different formats and is available for Windows and Linux.
http://www.7-zip.org/
7za a –mx0 –tzip %destination %source
Because of the new login system a temp directory based on session can be created.
So different zip files can be created at the same time
All this gives me a new idea.
When making use of a temp directory it is also possible to transcode the music to an other format before making the zip file.
This makes sense for lossless music.
What do you think of this idea?
In the login script is there a session ID that is created or some kind of key that we can use to create a directory to store the zip in? In my situation, I have everyone log in via the anonymous login to use my script. Storing the zip file in a directory based on username wouldn't be enough. I'm searching the login script now.
Update... Found a key I was looking for.
As for the idea, I'm loving it. I can get the zip part down, just about have it working. But for the transcoding into a different format, that's way out of me league
Update... Found a key I was looking for.
As for the idea, I'm loving it. I can get the zip part down, just about have it working. But for the transcoding into a different format, that's way out of me league
Code: Select all
cookie('netjukebox_hash')
- wbartels
- netjukebox developer
- Posts: 881
- Joined: Thu Nov 04, 2004 3:12 pm
- Location: Netherlands
- Contact:
On netjukebox 3.75 the cookie('netjukebox_hash') cannot be used as session id.lylos wrote:In the login script is there a session ID that is created or some kind of key that we can use to create a directory to store the zip in? In my situation, I have everyone log in via the anonymous login to use my script. Storing the zip file in a directory based on username wouldn't be enough. I'm searching the login script now.
Update... Found a key I was looking for.
Code: Select all
cookie('netjukebox_hash')
It is a hash based on the expire time and will change very often.
In netjukebox 3.76 cookie('netjukebox_sid') is set a random number witch will be updated often, but tracked in the database with a session_id.
I will finish netjukebox 3.76 now, and start with the album downloading in the next version.
Here's what I have so far. It generates the zip file, it sends it, then it deletes the zip file after completion of the send.
Only issue I'm having is when I cancel the download or click stop, I'm stuck with a huge zip file in a temp directory... any ideas?
And this is UGLY UGLY UGLY... Still working on it
Only issue I'm having is when I cancel the download or click stop, I'm stuck with a huge zip file in a temp directory... any ideas?
And this is UGLY UGLY UGLY... Still working on it
Code: Select all
// +---------------------------------------------------------------------------+
// | Download Album |
// +---------------------------------------------------------------------------+
function downloadalbum($album_id)
{
global $cfg;
authenticate('access_download');
ini_set('max_execution_time', $cfg['download_timeout']);
$test = mysql_query('SELECT relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($file = mysql_fetch_array($test))
{
$filename = mysql_query('SELECT artist, title FROM track WHERE relative_file = "' . mysql_real_escape_string($file[0]) .'"');
$name = mysql_fetch_array($filename);
$file2 = $cfg['media_dir'] . $file[0];
$filelist .= '"'. $file2 .'" ';
};
$albumname = mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$albumname2 = mysql_fetch_array($albumname);
$combined2 = $albumname2[0] ." - ". $albumname2[1] .".zip";
set_time_limit(0);
$downloadcmd = 'C:/Codecs/7za.exe a -mx0 -tzip "'. $cfg['tempdir'] . cookie('netjukebox_hash') .'/'. $combined2 .'" '. $filelist;
@exec($downloadcmd);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . $combined2 . '"');
header('Content-Transfer-Encoding: binary');
$file = $cfg['tempdir'] . cookie('netjukebox_hash') .'/'. $combined2;
if (version_compare(phpversion(), '5.0.0', '>='))
{
$filehandle = @fopen($file, 'rb') or exit();
while (!feof($filehandle))
echo fread($filehandle, 1024 * 1024);
fclose($filehandle);
}
else
@readfile($file);
function rmdirr($dir) {
if($objs = glob($dir."/*")){
foreach($objs as $obj) {
is_dir($obj)? rmdirr($obj) : unlink($obj);
}
}
rmdir($dir);
}
rmdirr($cfg['tempdir'] . cookie('netjukebox_hash') .'/');
}