1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my $ROOT="/mnt/usb/spesktv";
7 my $BUMPER_DIR="$ROOT/bumpers";
8 my $VID_DIR="$ROOT/videos";
9 my $PFILE="$ROOT/playlist.vlc";
10
11 my $PLENGTH=20;
12
13 my @video_paths = split("\n", `ls $VID_DIR/*.mp4`);
14 my @bumper_paths = split("\n", `ls $BUMPER_DIR/*.mp4`);
15
16 sub wr($$) {
17 my $path = shift;
18 my $line = shift;
19 open(my $fh, '>', $path) or die "Couldn't open $path";
20 print $fh $line;
21 close($fh);
22 }
23
24 sub apd($$) {
25 my $path = shift;
26 my $line = shift;
27 open(my $fh, '>>', $path) or die "Couldn't open $path";
28 print $fh $line;
29 close($fh);
30 }
31
32 sub rnd_vid_path {
33 my $path =$video_paths[ rand @video_paths ];
34 $path = $path . "\n";
35 return $path;
36 }
37
38 sub rnd_bmp_path() {
39 my $path = $bumper_paths[ rand @bumper_paths ];
40 $path = $path . "\n";
41 return $path;
42 }
43
44
45 sub gen_pl() {
46
47 wr($PFILE,"");
48 apd($PFILE,rnd_bmp_path());
49 foreach my $i ( 1..$PLENGTH ) {
50 if ( $i % 2 == 0 ) {
51 apd($PFILE,rnd_bmp_path());
52 }
53 apd($PFILE,rnd_vid_path());
54 }
55 apd($PFILE,$PFILE . "\n");
56 }
57
58 while () {
59
60 my $date = `date`;
61 chomp $date;
62 print("$date\n");
63 print("Generating playlist...\n");
64 gen_pl();
65 print("Sleeping for 1hr minutes...\n");
66 sleep 3600;
67
68 }