Bend Source is the Best place in Oregon for weekly updates. : GNUMP3d

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2009-02-04 12:22:11 by JimLucas

Additions:
<?php
/*
* This is a script that works with GNUMP3d
* Author: Jim Lucas
* Date: 2009/01/20
* Email: jlucas@cmsws.com
*
* I wrote this because it was easier then modifying the source for GNUMP3d
* and/or releasing it with the next version of the software.
*
*/

error_reporting(E_ALL);
ini_set('display_errors', 0);

# allowed file formats
$allowed_types = array('mp3', 'm4a');

# Path to your gnump3d.conf file
$_CONF = '/etc/gnump3d/gnump3d.conf';

/*
You should not need to modify anything beyond this point.
Do so at your own risk...
*/

if ( is_file($_CONF) && is_readable($_CONF) ) {
foreach ( file($_CONF) AS $line ) {
$line = trim($line);
if ( strlen($line)

0 ) if ( $line[0]

'#' )
$parts = explode('=', $line, 2);

$parts[0] = trim($parts[0]);
$parts[1] = trim($parts[1]);

$$parts[0] = $parts[1];


if ( empty($root) ) {
die('root folder not given');
if ( empty($port) ) {
die('Port not given');
if ( empty($hostname) ) {
die('Hostname not given');
if ( empty($binding_host) ) {
die('binding_host not given');

if ( isset($_POST['submit']) || isset($_POST['download']) ) {
# This will take care of posting crap to the script
$list = "#EXTM3U\n";

if ( isset($_POST['music']) && is_array($_POST['music']) && count($_POST['music']) ) {
foreach ( $_POST['music'] AS $song ) {
if ( !is_file($root.rawurldecode($song)) )
continue;
$list .= "#EXTINF:0,\n";
$list .= "http://{$hostname}:{$port}$song\n";
}

We'll be outputting a PDF
header('Content-type: application/m3u');

It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="playlist.m3u"');

echo $list;

exit;
$folder = ;
if ( isset($_GET['folder']) ) { #&& checkFolder($_GET['folder'])) {
$folder = $_GET['folder'];


echo
<HTML

<form method='post' action='{$_SERVER['PHP_SELF']}'>

<h2>Please be patient, the list is loading...</h2>

HTML;


echo fetchDirectoryContents($root);

echo
<HTML

<input type="submit" name="submit" value="Generate Playlist" />

</form>
HTML;

/*
*
* Below you will find the function that makes it all happen.
*
*
*/

function fetchDirectoryContents($dir) {
global $allowed_types, $totalFiles, $totalDirectories, $port, $hostname, $root;
$lists = array('folders' => array(), 'files' => array());
$list = glob($dir.'/*');
$section = ;
foreach ( $list AS $entry ) {
if ( is_file($entry) ) {
$ext = substr($entry, (int)('-'.strpos(strrev($entry), '.')));
if ( !in_array(strtolower($ext), $allowed_types) )
continue;
$lists['files'][] = $entry;
} else if ( is_dir($entry) ) {
$lists['folders'][] = $entry;
}

sort($lists['folders']);
sort($lists['files']);

if ( $lists['folders'] ) {
$section .= '<ul>';
foreach ( $lists['folders'] AS $folder ) {
$section .= '<li>' . htmlspecialchars(str_replace($dir.'/', , $folder)) . '</li>';
$section .= fetchDirectoryContents($folder);
}
$section .= "</ul>\n";
if ( $lists['files'] ) {
$section .= '<ul>';
foreach ( $lists['files'] AS $file ) {
$section .= '<li><input type="checkbox" name="music[]" value="' . str_replace('%2F', '/', rawurlencode(str_replace($root, , $file) )) . '" />' . str_replace($dir.'/', , $file) . '</li>';
}
$section .= "</ul>\n";
}
return $section;
?>

Deletions:
<?php
/*
* This is a script that works with GNUMP3d
* Author: Jim Lucas
* Date: 2009/01/20
* Email: jlucas@cmsws.com
*
* I wrote this because it was easier then modifying the source for GNUMP3d
* and/or releasing it with the next version of the software.
*
*/
error_reporting(E_ALL);
ini_set('display_errors', 'on');
# For debugging purposes...
define('DEBUG', TRUE);
# allowed file formats
$allowed_types = array('mp3', 'm4a');
# Path to your gnump3d.conf file
$_CONF = '/etc/gnump3d/gnump3d.conf';
/*
You should not need to modify anything beyond this point.
Do so at your own risk...
*/
if ( is_file($_CONF) && is_readable($_CONF) ) {
foreach ( file($_CONF) AS $line ) {
$line = trim($line);
if ( strlen($line)

0 )
continue;
if ( $line[0]

'#' )
continue;

$parts = explode('=', $line, 2);
$parts[0] = trim($parts[0]);
$parts[1] = trim($parts[1]);
$$parts[0] = $parts[1];
# p( $line . PHP_EOL );
}
if ( empty($root) ) {
die('root folder not given');
}
if ( empty($port) ) {
die('Port not given');
}
if ( empty($hostname) ) {
die('Hostname not given');
}
if ( empty($binding_host) ) {
die('binding_host not given');
}
if ( isset($_POST['submit']) || isset($_POST['download']) ) {
# This will take care of posting shit to this script.
$list = "#EXTM3U\n";
if ( isset($_POST['music']) && is_array($_POST['music']) && count($_POST['music']) ) {
foreach ( $_POST['music'] AS $song ) {
if ( !is_file($root.rawurldecode($song)) )
$list .= "#EXTINF:0,\n";
$list .= "http://{$hostname}:{$port}$song\n";
We'll be outputting a PDF
header('Content-type: application/m3u');
It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="playlist.m3u"');
echo $list;
exit;
}
$folder = ;
if ( isset($_GET['folder']) ) { #&& checkFolder($_GET['folder'])) {
$folder = $_GET['folder'];
}
echo
<HTML
<form method='post' action='{$_SERVER['PHP_SELF']}'>
<h2>Please be patient, the list is loading...</h2>
HTML;
echo fetchDirectoryContents($root);
echo
<HTML
<input type="submit" name="submit" value="Generate Playlist" />
</form>
HTML;
/*
*
* Below you will find the function that makes it all happen.
*
*
*/
function fetchDirectoryContents($dir) {
global $allowed_types, $totalFiles, $totalDirectories, $port, $hostname, $root;
$lists = array('folders' => array(), 'files' => array());
$list = glob($dir.'/*');
$section = ;
foreach ( $list AS $entry ) {
if ( is_file($entry) ) {
$ext = substr($entry, (int)('-'.strpos(strrev($entry), '.')));
if ( !in_array(strtolower($ext), $allowed_types) )
$lists['files'][] = $entry;
} else if ( is_dir($entry) ) {
$lists['folders'][] = $entry;
sort($lists['folders']);
sort($lists['files']);
if ( $lists['folders'] ) {
$section .= '<ul>';
foreach ( $lists['folders'] AS $folder ) {
$section .= '<li>' . htmlspecialchars(str_replace($dir.'/', , $folder)) . '</li>';
$section .= fetchDirectoryContents($folder);
$section .= "</ul>\n";
if ( $lists['files'] ) {
$section .= '<ul>';
foreach ( $lists['files'] AS $file ) {
$section .= '<li><input type="checkbox" name="music[]" value="' . str_replace('%2F', '/', rawurlencode(str_replace($root, , $file) )) . '" />' . str_replace($dir.'/', , $file) . '</li>';
$section .= "</ul>\n";
}
return $section;
}
?>




Oldest known version of this page was edited on 2009-02-04 11:11:58 by JimLucas []
Page view:

My Stuff for GNUMP3d


Here is a script written in PHP that will, given the right configuration options, be able to allow you to select your play list on a per song basis

The output isn't styled at all, but it wouldn't take much to customize it to your taste.

Hope someone finds it useful.

<?php
/*
 *  This is a script that works with GNUMP3d
 *  Author: Jim Lucas
 *  Date: 2009/01/20
 *  Email: jlucas@cmsws.com
 *
 *  I wrote this because it was easier then modifying the source for GNUMP3d 
 *  and/or releasing it with the next version of the software.
 *
*/

error_reporting(E_ALL);
ini_set('display_errors', 'on');

# For debugging purposes...
define('DEBUG', 	TRUE);

# allowed file formats
$allowed_types = array('mp3', 'm4a');

# Path to your gnump3d.conf file
$_CONF = '/etc/gnump3d/gnump3d.conf';

/*****************************************************************************
You should not need to modify anything beyond this point.
Do so at your own risk...
*****************************************************************************/

if ( is_file($_CONF) && is_readable($_CONF) ) {
	foreach ( file($_CONF) AS $line ) {
		$line = trim($line);
		if ( strlen($line) === 0 )
			continue;
		if ( $line[0] == '#' )
			continue;
		
		$parts = explode('=', $line, 2);

		$parts[0] = trim($parts[0]);
		$parts[1] = trim($parts[1]);

		$$parts[0] = $parts[1];

#		p( $line . PHP_EOL );

	}
}

if ( empty($root) ) {
	die('root folder not given');
}
if ( empty($port) ) {
	die('Port not given');
}
if ( empty($hostname) ) {
	die('Hostname not given');
}
if ( empty($binding_host) ) {
	die('binding_host not given');
}

if ( isset($_POST['submit']) || isset($_POST['download']) ) {
	# This will take care of posting shit to this script.


	$list = "#EXTM3U\n";

	if ( isset($_POST['music']) && is_array($_POST['music']) && count($_POST['music']) ) {
		foreach ( $_POST['music'] AS $song ) {
			if ( !is_file($root.rawurldecode($song)) )
				continue;
			$list .= "#EXTINF:0,\n";
			$list .= "http://{$hostname}:{$port}$song\n";
		}
	}

	// We'll be outputting a PDF
	header('Content-type: application/m3u');

	// It will be called downloaded.pdf
	header('Content-Disposition: attachment; filename="playlist.m3u"');

	echo $list;

	exit;
}
$folder = '';
if ( isset($_GET['folder']) ) { #&& checkFolder($_GET['folder'])) {
	$folder = $_GET['folder'];
}


echo <<<HTML

<form method='post' action='{$_SERVER['PHP_SELF']}'>

<h2>Please be patient, the list is loading...</h2>

HTML;


echo fetchDirectoryContents($root);

echo <<<HTML

<input type="submit" name="submit" value="Generate Playlist" />

</form>
HTML;

/*
 *
 * Below you will find the function that makes it all happen.
 *
 *
*/

function fetchDirectoryContents($dir) {
	global $allowed_types, $totalFiles, $totalDirectories, $port, $hostname, $root;
	$lists = array('folders' => array(), 'files' => array());
	$list = glob($dir.'/*');
	$section = '';
	foreach ( $list AS $entry ) {
		if ( is_file($entry) ) {
			$ext = substr($entry, (int)('-'.strpos(strrev($entry), '.')));
			if ( !in_array(strtolower($ext), $allowed_types) )
				continue;
			$lists['files'][] = $entry;
		} else if ( is_dir($entry) ) {
			$lists['folders'][] = $entry;
		}
	}

	sort($lists['folders']);
	sort($lists['files']);

	if ( $lists['folders'] ) {
		$section .= '<ul>';
		foreach ( $lists['folders'] AS $folder ) {
			$section .= '<li>' . htmlspecialchars(str_replace($dir.'/', '', $folder)) . '</li>';
			$section .= fetchDirectoryContents($folder);
		}
		$section .= "</ul>\n";
	}
	if ( $lists['files'] ) {
		$section .= '<ul>';
		foreach ( $lists['files'] AS $file ) {
			$section .= '<li><input type="checkbox" name="music[]" value="' . str_replace('%2F', '/', rawurlencode(str_replace($root, '', $file) )) . '" />' . str_replace($dir.'/', '', $file) . '</li>';
		}
		$section .= "</ul>\n";
	}       	
	return $section;
}
?>
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.2052 seconds