Commit c03700f6 authored by Philipp's avatar Philipp
Browse files

initial import

parents
# ezWeb
Webinterface for running a streaming station with nothing but linux cli tools.
<?php
/*
* ezweb by P. Giebel <spam@stimpyrama.org>
*
* Created on 24.12.2007
*/
//$webdir = "/var/www/ezweb/";
$webdir = "/home/stimpy/radio/ezweb/web/";
if ( !@require_once( $webdir ."data/include/config.inc.php" ) ) die( "error loading config-file\n" );
if ( !@require_once( $webdir ."data/include/unit_main.inc.php" ) ) die( "error loading main unit\n" );
if ( !@require_once( $webdir ."data/include/getid3/getid3.php" ) ) die( "error loading getid3 library\n" );
if ( !@require_once( "DB.php" ) ) die( "error loading PEAR:DB - please install using pear...\n" );
if ( $cfg["mp3dir"][strlen( $cfg["mp3dir"] )-1] != "/" ) $cfg["mp3dir"] .= "/";
$dsn = $cfg["sql"]["type"] ."://". $cfg["sql"]["user"] .":". $cfg["sql"]["pass"] ."@". $cfg["sql"]["host"] ."/". $cfg["sql"]["db"];
$db =& DB::connect( $dsn, $cfg["sql"]["options"] );
if ( PEAR::isError( $db ) ) {
die( $db->getMessage() ."\n" );
}
if ( $_SERVER["argc"] > 0 ) $cli = true;
if ( $cli ) {
$collection = $_SERVER["argv"][1];
} else {
$collection = strip_tags( $_GET["arg1"] );
}
if ( !$collection ) {
$query = "SELECT id FROM collections ORDER BY id";
$res = $db->query( $query );
while ( $row = $res->fetchrow( DB_FETCHMODE_ASSOC ) ) {
$collection = $row["id"];
scanmp3s( $cfg["mp3dir"], $db, $collection, $cfg["scanexts"] );
}
} else {
if ( !is_int( $collection ) ) {
$query = "SELECT id FROM collections WHERE name LIKE '$collection'";
$res = $db->query( $query );
$row = $res->fetchrow( DB_FETCHMODE_ASSOC );
$collection = $row["id"];
}
scanmp3s( $cfg["mp3dir"], $db, $collection, $cfg["scanexts"] );
}
// cleanup old (missing) files
$query = "SELECT * FROM files";
$res = $db->query( $query );
while ( $row = $res->fetchrow( DB_FETCHMODE_ASSOC ) ) {
if ( !file_exists( $row["filename"] ) ) {
$fid = intval( $row["id"] );
$query = "DELETE FROM files WHERE id='$id'";
$res2 = $db->query( $query );
}
}
?>
#!/usr/bin/php
<?php
// configuration
//$webdir = "/var/www/ezweb/";
$webdir = "/home/stimpy/radio/ezweb/web/";
$now = time();
// external files
if ( !@require_once( $webdir ."data/include/config.inc.php" ) ) die( "error loading config-file" );
if ( !@require_once( $webdir ."data/include/unit_main.inc.php" ) ) die( "error loading main unit" );
if ( !@require_once( "DB.php" ) ) die( "error loading PEAR:DB - please install using pear..." );
if ( $cfg["mp3dir"][strlen( $cfg["mp3dir"] )-1] != "/" ) $cfg["mp3dir"] .= "/";
// sql connect
$dsn = $cfg["sql"]["type"] ."://". $cfg["sql"]["user"] .":". $cfg["sql"]["pass"] ."@". $cfg["sql"]["host"] ."/". $cfg["sql"]["db"];
$db =& DB::connect( $dsn, $cfg["sql"]["options"] );
if ( PEAR::isError( $db ) ) {
die( $db->getMessage() );
}
// cli-check
if ( $_SERVER["argc"] > 0 ) $cli = true;
if ( !$cli ) die( "no web access - please run via ezstream" );
// get next track (first file from queue)
$query = "SELECT filename, fid FROM queue WHERE pos='1'";
$res = $db->query( $query );
$row = $res->fetchrow( DB_FETCHMODE_ASSOC );
$fid = $row["fid"];
$filename = $row["filename"];
if ( !$filename ) $filename = $cfg["fallback"]["filename"];
echo $filename ."\n";
// delete first file from queue
$query = "DELETE FROM queue WHERE pos='1'";
$res = $db->query( $query );
// add track to history
$filename = $db->escapeSimple( $filename );
$now = time();
$query = "INSERT INTO history ( filename, fid, played ) values ".
"( '$filename', '$fid', '$now' )";
$res = $db->query( $query );
// update "last played" tag
$query = "UPDATE files SET lastplayed='$now' WHERE id='$fid'";
$res = $db->query( $query );
// reorder queue and get endtime
$query = "SELECT id, fid FROM queue ORDER BY pos ASC";
$res = $db->query( $query );
$qlength = intval( $res->numRows() );
$pos = 1;
$qendtime = 0;
while ( $row = $res->fetchrow( DB_FETCHMODE_ASSOC ) ) {
$qid = $row["id"];
$fid = $row["fid"];
$query = "UPDATE queue SET pos='$pos' WHERE id='$qid'";
$res2 = $db->query( $query );
$query = "SELECT length FROM files WHERE id='$fid'";
$res2 = $db->query( $query );
$row2 = $res2->fetchrow( DB_FETCHMODE_ASSOC );
$qendtime += intval( $row2["length"] );
$pos++;
}
// fill queue
if ( $qlength < intval( $cfg["autoqueue"] ) ) {
$query = "SELECT fid FROM queue ORDER BY pos DESC LIMIT ". $cfg["dupestep"];
$res = $db->query( $query );
$queuesize = intval( $res->numRows() );
$checkartists = array();
while ( $row = $res->fetchrow( DB_FETCHMODE_ASSOC ) ) {
$fid = intval( $row["fid"] );
$query = "SELECT id3_artist FROM files WHERE id='$fid'";
$res2 = $db->query( $query );
$row2 = $res2->fetchrow( DB_FETCHMODE_ASSOC );
if ( array_search( strtolower( $row2["id3_artist"] ), $checkartists ) === false )
array_push( $checkartists, $db->escapeSimple( strtolower( $row2["id3_artist"] ) ) );
}
if ( $queuesize < intval( $cfg["dupestep"] ) ) {
$historysize = intval( $cfg["dupestep"] )-$queuesize;
$query = "SELECT fid FROM history ORDER BY id DESC LIMIT $historysize";
$res = $db->query( $query );
while ( $row = $res->fetchrow( DB_FETCHMODE_ASSOC ) ) {
$fid = intval( $row["fid"] );
$query = "SELECT id3_artist FROM files WHERE id='$fid'";
$res2 = $db->query( $query );
$row2 = $res2->fetchrow( DB_FETCHMODE_ASSOC );
if ( array_search( strtolower( $row2["id3_artist"] ), $checkartists ) === false )
array_push( $checkartists, $db->escapeSimple( strtolower( $row2["id3_artist"] ) ) );
}
}
$missing = intval( $cfg["autoqueue"] )-$qlength;
$qendtime += intval( date( "G", $now ) )*60*60;
$qendtime += intval( date( "i", $now ) )*60;
$dow = intval( date( "w" ) )+1;
$query = "SELECT id, filename, filesize, weight FROM files WHERE";
foreach ( $checkartists as $ca ) {
if ( strlen( $ca ) > 0 )
$query .= " id3_artist NOT LIKE '$ca' AND";
}
$sqendtimemax = $qendtime+600;
$sqendtimemin = $qendtime-600;
$query2 = "SELECT id, cid, days FROM automat WHERE starttime<'$sqendtimemax' AND starttime>'$sqendtimemin' AND endtime='999999' AND lastexec<>'$dow' ORDER BY starttime DESC";
$res2 = $db->query( $query2 );
if ( $res2->numRows() > 0 ) {
$row2 = $res2->fetchrow( DB_FETCHMODE_ASSOC );
$autodays = unserialize( $row2["days"] );
if ( $autodays[$dow] == 1 ) {
$aid = intval( $row2["id"] );
$cid = intval( $row2["cid"] );
$query3 = "SELECT id, filename, weight FROM files WHERE collection='$cid' AND weight>'0' ORDER BY RAND()*weight DESC LIMIT 1";
$res3 = $db->query( $query3 );
$row3 = $res3->fetchrow( DB_FETCHMODE_ASSOC );
$filename = $db->escapeSimple( $row3["filename"] );
$query3 = "INSERT INTO queue ( filename, fid, pos ) values ".
"( '$filename', '". $row3["id"] ."', ".
"'$pos' )";
$res3 = $db->query( $query3 );
$query3 = "UPDATE automat SET lastexec='$dow' WHERE id='$aid'";
$res3 = $db->query( $query3 );
$pos++;
$missing--;
if ( $missing < 0 ) $missing = 0;
}
}
$query2 = "SELECT id, cid, days FROM automat WHERE starttime<'$qendtime' AND endtime>'$nqendtime' AND endtime<'999999' ORDER BY starttime DESC";
$res2 = $db->query( $query2 );
if ( $res2->numRows() > 0 ) {
$row2 = $res2->fetchrow( DB_FETCHMODE_ASSOC );
$autodays = unserialize( $row2["days"] );
$cid = intval( $row2["cid"] );
if ( $autodays[$dow] == 1 ) $query .= " collection='$cid' AND";
}
$query .= " weight>'0' ORDER BY ";
$playlow = rand( 0, 100 );
if ( $playlow < $cfg["lowweightchance"] ) $query .= "lastplayed ASC LIMIT $missing";
else $query .= "RAND()*weight DESC LIMIT $missing";
$res = $db->query( $query );
if ( intval( $res->numRows() ) < $missing ) {
$query = "SELECT id, filename, filesize, weight FROM files WHERE collection='$cid' AND weight>'0' ORDER BY RAND()*weight DESC LIMIT $missing";
$res = $db->query( $query );
if ( intval( $res->numRows() ) < $missing ) {
$query = "SELECT id, filename, filesize, weight FROM files WHERE weight>'0' ORDER BY RAND()*weight DESC LIMIT $missing";
$res = $db->query( $query );
}
}
if ( PEAR::isError( $res ) ) {
echo $res->getMessage() ."\n";
die ( "query: ". $query ."\n" );
}
while ( $row = $res->fetchrow( DB_FETCHMODE_ASSOC ) ) {
$filename = $db->escapeSimple( $row["filename"] );
$fid = intval( $row["id"] );
if ( ( !$fid ) OR ( $fid == 0 ) ) {
$fid = $cfg["fallback"]["fid"];
$filename = $cfg["fallback"]["filename"];
}
$query = "INSERT INTO queue ( filename, fid, pos ) values ".
"( '$filename', '". $fid ."', ".
"'$pos' )";
$res2 = $db->query( $query );
$pos++;
}
}
?>
AuthType Basic
AuthName "eclectix radio control interface"
AuthUserFile /home/stimpy/.ht-ezweb
Require valid-user
body {
font-size: 12px;
color: #FFFFFF;
font-family: arial, helvetica, sans-serif;
background-color: #002244;
padding: 0px;
margin: 0px;
cursor: default!important;
}
#fw_nowplaying {
border: 1px solid #000000;
background-color: #FFFFFF;
color: #000000;
width: 88%;
height: 60px;
float: left;
}
#fw_currtime {
border: 1px solid #000000;
background-color: #FFFFFF;
color: #000000;
margin-left: 90%;
height: 60px;
}
#fw_toppart {
margin-left: 1%;
margin-right: 1%;
margin-top: 10px;
}
#fw_midpart {
width: 98%;
margin-left: 1%;
margin-right: 1%;
margin-top: 10px;
clear: both;
}
#fw_leftcol {
width: 49%;
}
#fw_rightcol {
width: 49%;
float: right;
}
#fw_collections {
border: 1px solid #000000;
background-color: #FFFFFF;
color: #000000;
height: 405px;
padding: 1%;
overflow: hidden;
}
#collection_tracks {
height: 375px;
overflow: scroll;
}
#fw_queue {
border: 1px solid #000000;
background-color: #FFFFFF;
color: #000000;
width: 98%;
height: 230px;
margin-top: 10px;
padding: 1%;
overflow: scroll;
}
#fw_history {
border: 1px solid #000000;
background-color: #FFFFFF;
color: #000000;
width: 98%;
height: 150px;
margin-top: 10px;
padding: 1%;
overflow: scroll;
}
#fw_automat {
border: 1px solid #000000;
background-color: #FFFFFF;
color: #000000;
margin-left: 1%;
margin-right: 1%;
margin-top: 1%;
height: 115px;
padding: 1%;
}
#fw_infobox {
position: absolute;
top: 200px;
left: 1px;
padding: 5px;
margin-left: 30%;
width: 40%;
border: 2px solid #001144;
background-color: #DDE0FF;
color: #FF0000;
}
img {
border: 0;
}
.defaulttable_head {
background-color: #223399;
font-weight: bold;
color: #FFFFFF;
}
.defaulttable_text-a {
background-color: #E0EFFF;
}
.defaulttable_text-b {
background-color: #D0E0FF;
}
.btn, .btn:visited {
text-decoration: none;
color: #000000;
font-weight: bold;
font-size: 14px;
border: 1px solid #000000;
background-color: #E0EFFF;
}
.btn:hover, .btn:visited:hover {
text-decoration: none;
color: #FF0000;
border: 1px solid #444444;
background-color: #C0CFFF;
cursor: pointer;
}
a.smallbtn, a.smallbtn:visited {
text-decoration: none;
color: #000000;
font-weight: bold;
font-size: 14px;
}
a.smallbtn:hover, a.smallbtn:visited:hover {
text-decoration: none;
color: #FF0000;
cursor: pointer;
}
a.help, a.help:visited {
color: #000000;
text-decoration: none;
}
a.help, a.help:visited {
color: #000000;
text-decoration: none;
cursor: help;
}
input[type=text], select {
border: 1px solid #000000;
padding: 1px;
background-color: #FFFFFF;
}
input[type=text]:hover, select:hover, input[type=text]:focus, select:focus {
border: 1px solid #000000;
padding: 1px;
background-color: #BBFFBB;
}
.xajaxfield {
border: 0!important;
background: transparent!important;
}
This diff is collapsed.
<?php
/*
* ezweb by P. Giebel <spam@stimpyrama.org>
*
* Created on 24.12.2007
*/
$cfg = array( "basepath" => "/home/radio/public_html/ezweb/",
"sql" => array( "type" => "mysql",
"host" => "192.168.1.2",
"user" => "sqluser",
"pass" => "hackme",
"db" => "ezweb",
"options" => array ( "debug" => 2,
"portability" => DB_PORTABILITY_ALL
)
),
"mp3dir" => "/home/radio/mp3",
"scanexts" => array( "mp3" ),
"autoqueue" => 5,
"dupestep" => 50,
"fallback" => array( "fid" => 209,
"filename" => "/home/radio/mp3/Tracks/Trash Fashion - Its a Rave Dave (JE2 Grade 8 Mix).mp3"
)
);
?>
<?php
/*
* ezweb v0.1 by P. Giebel <spam@stimpyrama.org>
*
* Config file (see comments for help)
*/
$cfg = array( "basepath" => "/path/to/ezweb", // physical base-path of your ezweb web-dir
// SQL-settings
"sql" => array( "type" => "mysql", // DB-Type (mysql, pgsql, msql, etc.. only mysql is tested!)
"host" => "localhost", // hostname of your sql-server
"user" => "ezwebuser", // sql username
"pass" => "secret", // sql password
"db" => "ezweb", // sql db name
"options" => array ( "debug" => 2,
"portability" => DB_PORTABILITY_ALL
) // sql-options..
),
"mp3dir" => "/path/to/mp3s/", // base-dir of your mp3-collection(s)
"scanexts" => array( "mp3" ), // which extensions to scan (case-insensitive)
"autoqueue" => 5, // how many files should always be on queue (will be added automatically and randomly)
"dupestep" => 10, // check last X played tracks for artist-dupes (so no two tracks by the same artist will be played too fast after another..
// fallback-track - if something goes wrong, play this track instead of nothing..
"fallback" => array( "fid" => 1, // fileid
"filename" => "/path/to/your/fallbackfile.mp3" // filename incl. path (as wanted by ezstream)
),
"lowweightchance" => 10 // chance to get played "out of the order" for low weighted tracks
);
?>
<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at http://getid3.sourceforge.net //
// or http://www.getid3.org //
/////////////////////////////////////////////////////////////////
// //
// extension.cache.dbm.php - part of getID3() //
// Please see readme.txt for more information //
// ///
/////////////////////////////////////////////////////////////////
// //
// This extension written by Allan Hansen <ahartemis*dk> //
// ///
/////////////////////////////////////////////////////////////////
/**
* This is a caching extension for getID3(). It works the exact same
* way as the getID3 class, but return cached information very fast
*
* Example:
*
* Normal getID3 usage (example):
*
* require_once 'getid3/getid3.php';
* $getID3 = new getID3;
* $getID3->encoding = 'UTF-8';
* $info1 = $getID3->analyze('file1.flac');
* $info2 = $getID3->analyze('file2.wv');
*
* getID3_cached usage:
*
* require_once 'getid3/getid3.php';
* require_once 'getid3/getid3/extension.cache.dbm.php';
* $getID3 = new getID3_cached('db3', '/tmp/getid3_cache.dbm',
* '/tmp/getid3_cache.lock');
* $getID3->encoding = 'UTF-8';
* $info1 = $getID3->analyze('file1.flac');
* $info2 = $getID3->analyze('file2.wv');
*
*
* Supported Cache Types
*
* SQL Databases: (use extension.cache.mysql)
*
* cache_type cache_options
* -------------------------------------------------------------------
* mysql host, database, username, password
*
*
* DBM-Style Databases: (this extension)
*
* cache_type cache_options
* -------------------------------------------------------------------
* gdbm dbm_filename, lock_filename
* ndbm dbm_filename, lock_filename
* db2 dbm_filename, lock_filename
* db3 dbm_filename, lock_filename
* db4 dbm_filename, lock_filename (PHP5 required)
*
* PHP must have write access to both dbm_filename and lock_filename.
*
*
* Recommended Cache Types
*
* Infrequent updates, many reads any DBM
* Frequent updates mysql
*/
class getID3_cached_dbm extends getID3
{
// public: constructor - see top of this file for cache type and cache_options
function getID3_cached_dbm($cache_type, $dbm_filename, $lock_filename) {
// Check for dba extension
if (!extension_loaded('dba')) {
die('PHP is not compiled with dba support, required to use DBM style cache.');
}
// Check for specific dba driver
if (function_exists('dba_handlers')) { // PHP 4.3.0+
if (!in_array('db3', dba_handlers())) {
die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
}
}
else { // PHP <= 4.2.3
ob_start(); // nasty, buy the only way to check...
phpinfo();
$contents = ob_get_contents();
ob_end_clean();
if (!strstr($contents, $cache_type)) {
die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
}
}
// Create lock file if needed
if (!file_exists($lock_filename)) {
if (!touch($lock_filename)) {
die('failed to create lock file: ' . $lock_filename);
}
}
// Open lock file for writing
if (!is_writeable($lock_filename)) {
die('lock file: ' . $lock_filename . ' is not writable');
}
$this->lock = fopen($lock_filename, 'w');
// Acquire exclusive write lock to lock file
flock($this->lock, LOCK_EX);
// Create dbm-file if needed
if (!file_exists($dbm_filename)) {
if (!touch($dbm_filename)) {
die('failed to create dbm file: ' . $dbm_filename);
}
}
// Try to open dbm file for writing
$this->dba = @