#!perl
use strict;
use Time::Local;
use Warnings;
use Win32;
use Win32::OLE;
my $start = shift || -1; # Use -1 for immediate start.
my $playlist = shift;
my $fadeup = 1;
if ( not defined $playlist )
{
if ( $start !~ m/^\s*-?\d+\s*$/ )
{
$playlist = $start;
$start = -1;
$fadeup = 0;
}
else
{
$playlist = "Party Shuffle";
}
}
if ( $start != "-1" ) # Determine when to proceed, then wait until the
+n.
{
my ( $sH, $sM ) = $start =~ m/^\s*(\d\d?)(\d\d)\s*$/;
die "$0 '$start'\nTime should be in military time with no symbols,
+ e.g.:\n6:30 am = 630, 10:15 pm = 2215\n"
unless defined( $sH ) and defined( $sM );
my $t = time();
my @p = localtime($t); # ($sec,$min,$hour,$mday,$mon,$year,$wday,$
+yday,$isdst)
my ( $tM, $tH ) = ( $p[1], $p[2] );
my $s = 0;
my $today = 0;
if ( $sH < $tH || ( $sH == $tH && $sM <= $tM ) )
{
my @sP = localtime($t + 86400);
$s = timelocal( 0, $sM, $sH, $sP[3], $sP[4], $sP[5] );
}
elsif ( $sH > $tH || ( $sH == $tH && $sM > $tM ) )
{
$s = timelocal( 0, $sM, $sH, $p[3], $p[4], $p[5] );
$today = 1;
}
else
{ die "ASSERT( '$sH', '$tH' )" }
print "Set for ", ( $today ? "today, " : "tomorrow, " ), scalar( l
+ocaltime( $s ) ), "\n";
sleep( ( $s - $t ) - 59 ) if ( ( $s - $t ) > 59 );
print "Ready? One Minute to Go!\n";
sleep( 15 ) while time() < $s;
}
else
{
# no delay? then no fade either.
$fadeup = 0;
}
print "Starting iTunes . . .\n";
my $G_iTA = new Win32::OLE("iTunes.Application");
$G_iTA->{ "BrowserWindow" }->{ "MiniPlayer" } = 1;
$G_iTA->{ "SoundVolume" } = $fadeup ? 10 : 90;
print "Playing...\n";
$G_iTA->{ "LibrarySource" }->{ "Playlists" }->ItemByName( $playlist )-
+>PlayFirstTrack();
if ( $fadeup )
{
print "Fading up...\n";
for my $v ( 11 .. 90 )
{
sleep( 1 );
$G_iTA->{ "SoundVolume" } = $v;
}
print "Have a nice day!\n\n";
}
else
{
print "iTunes load complete.\n\n";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.