#!/usr/bin/perl #H# This script randomly plays TV show files using my xplay script. It takes #H# a list of file specs with wild cards from @FileSpecs and turns it into a #H# list of files to be played. The files are then played in random order and #H# each one is removed from the queue after it is played so that there is no #H# repitition. It also plays all of my music videos. #H# #H# It also folds multi-part TV show episodes together so they get watched #H# in the proper order as a single episode. #H# #H# I tend to run this script late at night so I can fall asleep watching old #H# TV shows which is the reason for the specific selection of what shows get #H# played. #H# #H# I used to use my rxplay script with a predefined list of parameters but #H# the arg list got too long for the shell to handle. #print "Spinning up the drives in insomnia...\n"; #system ("ssh insomnia sudo /sbin/pvs"); $HostName=`uname -n`; chomp $HostName; if ($HostName eq "dementia") { $Player="vplay"; } else { $Player="xplay"; } if ($ENV{"DISPLAY"} eq ":0.1") { $Player="vplay"; } @FileSpecs=(); @Files=(); srand; # Stuff all the file specs into an array... # These file specs will eventually get expanded into the playlist. #push (@FileSpecs,"10*/*"); push (@FileSpecs,"21*/*"); #push (@FileSpecs,"24/*.mkv"); push (@FileSpecs,"7th?Heaven/*"); push (@FileSpecs,"ALF/*"); push (@FileSpecs,"Adam?12/*"); push (@FileSpecs,"Agent?Aika/*"); push (@FileSpecs,"Airwolf/*"); #push (@FileSpecs,"Alias*/*"); push (@FileSpecs,"Alien?Nation/*"); push (@FileSpecs,"American?Dad/*"); push (@FileSpecs,"Anamaniacs/*"); push (@FileSpecs,"Angel/*"); push (@FileSpecs,"Angelic?Layer/*"); push (@FileSpecs,"Area?88/*"); push (@FileSpecs,"Arrested?Development/*"); #push (@FileSpecs,"Band?of?Brothers/*"); #push (@FileSpecs,"Babylon?5/*"); push (@FileSpecs,"Bang*/*"); push (@FileSpecs,"Birds?of?Prey/*"); push (@FileSpecs,"Black?Sheep?Squadron/*"); push (@FileSpecs,"Blade/*"); push (@FileSpecs,"Blue?Thunder/*"); push (@FileSpecs,"Blue?Seed/*"); push (@FileSpecs,"Boston?Public/*"); push (@FileSpecs,"Bubblegum?Crisis*/*"); push (@FileSpecs,"Buck?Rogers*/*"); push (@FileSpecs,"Buffy*/*"); push (@FileSpecs,"Burst?Angel/*"); push (@FileSpecs,"Charmed/*"); push (@FileSpecs,"Chrono?Crusade/*"); push (@FileSpecs,"Castle/*"); push (@FileSpecs,"Cleopatra?2525/*"); push (@FileSpecs,"Commander*/*"); push (@FileSpecs,"Cosmos/*"); push (@FileSpecs,"Comic?Party/*"); push (@FileSpecs,"Conviction/*"); push (@FileSpecs,"COPS/*"); push (@FileSpecs,"Cowboy*/*"); push (@FileSpecs,"Crusade/*"); push (@FileSpecs,"Daphne*/*"); push (@FileSpecs,"Daria/*"); push (@FileSpecs,"Dark?Angel/*"); push (@FileSpecs,"Dexter?s?Laboritory/*"); push (@FileSpecs,"Dilbert/*"); push (@FileSpecs,"Dragnet*/*"); push (@FileSpecs,"Dogfights/*"); push (@FileSpecs,"Dollhouse/*"); push (@FileSpecs,"Earth?2/*"); push (@FileSpecs,"Emergency*/*"); push (@FileSpecs,"Eureka/*"); push (@FileSpecs,"Evangelion/*"); push (@FileSpecs,"Family?Guy/*"); push (@FileSpecs,"Farscape/*"); push (@FileSpecs,"Firefly/*"); push (@FileSpecs,"First?Wave/*"); push (@FileSpecs,"Friday?the?13th/*"); push (@FileSpecs,"From?the?Earth*/*"); push (@FileSpecs,"Full?Metal?Panic/*"); push (@FileSpecs,"Fullmetal?Alchemist*/*"); push (@FileSpecs,"Futurama*/*"); push (@FileSpecs,"*Galactica*/*"); push (@FileSpecs,"Geneshaft/*"); push (@FileSpecs,"Get?Smart/*"); push (@FileSpecs,"GetBackers/*"); push (@FileSpecs,"Girls?Bravo/*"); push (@FileSpecs,"Grenadier/*"); push (@FileSpecs,"Ghost?in?the?Shell*/*"); push (@FileSpecs,"Godannar/*"); push (@FileSpecs,"Gunslinger?Girl/*"); push (@FileSpecs,"Gunsmith?Cats/*"); push (@FileSpecs,"Hanaukyo*/*"); push (@FileSpecs,"Highlander*/*"); push (@FileSpecs,"Highschool?of?the?Dead/*"); push (@FileSpecs,"Homicide??Life?on?the?Street/*"); push (@FileSpecs,"Home?Improvement/*"); push (@FileSpecs,"House/*"); push (@FileSpecs,"It?s?Effin??Science/*"); push (@FileSpecs,"Ikki?Tousen/*"); push (@FileSpecs,"JAG/*"); #push (@FileSpecs,"Jeremiah/*"); #push (@FileSpecs,"Jericho/*"); push (@FileSpecs,"Joan?of?Arcadia/*"); push (@FileSpecs,"Judging?Amy/*"); push (@FileSpecs,"Justice?League/*"); push (@FileSpecs,"Justified/*"); push (@FileSpecs,"Knight?Rider*/*"); push (@FileSpecs,"King?of?the?Hill/*"); push (@FileSpecs,"Lassie*/*"); push (@FileSpecs,"Law*Order*/*"); push (@FileSpecs,"Lexx/*"); push (@FileSpecs,"Life/*"); push (@FileSpecs,"Lois?and?Clark/*"); push (@FileSpecs,"Lock?N?Load/*"); push (@FileSpecs,"MacGyver/*"); push (@FileSpecs,"Mail?Call/*"); push (@FileSpecs,"Magical*/*"); push (@FileSpecs,"Medical?Investigation/*"); push (@FileSpecs,"Modern?Marvels/*"); push (@FileSpecs,"Monk/*"); push (@FileSpecs,"Monty?Python*/*"); push (@FileSpecs,"Moral?Orel/*"); push (@FileSpecs,"Mushi?Shi/*"); push (@FileSpecs,"MythBusters/*"); push (@FileSpecs,"NCIS*/*"); push (@FileSpecs,"Numb3rs/*"); push (@FileSpecs,"Odyssey?5/*"); push (@FileSpecs,"Over?There/*"); #push (@FileSpecs,"Penn*/*"); push (@FileSpecs,"Pinky*/*"); push (@FileSpecs,"Planetes/*"); push (@FileSpecs,"Police?Squad/*"); push (@FileSpecs,"Quantum?Leap/*"); push (@FileSpecs,"Read?or?Die/*"); push (@FileSpecs,"Renegade/*"); push (@FileSpecs,"Ringer/*"); push (@FileSpecs,"Robocop*/*"); push (@FileSpecs,"Robot?Chicken/*"); push (@FileSpecs,"Robotech/*"); #push (@FileSpecs,"Roswell/*"); push (@FileSpecs,"Rurouni?Kenshin/*"); push (@FileSpecs,"Salvage*/*"); push (@FileSpecs,"SeaQuest?DSV/*"); push (@FileSpecs,"Seven?Days/*"); #push (@FileSpecs,"Sharpe/*"); push (@FileSpecs,"Shuffle/*"); push (@FileSpecs,"Sledge?Hammer/*"); push (@FileSpecs,"Sliders/*"); push (@FileSpecs,"Smash?Lab/*.mkv"); #push (@FileSpecs,"Smallville/*.mkv"); push (@FileSpecs,"Sons?of?Anarchy/*"); push (@FileSpecs,"South?Park/*"); push (@FileSpecs,"Space??Above*/*"); push (@FileSpecs,"Space?Precinct/*"); push (@FileSpecs,"Star?Trek*/*"); push (@FileSpecs,"Stargate*/*"); push (@FileSpecs,"Starhyke/*"); push (@FileSpecs,"Starship?Operators/*"); push (@FileSpecs,"Street?Hawk/*"); push (@FileSpecs,"Strike?Witches/*"); push (@FileSpecs,"That??0?s?Show/*"); push (@FileSpecs,"The?A-Team/*"); push (@FileSpecs,"The?Animatrix/*"); push (@FileSpecs,"The?Big?Bang?Theory/*"); push (@FileSpecs,"The?Dresden?Files/*"); push (@FileSpecs,"The?Equalizer/*"); push (@FileSpecs,"The?Greatest?American?Hero/*"); push (@FileSpecs,"The?IT?Crowd/*"); push (@FileSpecs,"The?Outer?Limits/*"); push (@FileSpecs,"The?Power?Puff?Girls/*"); push (@FileSpecs,"The?Practice/*"); push (@FileSpecs,"The?Ren?and?Stimpy?Show/*"); push (@FileSpecs,"*The?Sarah?Connor*/*"); #push (@FileSpecs,"The?Shield/*"); push (@FileSpecs,"The?Simpsons/*"); push (@FileSpecs,"This?Ugly?Yet*/*"); #push (@FileSpecs,"The?West?Wing/*"); push (@FileSpecs,"Third?Watch/*"); push (@FileSpecs,"ThunderCats*/*"); push (@FileSpecs,"T.J.?Hooker/*"); #push (@FileSpecs,"Tour?of?Duty/*"); push (@FileSpecs,"Tremors/*"); push (@FileSpecs,"Tripping?the?Rift/*"); push (@FileSpecs,"Tru?Calling/*"); push (@FileSpecs,"V/*"); push (@FileSpecs,"Voyagers!/*"); push (@FileSpecs,"War?of?the?Worlds/*"); push (@FileSpecs,"Wing?Commander*/*"); push (@FileSpecs,"X-Men*/*"); push (@FileSpecs,"Xena/*"); push (@FileSpecs,"You?re?Under?Arrest*/*"); push (@FileSpecs,"Yu-Gi*/*"); push (@FileSpecs,"Zegapain/*"); push (@FileSpecs,"/home/asylum/kmk/media/VideoClips/demos/*.mkv"); push (@FileSpecs,"/home/asylum/kmk/media/VideoClips/demos/*.avi"); push (@FileSpecs,"/home/asylum/kmk/media/VideoClips/demos/*.mpg"); push (@FileSpecs,"/home/asylum/kmk/media/Movies/*"); #@FileSpecs=(); #push (@FileSpecs,"Star?Trek*/*"); #push (@FileSpecs,"MythBusters/*"); #push (@FileSpecs,"Bang*/*"); #push (@FileSpecs,"21*/*"); #push (@FileSpecs,"Adam?12/*"); #push (@FileSpecs,"CHiPs/*"); #push (@FileSpecs,"Dragnet*/*"); #push (@FileSpecs,"Emergency*/*"); #push (@FileSpecs,"Eureka/*"); #push (@FileSpecs,"Sliders/*"); #push (@FileSpecs,"TJ?Hooker/*"); # Get the list of actual files based on the file specs using ls print "Building file lists\n"; foreach $FileSpec (@FileSpecs) { print "."; # using realpath instead of ls so that symlinks don't have to be tracked down during playback possibly spinning up extra disks for no good reason. open (FileList, "realpath $FileSpec |"); while () { $FileName=$_; chomp $FileName; if ($FileName !~ /\.md5$/) { if ($FileName !~ /\.par2$/) { if ($FileName !~ /\.txt$/) { if ($FileName !~ /\.1080/) { # if ($FileName !~ /\.720/) { push (@Files,$FileName); # } } } } } } close (FileList); } print ".\n"; # attempt to fold together multi-part episodes... # This forces multi-part episodes to be played in order whenever part 1 is chosen # by the randomizer. $NumFiles=$#Files; $ArrayPos=0; while ($ArrayPos <= $NumFiles) { if ($Files[$ArrayPos] =~ /part 1\)\./) { $EndFound="N"; $NextArrayPos=$ArrayPos+1; $Part=1; while ($EndFound ne "Y") { $Part++; if ($Files[$NextArrayPos] =~ /part $Part\)\./) { $Files[$ArrayPos]="$Files[$ArrayPos]+++$Files[$NextArrayPos]"; splice (@Files,$NextArrayPos,1); } else { $EndFound="Y"; } } } $ArrayPos++; } # same as above but allow for 2 digit 0-padded part numbers. $NumFiles=$#Files; $ArrayPos=0; while ($ArrayPos <= $NumFiles) { if ($Files[$ArrayPos] =~ /part 01\)\./) { $EndFound="N"; $NextArrayPos=$ArrayPos+1; $Part=1; while ($EndFound ne "Y") { $Part++; $PaddedPart = sprintf("%02d", $Part); if ($Files[$NextArrayPos] =~ /part $PaddedPart\)\./) { $Files[$ArrayPos]="$Files[$ArrayPos]+++$Files[$NextArrayPos]"; splice (@Files,$NextArrayPos,1); } else { $EndFound="Y"; } } } $ArrayPos++; } # Need an initial number here but it will get updated later inside of the loop. $NumFiles=$#Files; # ANSI colors... $Black= "\e[0;30m"; $Red= "\e[0;31m"; $Green= "\e[0;32m"; $Yellow="\e[0;33m"; $Blue= "\e[0;34m"; $Purple="\e[0;35m"; $Cyan= "\e[0;36m"; $White= "\e[0;37m"; while ($NumFiles >= 0) { # Pick a random filename from the array after adding 1 since the array starts at 0. $NumFiles=$NumFiles+1; $FileNum=int(rand($NumFiles)); $File=$Files[$FileNum]; # Make sure there is no extra crap from ls in the filename chomp $File; $File =~ s/\*$//; $File =~ s/\@$//; $File =~ s/\/$//; # Make the FilNum look more normal since the array starts at 0 instead of 1 # but this is only for display in the next command. $DisplayFileNum=$FileNum+1; # Increase volume level for AC3 stuff if ($HostName ne "dementia") { if ($File =~ /\.ac3/) { $PlayerParams="-af volume=20:1,volnorm=2"; } else { $PlayerParams="-af volnorm=2"; } } # Actually play the file with my xplay script. if ($File =~ /\+\+\+/) { @MultiPart=split (/\+\+\+/,$File); $NumParts=$#MultiPart; foreach $File (@MultiPart) { $ShortFileName=$File; $ShortFileName =~ s/.*\///g; print "${Yellow}Playing $ShortFileName ($DisplayFileNum/$NumFiles) (+$NumParts parts)...\n"; $NumParts=$NumParts-1; #sleep 1; system qq[$Player "$File" $PlayerParams >\& /dev/null]; } } else { $ShortFileName=$File; $ShortFileName =~ s/.*\///g; print "${Green}Playing $ShortFileName ($DisplayFileNum/$NumFiles)...\n"; #sleep 1; system qq[$Player "$File" $PlayerParams >\& /dev/null]; } # Cut the file that was just played out of the array so it doesn't get repeated. splice (@Files,$FileNum,1); $NumFiles=$#Files; }