#!/usr/bin/perl
use strict;
use warnings;
my $ROOT="/mnt/usb/spesktv";
my $BUMPER_DIR="$ROOT/bumpers";
my $VID_DIR="$ROOT/videos";
my $PFILE="$ROOT/playlist.vlc";
my $PLENGTH=20;
my @video_paths = split("\n", `ls $VID_DIR/*.mp4`);
my @bumper_paths = split("\n", `ls $BUMPER_DIR/*.mp4`);
sub wr($$) {
my $path = shift;
my $line = shift;
open(my $fh, '>', $path) or die "Couldn't open $path";
print $fh $line;
close($fh);
}
sub apd($$) {
my $path = shift;
my $line = shift;
open(my $fh, '>>', $path) or die "Couldn't open $path";
print $fh $line;
close($fh);
}
sub rnd_vid_path {
my $path =$video_paths[ rand @video_paths ];
$path = $path . "\n";
return $path;
}
sub rnd_bmp_path() {
my $path = $bumper_paths[ rand @bumper_paths ];
$path = $path . "\n";
return $path;
}
sub gen_pl() {
wr($PFILE,"");
apd($PFILE,rnd_bmp_path());
foreach my $i ( 1..$PLENGTH ) {
if ( $i % 2 == 0 ) {
apd($PFILE,rnd_bmp_path());
}
apd($PFILE,rnd_vid_path());
}
apd($PFILE,$PFILE . "\n");
}
while () {
my $date = `date`;
chomp $date;
print("$date\n");
print("Generating playlist...\n");
gen_pl();
print("Sleeping for 1hr minutes...\n");
sleep 3600;
}