<icecast> <limits> <sources>2</sources> <burst-size>32768</burst-size> <threadpool>5</threadpool> </limits> <authentication> <admin-user>admin</admin-user> <admin-password>_</admin-password> </authentication> <directory> <yp-url-timeout>15</yp-url-timeout> <yp-url>http://dir.xiph.org/cgi-bin/yp-cgi</yp-url> </directory> <directory> <yp-url-timeout>15</yp-url-timeout> <yp-url>http://www.oddsock.org/cgi-bin/yp-cgi</yp-url> </directory> <hostname>_IP_</hostname> <listen-socket> <port>__</port> <!— 8000 --> </listen-socket> <fileserve>1</fileserve> <!--, : Icecast, , , xml- , --> <paths> <basedir>/usr/share/icecast</basedir> <logdir>/var/log/icecast</logdir> <webroot>/home/www/icecast</webroot> <adminroot>/home/www/icecast/admin</adminroot> <alias source="/" dest="/status.xsl"/> </paths> <logging> <accesslog>access.log</accesslog> <errorlog>error.log</errorlog> <loglevel>3</loglevel> </logging> <!-- -. , .. ices, . --> <mount> <mount-name>/non-stop</mount-name> <password>_-</password> <max-listeners>___</max-listeners> <charset>cp1251</charset> <public>0</public> <stream-name>_</stream-name> <!-- , Habr.FM Non-Stop --> <stream-description>24/7 Non-stop music</stream-description> <stream-url>_</stream-url> <genre>Electronic</genre> <!-— --> <bitrate>128</bitrate> <type>audio/mpeg</type> <subtype>mp3</subtype> <!-- mp3, . --> <hidden>0</hidden> </mount> <!-- mountpoint , --> <mount> <mount-name>/live</mount-name> <password>__</password> <max-listeners>100</max-listeners> <!-- : , mountpoint /live, , ( ) -. , /live. . --> <fallback-mount>/non-stop</fallback-mount> <fallback-override>1</fallback-override> <fallback-when-full>0</fallback-when-full> <charset>cp1251</charset> <public>1</public> <stream-name>_</stream-name> <stream-description>_</stream-description> <stream-url>_</stream-url> <genre>Electronic</genre> <!-- --> <bitrate>128</bitrate> <type>audio/mpeg</type> <subtype>mp3</subtype> <hidden>0</hidden> </mount> <security> <chroot>0</chroot> <changeowner> <user>icecast</user> <!-- , Icecast --> <group>nogroup</group> <!-- --> </changeowner> </security> </icecast>
<ices:Configuration xmlns:ices="http://www.icecast.org/projects/ices"> <Playlist> <!-- ( ). --> <File>/home/PUBLIC/Music/playlist.m3u</File> <Randomize>0</Randomize> <!-- , .. . --> <Type>builtin</Type> <Module>ices</Module> <Crossfade>1</Crossfade> <!-- , (. <Reencode>) --> </Playlist> <Server> <Hostname>localhost</Hostname> <Port>_</Port> <Password>_</Password> <Protocol>http</Protocol> </Server> <Execution> <Background>1</Background> <Verbose>1</Verbose> <Base_Directory>/tmp</Base_Directory> </Execution> <Stream> <!-- <Server> (. ) --> <Server> <Hostname>localhost</Hostname> <Port>_</Port> <Password>_</Password> <Protocol>http</Protocol> </Server> <Mountpoint>/non-stop</Mountpoint> <!-- , .. . --> <Name>_</Name> <Genre>Electronic</Genre> <!-- --> <Description>24/7 Non-stop music</Description> <URL>_</URL> <Bitrate>128</Bitrate> <Public>1</Public> <!-- . ices , , . --> <Reencode>0</Reencode> <Samplerate>-1</Samplerate> <Channels>2</Channels> </Stream> </ices:Configuration>
#!/bin/bash # MUSICDIR=/home/PUBLIC/Music cd $MUSICDIR for i in *; do cd $MUSICDIR/$i find `pwd` -name "*.mp3" > playlist.m3u done
# crontab -e 10,40 * * * * /root/scripts/radio/music_find.sh
#include <iostream> #include <fstream> #include <cstdlib> #include <ctime> #include <string> #include <vector> using namespace std; int main(const int argc, const char *argv[]) { if (argc<2) { cout << "ERROR: no argument recieved." << endl; return 1; } vector<string> list; string line; ifstream infile(argv[1]); if (infile.fail()) return 1; cout << "Using file: " << argv[1] << endl; while (!infile.eof()) { getline(infile,line); list.push_back(line); } infile.close(); cout << "End of file reached." << endl; int n = list.size(); if (n>1) { cout << "Begin shuffle." << endl; srand(time(0)); string temp; for (int i=0; i<(n-1); i++) { int r = i + (rand() % (ni)); temp = list[i]; list[i] = list[r]; list[r] = temp; } cout << "Finished shuffle." << endl; ofstream outfile(argv[1]); for (int i=0; i<n; i++) outfile << list[i] << endl; outfile.close(); cout << "File succuessfully updated." << endl; return 0; } return 1; }
#!/bin/bash MUSICDIR=/home/PUBLIC/Music cd $MUSICDIR cp -f $1/playlist.m3u playlist.m3u /root/scripts/radio/shuffle playlist.m3u >> /dev/null echo "$1" > /home/www/HabrFM.ru/genre_non-stop.txt if ps -A | grep ices then killall -HUP ices else /etc/init.d/ices start fi
crontab -e 58 01 * * * /root/scripts/radio/playlist_update Breaks 58 03 * * * /root/scripts/radio/playlist_update Chill 58 09 * * * /root/scripts/radio/playlist_update Dance 58 14 * * * /root/scripts/radio/playlist_update House 58 17 * * * /root/scripts/radio/playlist_update Trance 58 21 * * * /root/scripts/radio/playlist_update Hardstyle 58 23 * * * /root/scripts/radio/playlist_update Hardcore
#!/usr/bin/php <?php $MUSICDIR="/home/PUBLIC/Music"; $hostname = "localhost"; $username = "radio"; // $password = "12345"; // $dbName = "radio"; // mysql_connect($hostname,$username,$password) OR die("Can't connect to database."); mysql_select_db($dbName) or die(mysql_error()); $Gen = array('Dance','House','Trance','Hardstyle','Hardcore','Chill','Breaks','Pumping'); $sql = "SELECT * FROM radio.songs"; $all = mysql_query($sql); $num_before = mysql_num_rows($all); echo "There are $num_before records in database.\n"; echo "\n"; echo "Searching for non-existing file names...\n"; $deleted = 0; while($row = mysql_fetch_array($all, MYSQL_ASSOC)) { $id = $row['id']; $db_filename = $row['Filename']; $exist = @fopen($db_filename,"r"); if (!$exist) { echo "Deleting: [$id] $db_filename\n"; $sql = "DELETE FROM radio.songs WHERE id=$id"; mysql_query($sql); $deleted++; } } if (!$deleted) { echo "Nothing deleted.\n"; } else { echo "Total deleted: $deleted records.\n"; } echo "\n"; $added = 0; echo "Searching for new tracks...\n"; for ($i=0;$i<count($Gen);$i++) { $genre=$Gen[$i]; $fp = fopen("$MUSICDIR/$genre/playlist.m3u","r"); while (!feof($fp)) { $filename = fgets($fp); if (strpos($filename,".mp3")) { $filename = substr($filename,0,strlen($filename)-1); $sql = sprintf("SELECT * FROM radio.songs WHERE Filename='%s'",mysql_real_escape_string($filename)); $res = mysql_query($sql); $num = mysql_num_rows($res); if ($num == 0) { $title = strstr($filename," "); $start = strpos($filename,". ")+2; $len = strpos($filename,".mp3") - $start; $title = substr($filename,$start,$len); $filename = substr($filename,0,strpos($filename,".mp3")+4); $sql = sprintf("INSERT INTO radio.songs ( `id`, `Genre`, `Title`, `Filename`, `Rate` ) VALUES ( NULL, '$genre', '%s', '%s', '0' )", mysql_real_escape_string($title),mysql_real_escape_string($filename)); mysql_query($sql) or die(mysql_error()); $added++; echo "Adding $filename\n"; } } } } if (!$added) { echo "Nothing added.\n"; } else { echo "Total added: $added records.\n"; } echo "\n"; $sql = "SELECT * FROM radio.songs"; $all = mysql_query($sql); $num_after = mysql_num_rows($all); if ($num_before == $num_after) { echo "There are still $num_after records in database.\n"; } else { echo "There are $num_after records in database.\n"; } mysql_close(); ?>
/root/scripts/radio/db_update.php
#!/usr/bin/php <?php $STATS_FILE = 'http://IP__:_/status.xsl'; $DOCROOT = '/var/www/HabrFM.ru'; // $hostname = "localhost"; $username = "radio"; // $password = "12345"; // $dbName = "radio"; // mysql_connect($hostname,$username,$password) OR die("Can't connect to database."); mysql_select_db($dbName) or die(mysql_error()); for($i=1;$i<13;$i++) { $fp = fopen($STATS_FILE,'r'); if(!$fp) { die("Unable to connect to Icecast server."); } $stats_file_contents = ''; while(!feof($fp)) { $stats_file_contents .= fread($fp,1024); } fclose($fp); $radio_info = array(); $radio_info['genre'] = ''; $radio_info['listeners'] = ''; $radio_info['now_playing'] = ''; $temp = array(); $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>"; $search_td = array('<td class="streamdata">','</td>'); if(preg_match_all("/$search_for/siU",$stats_file_contents,$matches)) { foreach($matches[0] as $match) { $to_push = str_replace($search_td,'',$match); $to_push = trim($to_push); array_push($temp,$to_push); } } $radio_info['listeners'] = $temp[5]; $radio_info['now_playing'] = $temp[9]; if(strpos($stats_file_contents,'/live')) { $radio_info['genre'] = "DJ On-Air"; } else { $fp = fopen("$DOCROOT/genre_non-stop.txt","r"); $radio_info['genre'] = fgets($fp); fclose($fp); $radio_info['genre'] = substr($radio_info['genre'],0,strlen($radio_info['genre'])-1); } if ($radio_info['genre'] == "DJ On-Air"){ $rate = "1000+"; } else { $sql = sprintf("SELECT * FROM songs WHERE ( Genre='%s' AND Title='%s' )", mysql_real_escape_string($radio_info['genre']), mysql_real_escape_string($radio_info['now_playing'])); $res = mysql_query($sql) or die(); $row = mysql_fetch_array($res, MYSQL_ASSOC); $rate = $row['Rate']; $id = $row['id']; } $fp = fopen("$DOCROOT/now_playing.txt","w"); fputs($fp,$radio_info['now_playing']); fclose($fp); $fp = fopen("$DOCROOT/id.txt","w"); fputs($fp,$id); fclose($fp); $fp = fopen("$DOCROOT/listeners.txt","w"); if ($radio_info['listeners'] > 0) { fputs($fp,'<span style="color:green; font-weight: bold;">'.$radio_info['listeners'].'</span>'); } else { fputs($fp,'<span style="color:black; font-weight: bold;">'.$radio_info['listeners'].'</span>'); } fclose($fp); $fp = fopen("$DOCROOT/genre.txt","w"); fputs($fp,$radio_info['genre']); fclose($fp); $fp = fopen("$DOCROOT/rate.txt","w"); if ($rate > 0) { fputs($fp,'<span style="color:green; font-weight: bold;">+'.$rate.'</span>'); } if ($rate < 0) { fputs($fp,'<span style="color:red; font-weight: bold;">'.$rate.'</span>'); } if ($rate == 0) { fputs($fp,'<span style="color:black; font-weight: bold;">'.$rate.'</span>'); } fclose($fp); sleep(5); } ?>
crontab -e */1 * * * * /root/scripts/radio/icecast_status.php
<?php //, , $DOCROOT = '/var/www/HabrFM.ru'; $hostname = "localhost"; $username = "radio"; $password = "12345"; $dbName = "radio"; mysql_connect($hostname,$username,$password) OR die("Can't connect to database."); mysql_select_db($dbName) or die(mysql_error()); $fp = fopen("$DOCROOT/id.txt", "r"); $id = fgets($fp); fclose($fp); $sql = sprintf("SELECT * FROM votes WHERE ( id='%s' AND ip='%s' )", $id, mysql_real_escape_string($_SERVER['REMOTE_ADDR'])); $res = mysql_query($sql); $num = mysql_num_rows($res); if ($num == 0) { $type = $_GET['type']; if ($type == 'plus') { $sql = sprintf("UPDATE songs SET Rate=Rate+1 WHERE id='%s'", $id); } else { if ($type == 'minus') { $sql = sprintf("UPDATE songs SET Rate=Rate-1 WHERE id='%s'", $id); } else { die('Irregular argument.'); } } if (mysql_query($sql)) { $sql = sprintf("INSERT INTO votes (`id`, `ip`) VALUES ('%s', '%s')", $id, mysql_real_escape_string($_SERVER['REMOTE_ADDR'])); mysql_query($sql); echo ' .'; } else { echo ' .'; } } else { echo " ."; } mysql_close(); ?>
vote.php?type=plus
vote.php?type=minus
<script> function show() { $.ajax({ url: "now_playing.txt", cache: false, success: function(html){ $("#now_playing").html(html); } }); $.ajax({ url: "genre.txt", cache: false, success: function(html){ $("#genre").html(html); } }); $.ajax({ url: "listeners.txt", cache: false, success: function(html){ $("#listeners").html(html); } }); $.ajax({ url: "rate.txt", cache: false, success: function(html){ $("#rate").html(html); } }); } $(document).ready(function(){ show(); setInterval('show()',5000); }); </script>
<?php $Gen = array('Dance','House','Trance','Hardstyle','Hardcore','Chill','Breaks','Pumping'); // :) $hostname = "localhost"; $username = "radio"; $password = "12345"; $dbName = "radio"; mysql_connect($hostname,$username,$password) OR die("Can't connect to database."); mysql_select_db($dbName) or die(mysql_error()); $genre = $_GET["genre"]; $type = $_GET["type"]; echo "<br>\n"; if (!(in_array($genre,$Gen))) { die("Irregular argument."); } $sql = sprintf("SELECT Title, Rate FROM songs WHERE (Genre='%s'",mysql_real_escape_string($genre)); if ($type==1) { $sql = $sql . " AND Rate>0) ORDER BY Rate DESC LIMIT 20"; } else if ($type==2) { $sql = $sql . " AND Rate<0) ORDER BY Rate ASC LIMIT 20"; } else { die("Irregular argument"); } $res = mysql_query($sql); if (mysql_num_rows($res)>0) { echo '<table border="1" style="font-family: Verdana,Geneva; font-size: 10;" cellspacing="0" width="100%">'; echo "\n"; echo '<tr><td align="left">â„–</td><td align="left" width="100%"> - </td><td align="right"></td></tr>'; echo "\n"; } else { echo " . - ."; } $i = 1; while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { echo "<tr>"; echo '<td align="left">' . $i . '.</td>'; echo '<td align="left">' . $row['Title'] . '</td>'; echo '<td align="right">' . $row['Rate'] . '</td>'; echo "</tr>\n"; $i++; } if (mysql_num_rows($res)>0) { echo '</table>'; } mysql_close(); ?>
Source: https://habr.com/ru/post/131116/
All Articles