Jump to content

Random Episode Selector


Monamo
 Share

Recommended Posts

Notes:

  • There may be an existing script already out there for this
  • There may be a much better way of doing this

But:

  • This is my first official script submission

...so please take it easy on me if either of the first two notes apply.

So, what's the script for? Well, I'm a big fan of watching movies and such on my computer. I've got a collection of Family Guy (and other TV shows) DVD's that I've converted to .AVI and stored them on my file server, in folders named based upon the "seasons"

  • Family Guy
  • \Season 1
  • \Season 2
  • \...

Well, after watching them all too many times to count, I wanted a method to pick a file at random for playback.

What the script does:

  • Indexes the available subfolders (based upon @ScriptDir)
  • Allows the option to deselect specific "seasons" (subfolders)
  • From the selected "seasons," creates an index of all of the .AVI files (or whatever you choose to set as your file mask)
  • Picks an episode from the generated index

Because the first step is to index the subfolders, I can just drop in a new "Season" once I convert the next DVD set. When I next run the program, the new season will be listed. I'm currently dropping this in the parent folder for the particular TV series, but I'm debating adding in functionality to place it at the root of an entire "TV Shows" parent folder.

To do:

  • I've still got to add exception controls for when there are no files matching the file mask found in a subfolder.
  • Work on indexing exceptions for similar filenames (known issue)

So, take a look, remember the notes at the start of my post, and lemme know what you think!

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Dim $ButtonOK, $afolders, $aCheckbox, $aFullFileList[1] = ["placeholder"]
Dim $sFilemask = "*.avi"

$afolders = _FileListToArray(@ScriptDir, "*", 2)

$iGUIWidth = 300
$iGUIHeight = (25 * $afolders[0]) + 30
$iGUIXPos = (@DesktopWidth - $iGUIWidth) / 2
$iGUIYPos = (@DesktopHeight - $iGUIHeight) / 2
GUICreate("Folder Selection", $iGUIWidth, $iGUIHeight, $iGUIXPos, $iGUIYPos)

CreateGUIItems()

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $ButtonOK
            CompileList()
            If UBound($aFullFileList) > 1 Then
                OpenRandom()
                Exit
            Else
                MsgBox(48, "Error", "No selections made, or no files matching" & @CRLF & @CRLF & $sFilemask & @CRLF & @CRLF & "were found in the selected folders.", 5)
            EndIf
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func CreateGUIItems()
    $iCheckboxPos = 15
    Global $aCheckbox[UBound($afolders) ]
    For $i = 1 To $afolders[0] Step 1
        $aCheckbox[$i] = GUICtrlCreateCheckbox($afolders[$i], 10, $iCheckboxPos, -1, 20)
        GUICtrlSetState(-1, $GUI_CHECKED)
        $iCheckboxPos = $iCheckboxPos + 20
        $aCheckbox[0] = UBound($aCheckbox)
    Next

    Global $ButtonOK = GUICtrlCreateButton("OK", ($iGUIWidth - 50) / 2, $iCheckboxPos, 50, 20)
EndFunc   ;==>CreateGUIItems

Func CompileList()
    $j = 1
    $n = 1
    For $i = 1 To UBound($aCheckbox) - 1 Step 1
        $sActiveCheckbox = $aCheckbox[$i]
        If GUICtrlRead($sActiveCheckbox) = $GUI_CHECKED Then
            $aActiveFileList = _FileListToArray(@ScriptDir & "\" & $afolders[$i], $sFilemask, 1)
            $j = (UBound($aActiveFileList) - 1) + $j
            ReDim $aFullFileList[$j]
            For $m = 1 To UBound($aActiveFileList) - 1 Step 1
                $aFullFileList[$n] = @ScriptDir & "\" & $afolders[$i] & "\" & $aActiveFileList[$m]
                $n = $n + 1
            Next
        EndIf
    Next
EndFunc   ;==>CompileList

Func OpenRandom()
    $iSelected = Random(1, UBound($aFullFileList) - 1, 1)
    Run("C:\Program Files\VideoLAN\VLC\vlc.exe -f " & '"' & $aFullFileList[$iSelected] & '"')
EndFunc   ;==>OpenRandom

- Edit: 10 AUG 2007 - Moved known issue item to "To Do" list item

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...