Guest User

Untitled

a guest
Dec 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.37 KB | None | 0 0
  1. Rem Type=Plugin
  2. Rem Name=MP4
  3. Rem Author=cyberjedi
  4. Rem Host=Assistant
  5.  
  6.  
  7.  
  8. 'This sub setups the plug-ins option panel in Hal's options dialog
  9. Sub OptionsPanel()
  10. '------------------
  11. ' Define the Help
  12. '------------------
  13. lblPlugin(0).Caption = "Hal will be able to play your favourite movies. Click below for more info"
  14. lblPlugin(0).Move 120, 120, 3300, 1000
  15. lblPlugin(0).WordWrap = True
  16. lblPlugin(0).Visible = True
  17. cmdPlugin(0).Move 320, 650, 2100, 375
  18. cmdPlugin(0).Caption = "Help on this plugin"
  19. cmdPlugin(0).Visible = True
  20. '------------------
  21. ' Define the Musical Mood listbox
  22. '------------------
  23. lblPlugin(1).Caption = "Hal Movie Mood level"
  24. lblPlugin(1).Move 320, 1300, 4000, 1000
  25. lblPlugin(1).WordWrap = True
  26. lblPlugin(1).Visible = True
  27. cboPlugin(0).Move 320, 1600, 1800
  28. cboPlugin(0).AddItem "Very high"
  29. cboPlugin(0).AddItem "High"
  30. cboPlugin(0).AddItem "Average"
  31. cboPlugin(0).AddItem "Low"
  32. cboPlugin(0).AddItem "No Movie
  33. cboPlugin(0).Visible = True
  34. cmdPlugin(1).Caption = "Apply Changes"
  35. cmdPlugin(1).Move 320, 2100, 1600, 375
  36. cmdPlugin(1).Visible = True
  37. '------------------
  38. ' Update the listbox with the current value stored in the table
  39. '------------------
  40. If HalBrain.CheckTableExistence("vrParameter") = True Then
  41. vrMovieMood = HalBrain.TopicSearch("Movie", "vrParameter")
  42. If vrMovieMood = "" Then vrMovieMood = 1
  43. Select Case vrMovieMood
  44. Case 8
  45. cboPlugin(0).Text = "Very high"
  46. Case 5
  47. cboPlugin(0).Text = "High"
  48. Case 2
  49. cboPlugin(0).Text = "Average"
  50. Case 1
  51. cboPlugin(0).Text = "Low"
  52. Case 0
  53. cboPlugin(0).Text = "No movie"
  54. End Select
  55. End If
  56. End Sub
  57.  
  58. Sub cmdPlugin_Click(Index)
  59. Dim vrTempQuery()
  60. Dim vrMovie, vrMovieMood
  61. Select Case Index
  62. Case 0
  63. HalMenu.HalCommand "<RUNPROG>vrMP4Help.html</RUNPROG>"
  64. Case 1
  65. '------------------
  66. ' Convert the listbox in a value
  67. '------------------
  68. Select Case cboPlugin(0).Text
  69. Case "Very high"
  70. vrMovieMood = 8
  71. Case "High"
  72. vrMovieMood = 5
  73. Case "Average"
  74. vrMovieMood = 2
  75. Case "Low"
  76. vrMovieMood = 1
  77. Case "No music"
  78. vrMovieMood = 0
  79. End Select
  80. '------------------
  81. ' If the Parameter table does not exist, I create it
  82. '------------------
  83. HalBrain.ReadOnlyMode = False
  84. vrTableName = "vrParameter"
  85. If HalBrain.CheckTableExistence(vrTableName) = False Then
  86. 'Create table if it doesn't exist
  87. HalBrain.CreateTable vrTableName, "TopicSearch", "miscData"
  88. End If
  89. '------------------
  90. ' Search if it contains the MovieMood parameter
  91. '------------------
  92. vrMovie = "MOVIE"
  93. If HalBrain.TopicSearch(vrMusic, vrTableName) = "" Then
  94. '------------------
  95. 'Creates the record storing the new value
  96. '------------------
  97. HalBrain.AddToTable vrTableName, "TopicSearch", vrMovie, vrMovieMood
  98. Else
  99. '------------------
  100. 'Updates the record storing the new value
  101. '------------------
  102. HalBrain.RunQuery "UPDATE " & vrTableName & " SET topic = " & vrMovieMood & " WHERE searchString = " & """" & vrMovie & """", vrTempQuery
  103. End If
  104. End Select
  105. End Sub
  106.  
  107.  
  108. Rem PLUGIN: PLUGINAREA1
  109. 'The comment above tells Ultra Hal Assistant to insert the following code
  110. 'on-the-fly into the main brain code in the section referenced.
  111.  
  112. '------------------
  113. ' Check if the user asked for reorganizing the MP4 table
  114. '------------------
  115. vrMp4 = False
  116. If InStr(UserSentence, " INDEX ") <> 0 And InStr(UserSentence, " MP4 ") <> 0 Then vrMP4 = True
  117.  
  118. If vrMP4 = True Then
  119. '------------------
  120. ' If the MP4 table does not exist, I create it
  121. '------------------
  122. HalBrain.ReadOnlyMode = False
  123. vrTableName = "vrMp4"
  124. If HalBrain.CheckTableExistence(vrTableName) = False Then
  125. ' Create table if it doesn't exist
  126. ' It must be of type Brain, to allow partial text search
  127. HalBrain.CreateTable vrTableName, "Brain", "miscData"
  128. Else
  129. ' The 260 parameter is 256 + 4 = Yes/No with Default = No
  130. vrAnswer = MsgBox("Shall I delete the existing index and recreate it from scratch?", 260, "MP4 Reindexing")
  131. If vrAnswer = 6 Then
  132. HalBrain.RunQuery "DELETE FROM " & vrTableName, vrTempQuery
  133. End If
  134. End If
  135. '------------------
  136. ' Ask which is the main MP4 folder
  137. '------------------
  138. vrMp4Folder = InputBox("Which main folder to you want to reindex?", "MP4 Reindexing", "c:\MP4")
  139. '------------------
  140. ' Read the main MP4 folder
  141. '------------------
  142. Set vrFso = CreateObject("Scripting.FileSystemObject")
  143. If vrFso.FolderExists(vrMp4Folder) Then
  144. GetResponse = "I have indexed all the MP4 files in the specified folder and subfolders. "
  145. HalBrain.ReadOnlyMode = False
  146. vrCurrentFolder = vrMp4Folder
  147. Call ReadFolder(vrCurrentFolder, vrMp4Folder)
  148. Else
  149. GetResponse = "The folder " & vrMp4Folder & " does not exist on your computer. "
  150. End If
  151. HalBrain.ReadOnlyMode = True
  152. End If
  153.  
  154. '------------------
  155. ' Check if the user asked for playing a song
  156. '------------------
  157. vrMp4 = False
  158. vrToPlay = ""
  159. vrNameToPlay = ""
  160. vrToPlay = UCase(HalBrain.SearchPattern(UserSentence, "PLAY * MOVIE *", 2))
  161. If vrToPlay <> "" Then
  162. If HalBrain.CheckTableExistence("vrMp4") = False Then
  163. GetResponse = "I don't find any MP4 index in our brain. "
  164. Else
  165. vrNameToPlay = HalBrain.QABrain(vrToPlay, "vrMp4", 0)
  166. If vrNameToPlay <> "" Then
  167. GetResponse = " "
  168. HalCommands = HalCommands & "<RUNPROG>" & vrNameToPlay & "</RUNPROG>"
  169. End If
  170. End If
  171. HalBrain.ReadOnlyMode = True
  172. End If
  173.  
  174. '------------------
  175. ' From time to time, Hal will play a movie, according to some word you say
  176. ' For example, you say: "I am going to California"
  177. ' Hal will play "California Dreaming"
  178. '------------------
  179. '------------------
  180. ' check the current movie mood factor
  181. '------------------
  182. vrMovieMood = HalBrain.TopicSearch("MOVIE", "vrParameter")
  183. If vrMovieMood = "" Then vrMovieMood = 0
  184. vrMovieMood = CInt(vrMovieMood)
  185.  
  186. If vrMovieMood > 0 Then
  187. j = Int(Rnd * 10) ' generate a random integer between 0 and 9
  188. If j < vrMovieMood Then
  189. vrKeywords = HalBrain.RemoveExtraSpaces(HalBrain.ExtractKeywords(" " & UserSentence & " "))
  190. vrKeywordList = Split(vrKeywords, " ")
  191. For i = Ubound(vrKeywordList) To Lbound(vrKeywordList)
  192. vrNameToPlay = HalBrain.QABrain(vrKeywordList(i), "vrMp4", 0)
  193. If vrNameToPlay <> "" Then
  194. GetResponse = "You talked about " & vrKeywordList(i) & " and this reminds me this movie. "
  195. HalCommands = HalCommands & "<RUNPROG>" & vrNameToPlay & "</RUNPROG>"
  196. Exit For
  197. End If
  198. Next
  199. End If
  200. End If
  201.  
  202.  
  203. Rem PLUGIN: FUNCTIONS
  204. 'The preceding comment is actually a plug-in directive for
  205. 'the Ultra Hal host application. It allows for code snippets
  206. 'to be inserted here on-the-fly based on user configuration.
  207.  
  208. Function ReadFolder(vrCurrentFolder, vrMp4Folder)
  209. Set vrFso = CreateObject("Scripting.FileSystemObject")
  210. Set vrFolder = vrFso.GetFolder(vrCurrentFolder)
  211. '------------------
  212. ' Read all the files in the current folder
  213. '------------------
  214. Set vrFiles = vrFolder.Files
  215. For Each vrFile in vrFiles
  216. '------------------
  217. ' It's an MP4 file; I add it to the table
  218. '------------------
  219. If UCase(Right(vrFile, 3)) = "MP4" Then
  220. vrSong = Ucase(vrFile)
  221. vrSong = Replace(vrSong, ".MP4", "")
  222. vrLen = Len(vrSong)
  223. vrPos = InStrRev(vrSong, "\")
  224. vrRight = vrLen - vrPos
  225. vrSong = LTrim(Right(vrSong, vrRight))
  226. HalBrain.AddToTable "vrMp4", "Brain", vrSong, vrFile
  227. End If
  228. Next
  229. '------------------
  230. ' Read all the subfolders in the current folder
  231. '------------------
  232. Set vrSubFolders = vrFolder.SubFolders
  233. For Each vrFolderObject in vrSubFolders
  234. '------------------
  235. ' Pay attetion here: This is recursive! We must be sure that it will get to an end
  236. ' Since we are reading directories on a hard disk, the number of recursions
  237. ' should never be infinite. However, a very big number of subfolders and files
  238. ' might lead to memory problems or to performances bottlenecks.
  239. ' I've tested it on a folder containing about 100 subfolders and 3.000 files,
  240. ' and got acceptable performances (less than 5 minutes)
  241. '------------------
  242. Call ReadFolder(vrFolderObject, vrMp4Folder)
  243. Next
  244.  
  245. End Function
Add Comment
Please, Sign In to add comment