Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
2012_ask_an_atheist_stream_reflector [2012/12/14 01:47]
sam
2012_ask_an_atheist_stream_reflector [2012/12/21 21:07] (current)
sam
Line 8: Line 8:
  
 Eventually, I'll create my own stream either from the studio or using a relatively clear AM receiver piped into a quiet computer (think RasPi), but as there'​s no internet in the studio and I've no place to put a receiver, scraping the KLAY stream is all we've got. Eventually, I'll create my own stream either from the studio or using a relatively clear AM receiver piped into a quiet computer (think RasPi), but as there'​s no internet in the studio and I've no place to put a receiver, scraping the KLAY stream is all we've got.
 +
 +**UPDATE 12/​21/​2012:​** For some reason, when I went to start the reflector this last Sunday, the filesystem had been completely borked. ​  No idea why, but the fact that I've started documenting things certainly helped get me back online sooner rather than later.
 +
 +There are changes, since I discovered that the KLAY stream will play commercials //over the live programming//​.  ​
  
 ===== Solution ===== ===== Solution =====
Line 16: Line 20:
  
   * Chromium   * Chromium
 +  * Some form of Click-to-Flash
   * alsa tools   * alsa tools
   * Flash Plugin   * Flash Plugin
   * [[http://​code.google.com/​p/​darkice/​|darkice]]   * [[http://​code.google.com/​p/​darkice/​|darkice]]
 +  * wmctrl
 +  * xdotool
   * Some scripting   * Some scripting
  
Line 24: Line 31:
  
 I used [[http://​slim.berlios.de|SLiM]] to boot directly into a user, and as I tend to do on small systems or projects, I used Window Maker as my window manager. ​  VM runs Arch Linux, as usual. I used [[http://​slim.berlios.de|SLiM]] to boot directly into a user, and as I tend to do on small systems or projects, I used Window Maker as my window manager. ​  VM runs Arch Linux, as usual.
 +
 +**Update 12/​21/​2012:​** I dropped SLiM in favor of booting into X right from systemd using [[https://​wiki.archlinux.org/​index.php/​Automatic_login_to_virtual_console|this from the Arch Linux wiki]].
  
 ==== Chromium ==== ==== Chromium ====
  
-Fortunately, the stream ​starts playing ​as soon as the page is loaded, so no xdotool hacking is required.  ​All that'​s ​necessary is to set the stream page as the start location and launch chromium   I could also go to that URL via scriptingbut I wasn't sure that I was going to need a lot of scripting to control the web browser before I went that way.+The first time outwe took advantage of the fact that the stream ​started ​as soon as the page was loaded.  ​But since we found out the stream provider plays commercials over the stream, I installed a click-to-flash plugin to prevent flash video from playing((Becky'​s ​Idea!)). ​  This meant that we had to click around on the screen to get the flash to load ​Fortunately,​ this also allowed us to turn the volume up on the flash app. 
 + 
 +It also meant that if the browser shutdown incorrectlyit would push the "​Restore"​ dialog and throw the coordinates off.   To avoid that, we blow away the Chromium config directory and restore from a tar'ed backup on each chromium start. 
 + 
 +chromewatch.pl is a little more complex than it started out as.   It still uses a lot of sleep()'​s and usleep()'​s where we can't really watch for things, though. 
  
 ==== ALSA Tools ==== ==== ALSA Tools ====
Line 89: Line 103:
 #​!/​usr/​bin/​perl #​!/​usr/​bin/​perl
  
 +# Chromium Streamer 0.2
 +#  Sam Mulvey <​sam@askanatheist.tv>​ for Ask an Atheist
 +#  GPLv3, I guess. ​ Just share the wealth, man.
  
 +use Time::HiRes qw/usleep/;
 +use File::Path;
 + 
 + 
 $watchfile = "/​proc/​asound/​card0/​pcm0p/​sub0/​hw_params";​ $watchfile = "/​proc/​asound/​card0/​pcm0p/​sub0/​hw_params";​
 +$wmctrl ​   = "/​usr/​bin/​wmctrl";​
 +$xdotool ​  = "/​usr/​bin/​xdotool";​
 +$chromium ​ = "/​usr/​bin/​chromium";​
 +$killall ​  = "/​usr/​bin/​killall";​
 +
 +$klay_url ​ = "​http://​p.freestreams.com/?​pid=513.";​
 +$x_loc ​    = 199;
 +$y_loc ​    = 207;
 +$c_delay ​  = 5000;
 +$window_id = 0;
 +
 +
 +$config_dir ​  = "/​home/​sam/​.config";​
 +$restore_file = "/​home/​sam/​klay_reflect/​chromium.tgz";​
  
 $SIG{CHLD} = '​IGNORE';​ $SIG{CHLD} = '​IGNORE';​
 +$ENV{'​DISPLAY'​} = ":​0.0";​ 
 + 
 $|++; $|++;
 + 
 for (;;) { for (;;) {
 + 
         open(WATCH, $watchfile);​         open(WATCH, $watchfile);​
         chomp($check = <​WATCH>​);​         chomp($check = <​WATCH>​);​
         close(WATCH);​         close(WATCH);​
 + 
         if ($check eq "​closed"​) {         if ($check eq "​closed"​) {
 + 
                 print "​\nSound card not in use.  Restarting!\n\n";​                 print "​\nSound card not in use.  Restarting!\n\n";​
 +
 + # Launch Chromium
                 unless (fork()) {                 unless (fork()) {
-                        ​`killall chromium`;​ + 
-                        exec("/usr/bin/chromium"​);​+ rmtree($config_dir."/​chromium"​);​ 
 + system("​tar -C $config_dir -zxf $restore_file"​);​ 
 + usleep(500);​ 
 +                        ​`$killall chromium`;​ 
 + 
 + exec("$chromium ​$klay_url");
                 }                 }
-                sleep 12; 
-                print "​Continuing to watch.";​ 
  
  
 + # Move Things Around
 + unless (fork()) {
 +
 +
 +
 + # Get Window ID;
 + $window_id = 0;
 + do {
 +
 + chomp(@LIST = `$wmctrl -l`);
 + foreach (@LIST) {
 + (@F) = split("​ ", $_, 2);
 + $window_id = $F[0] if ($F[1] =~ m/​Chromium/​i);​
 +
 + }
 +
 + usleep(500);​
 +
 + } until ($window_id =~ '​x'​);​
 +
 + sleep 5;
 +
 + print "​WINDOW ID: $window_id\n";​
 +
 + # Maximize!
 + `$wmctrl -iR $window_id`;​
 + `$wmctrl -ir $window_id -b add,​maximized_vert,​maximized_horz`;​
 +
 +
 + # findclient: 10485795
 + # x:199 y:207 screen:0 window:​10485795
 + `$xdotool mousemove $x_loc $y_loc click --repeat 2 --delay $c_delay 1`;
 +
 + exit 0;
 +
 + }
 +
 +
 +                sleep 60;
 +                print "​Continuing to watch.";​
 + 
 + 
         } else {         } else {
                 print "​.";​                 print "​.";​
         }         }
 + 
         sleep 2;         sleep 2;
 + 
 } }
 +
 </​code>​ </​code>​
  
-There'​s a gap between the ad and the actual audio, leading to a possible race where chromewatch.pl checks the card status in the gap, but in testing I haven'​t run into it.+ 
 +There'​s a gap between the ad and the actual audio, leading to a possible race where chromewatch.pl checks the card status in the gap, but in testing I haven'​t run into it.  However, we've extended the wait period to after the ad play, so it's unlikely that the race will appear. ​  For more notes on the operation of this script, see [[#​Chromium]].
  
  
Line 130: Line 215:
  
 <​code>​ <​code>​
-/​usr/​bin/​urxvt -name ChromeWatch -title ChromeWatch -e /​home/​sam/​chromewatch.pl ​+/​usr/​bin/​urxvt -name ChromeWatch -title ChromeWatch -e /home/sam/​klay_reflect/​chromewatch.pl ​
 & &
-/​usr/​bin/​urxvt -name darkicerunner -title DarkIce -e /​usr/​bin/​darkice -c /​home/​sam/​darkice.cfg &+/​usr/​bin/​urxvt -name darkicerunner -title DarkIce -e /​usr/​bin/​darkice -c /home/sam/​klay_reflect/​darkice.cfg &
 exec wmaker exec wmaker
 </​code>​ </​code>​