Page 1 of 2

Download Album

Posted: Tue Mar 22, 2005 3:38 pm
by xdreamer
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.

Re: Download Album

Posted: Tue Mar 22, 2005 6:21 pm
by wbartels
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.
The zip library in PHP can only be used to extract zip files.

There is another library that also support compression.
Who knows the name of that library????

Posted: Wed Apr 27, 2005 5:27 pm
by ponchorage
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.

Posted: Wed Apr 27, 2005 7:44 pm
by wbartels
Thanks, I will first try out zlib.
Maybe it is possible to directly download the zlib stream without a temp file on the server.

[update]
zlib doesn't support multiple files :(
[/update]

Posted: Wed Oct 12, 2005 11:19 am
by lylos
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...

Posted: Wed Oct 12, 2005 1:32 pm
by wbartels
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...
Nice work.

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 :wink:

Posted: Thu Oct 13, 2005 2:35 am
by lylos
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...

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);
}
Also added the following line to stream.php where you check the commands:

Code: Select all

if ($command == 'downloadalbum') downloadalbum($album_id);
PS:
Thanks, I really love the album :)

Posted: Thu Oct 13, 2005 8:40 am
by wbartels
Thanks very much for the code :D

May this freeware class be bundled with netjukebox witch is GPL licensed?
Its Freeware you may use it as you wish but you may not redistribute it alone.
For commercial applications it is strongly recommended to upgrade to PRO version

Posted: Thu Oct 13, 2005 9:28 am
by lylos
The way I read it is that it can be re-distributed, but not alone... Which I'm guessing would go to say someone who is trying to say they made it? I don't own the script so I don't know.

Posted: Thu Oct 13, 2005 9:59 am
by wbartels
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?

Posted: Fri Oct 14, 2005 9:11 am
by wbartels
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?

Posted: Fri Oct 14, 2005 12:40 pm
by lylos
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. :D

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')

Posted: Fri Oct 14, 2005 1:14 pm
by wbartels
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. :D

Code: Select all

cookie('netjukebox_hash')
On netjukebox 3.75 the cookie('netjukebox_hash') cannot be used as session id.
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.

Posted: Fri Oct 14, 2005 2:09 pm
by lylos
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 :)

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') .'/');
}

Posted: Fri Oct 14, 2005 2:17 pm
by lylos
You said with the new version that there will be a session_id tracked in the mysql database. Is this going to be deleted after a timeout or whenever the user leaves the website? If so, then the deletion of the temp dirs can be tied with this.