Search And Play A Movie By Title, Subtitle or Random
-
My code formatting in this post apparently suck! Oops.
I could say:
' Hey Google tell trigger command movie with parameter die hard' the movie should be found and played.{ "trigger": "Movie", "command": "PlayMovie.vbs", "ground": "foreground", "voice": "movie", "allowParams": "true" }
Create PlayMovie.vbs with these contents:
'***************************************************************************** ' Author: Allan McFarlane (2018) ' Purpose: Locates And Play First Movie Whose Title Or ' SubTitle Matches The Passed Parameter(s). ' If There Is No Parameter A Random Movie Is Played. ' Inputs: Complete Or Partial Movie Title Or SubTitle, Or None. ' Returns: Message Box Will Be Shown If No Match Was Found. ' Notes: I Use MediaPlayerLite As A Player, It's Installer Offers To Install ' Crapware That Can Be Declined When Installing. ' All Movies Are Stored In A Single Folder Called 'Movies'. ' Each Movie File Is Stored In It's Own Folder In The Movies Folder. ' Searching Is Based Only On The Folder Name. ' Movie Year Should Not Be A Parameter. ' The Words 'The' And 'A' Can Be Used, But, Will Be Internally Dropped. ' Only The 'MP4' Encoded Video File Types Are Played By This Script. ' ' Movie Folders Follow The Following Naming Conventions: ' Butterfly Effect 2, The (2006) ' Catwoman (2004) ' Poison Ivy 4 _ The Secret Society (2008) ' Pirates of the Caribbean 1 _ The Curse of the Black Pearl (2003) ' RoboCop REMAKE (2014) ' Simple Plan, A (1998) ' Spider-Man 2 (2004) ' Nine And A Half Weeks (1986) '***************************************************************************** ' root needs to be set as the path to the 'Movies' folder root = "\\GOFLEX_HOME\GoFlex Home Public\Movies\" For Each a In WScript.Arguments arg = arg & a & " " Next 'a arg = LCase(Trim(arg)) If Left(arg, 4) = "the " Then 'discard superfluous leading THE from parameter arg = Right(arg, Len(arg) - 4) padding2 = 5 ElseIf Left(arg, 2) = "a " Then 'discard superfluous leading A from parameter arg = Right(arg, Len(arg) - 2) padding2 = 3 End If Set fso = CreateObject("Scripting.FileSystemObject") Set oFolders = fso.GetFolder(root) 'main folder that contains all sub folders, which contain the actual movie success = 0 If arg <> "" Then For Each oFolder In oFolders.SubFolders 'loop through sub folder list padding = padding2 If padding = 0 Then 'account for lenght of possible trailing text THE or A If InStr(LCase(oFolder.Name), ", a") > 0 Then padding = 3 End If If InStr(LCase(oFolder.Name), ", the") > 0 Then padding = 5 End If End If If InStr(oFolder.Name, "(") > 0 Then 'prepare for exclusion of trying to match release year ie: (2006) padding = padding + 7 End If subStart = 0 subTitle = "" subStart = InStr(oFolder.Name, "_") 'test for existence of possible subtitle If subStart > 0 Then 'fetch simple title and subtitle if present Title = LCase(Left(oFolder.Name, subStart - 1)) subTitle = LCase(Mid(oFolder.Name, subStart + 1, Len(oFolder.Name) - subStart - padding)) Else Title = LCase(oFolder.Name) End If 'does this folder's title or subtile contains a match to the parameter? If InStr(Title, arg) > 0 Or InStr(subTitle, arg) > 0 Then Set oFiles = oFolder.Files For Each oFile In oFiles 'loop through filenames to find my MP4 encoded movie If InStr(LCase(oFile.Name), ".mp4") > 0 Then arg = root & oFolder.Name & "\" & oFile.Name 'build path to movie file 'build string for specific executable with compatible command line arguments success = 1 arg = Chr(34) & "C:\Program Files\MediaPlayerLite\mpl.exe " & Chr(34) & " " & Chr(34) & arg & Chr(34) & " /fullscreen" CreateObject("Wscript.Shell").Run arg 'run it! Exit For End If Next Exit For End If Next Else 'No movie to search for, so play a random movie folderCount = oFolders.SubFolders.Count Randomize folderNum = Int((folderCount - 1 + 1) * Rnd + 1) curFolderNum = 0 For Each oFolder In oFolders.SubFolders 'loop through sub folder list curFolderNum = curFolderNum + 1 If curFolderNum = folderNum Then Set oFiles = oFolder.Files For Each oFile In oFiles 'loop through filenames to find the MP4 encoded movie If InStr(LCase(oFile.Name), ".mp4") > 0 Then arg = root & oFolder.Name & "\" & oFile.Name 'build path to movie file 'build string for specific executable with compatible command line arguments success = 1 arg = Chr(34) & "C:\Program Files\MediaPlayerLite\mpl.exe " & Chr(34) & " " & Chr(34) & arg & Chr(34) & " /fullscreen" CreateObject("Wscript.Shell").Run arg 'run it! Exit For End If Next Exit For End If Next End If Set fso = Nothing If success = 0 Then WScript.Echo "No Match Found!" & vbCrLf & arg End If
-
@a-mcf, I hope you don't mind. I re-formatted your post a little bit. I just added ``` before and after the big code block to make it look like code.
Also, nice job on the movie player script!