Re: FreeBSD and Bach Downloads

Florian Maul <[email protected]>
Newsgroups gmane.comp.audio.netjuke.user
Message-ID <[email protected]>
Hello Elijah,

> Anyone here get batch downloads to work under freebsd. I am using
> the latest b17 and it downloads a file but it is 0 bites.
To report at least one success, batch-downloading does work on my
debian linux box. What irritated me a bit was that mozilla doesn't
show any download progress and the compilation is not very fast
(60MB/1m30s), so you have to wait pretty long without anything
happening.

I can't really see why it wouldn't work on freebsd. It looks like the
tar or zip commands fail for some odd reason. Here are some possible
reasons for failures:
- you haven't set up the right path to zip/tar
- the apache-user does not have the rights to access and execute
  zip/tar
- the commandline options for zip/tar are different on freebsd (I
  doubt it). The following are used:
    tar c -C /music/dir "relative/path/to/file.mp3" ...
    zip -q -0 - "relative/path/to/file.mp3" ...
- maybe special characters in the mp3-filenames are not masked
  correctly by netjuke? (I didn't test it) - try mp3s with simple
  filenames.

I attached a special debug version of batch.php which just displays
the tar/zip-command used by netjuke to build the archive. Just make a
copy of your original batch.php and replace it with this one. Let it
display the command and try to copy it in a shell window to check if
it works or where it fails. I suggest appending a " > testfile.tar"
(without the quotes) to reroute the output to a file.
  
> I made sure of the tar path and also tried to use gzip under the zip
> path neither works for me.
GZip will not work, since it only compresses one file but does not
archive multiple files like zip and tar do.

Good luck :)

Florian
batch.php (application/octet-stream, 4.1 KB)
<?php

// defines if this script requires to be logged in
define( "PRIVATE", false );

# CALL COMMON LIBRARIES

require_once('./lib/inc-common.php');
require_once(FS_PATH."/etc/locale/".LANG_PACK."/inc-batch.php");

// Don't try to subvert me!
if (BATCH_DOWNLOAD == 'f') {

	header ("Location: index.php\n\n");
	
}

set_time_limit (BATCH_TIME_LIMIT);

if (strtolower($_REQUEST['do']) == 'download') {
	bundleMe ($_REQUEST['val']);
} else {
	header ("Location: index.php\n\n");
}

function bundleMe ($val) {
	
	GLOBAL $dbconn, $NETJUKE_SESSION_VARS;
	
	$total_size = 0;
	
	if ($val != '') {
	
		$id = split(",",$val);

    	$trans = get_html_translation_table (HTML_ENTITIES);
    	$trans = array_flip ($trans);
    	$data = strtr($data,$trans);
	
		foreach ($id as $this_id) {
      
	    $sql = "SELECT tr.location, tr.time, tr.name, ar.name, al.name  "
         . " from netjuke_tracks tr, netjuke_artists ar, netjuke_albums al "
         . " where tr.id = $this_id and ar.id = tr.ar_id and al.id = tr.al_id ";
      
      	$dbrs = $dbconn->Execute($sql);
      
      	$tr_location  = separatorCleanup($dbrs->fields[0]);
      	$tr_time      = floor($dbrs->fields[1]);
      	$tr_name      = strtr(format_for_display($dbrs->fields[2]),$trans);
      	$ar_name      = strtr(format_for_display($dbrs->fields[3]),$trans);
      	$al_name      = strtr(format_for_display($dbrs->fields[4]),$trans);
      
      	# Append web path value if location still doesn't contain ://
      	# Copes with the fact that the streaming server could be a relative path (eg: music/)
      	# instead of a protocol+hostname combination (http://streaming.host.dom)
      	#if (!strstr($tr_location,"://")) $tr_location  = WEB_PATH."/".$tr_location;
      
      	$tr_location = separatorCleanup($tr_location);   
        	
		$files .= "\"".rawurldecode($tr_location)."\" ";
       	// update the track's download count.
       	// Is normally done accurately in the dispatcher, but it is now optional...
       	$dbconn->Execute( "update netjuke_tracks set dl_cnt = dl_cnt + 1 where id = ".$this_id." " );
        
		$dbrs->Close();
		
		$total_size += filesize (MUSIC_DIR . '/' . $trlocation);
		if (($total_size / (1024 * 1024)) >= BATCH_SIZE_LIMIT) {
		
			exit;
			
		}

      }
		
	} else {
	
		alert (PLAYER_NOID);
    	exit;

	}
	
	if ($NETJUKE_SESSION_VARS["batch_type"] == '' )
	{
	
	// if user has not set batch_type, set one for them
	
		if (BATCH_TAR_PATH != "") 
		{ 
			$NETJUKE_SESSION_VARS["batch_type"] = 'TAR' ; 
		} else if (BATCH_ZIP_PATH != "") 
		{ 
			$NETJUKE_SESSION_VARS["batch_type"] = 'ZIP' ; 
		} else if (BATCH_SIT_PATH != "") 
		{ 
			$NETJUKE_SESSION_VARS["batch_type"] = 'SIT' ; 
		}

	  netjuke_session('update');
	
	}
	
	// Build the archive
	switch ($NETJUKE_SESSION_VARS["batch_type"]) {
		
		case 'TAR':
		
			$command = BATCH_TAR_PATH . " c -C " . MUSIC_DIR . " " . $files;
			$mime = "application/x-tar";
			$ext = "tar";
			
			break;
		
		case 'ZIP':
	
			$command = BATCH_ZIP_PATH . " -q -0 - " . $files;
			$mime = "application/zip";
			$ext = "zip";
			chdir (MUSIC_DIR);	// change working directory -- zip uses relative paths
			
			break;
		
		case 'SIT':
		
			$tfile = tempnam ("/tmp", "netjuke-");
			if ($tfile == FALSE) {
			
				javascript ("alert('".TMPNAM_FAILURE."');");
				exit;
				
			}
			
			unlink ($tfile);	// Remove file -- stuff stubbornly will not overwrite it
			
			$command = BATCH_SIT_PATH . " -l=0 -q --name=" . $tfile . " " . $files;
			$ext = "sit";
			$mime = "application/sit";
			chdir (MUSIC_DIR);	// change working directory -- zip uses relative paths
	
			break;
			
		default:
		
			header ("Location: prefs.php?do=edit\n\n");
			exit;
			
			break;
			
	}

//	header("Content-type: ".$mime);
//	header("Content-Disposition: attachment; filename=netjuke-".substr(time(),-7).".".$ext );
	print "<html><body>";
	print "<b>running the following command:</b><br><pre>$command</pre>";
	
	if ($NETJUKE_SESSION_VARS["batch_type"] == "SIT") {
	
		exec ($command);
		
		$val = @readfile ($tfile);
		if ($val == FALSE) {
		
			javascript ("alert('".TMPNAM_FAILURE."');");
			exit;
			
		}
		
	} else {
  		
//		passthru ($command);
	}

	print "</body></html>";
  	exit;
}

?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.