Advertisement
Guest User

Untitled

a guest
Sep 19th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.16 KB | None | 0 0
  1. #region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Icon=Luffys-flag-2.ico
  3. #AutoIt3Wrapper_Res_Description=Anime information tool, designed to fetch episode information and then process files.
  4. #AutoIt3Wrapper_Res_Fileversion=0.1.0.2
  5. #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
  6. #AutoIt3Wrapper_Res_Language=1033
  7. #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
  8.  
  9. #include <ButtonConstants.au3>
  10. #include <EditConstants.au3>
  11. #include <GUIConstantsEx.au3>
  12. #include <StaticConstants.au3>
  13. #include <WindowsConstants.au3>
  14. #include <IE.au3>
  15. #include <Inet.au3>
  16. #include <array.au3>
  17. #include <file.au3>
  18.  
  19. #region Interface
  20. $MainForm = GUICreate("Anime info gatherer!", 531, 218, 192, 124)
  21. GUISetIcon(@ScriptDir & "\Luffys-flag-2.ico", -1)
  22. $nameInputTxt = GUICtrlCreateInput("Type Name Here", 24, 16, 377, 21)
  23. $getDataBtn = GUICtrlCreateButton("Fetch data", 24, 48, 75, 25)
  24. $statusLabel = GUICtrlCreateLabel("Data fetching progress: Completed / Progress / Writing to CSV", 106, 53, 299, 24)
  25. $SaveFileBox = GUICtrlCreateInput("", 32, 80, 90, 21)
  26. $SavefileLabel = GUICtrlCreateLabel("Type the name of the file for temporary storage, testing only, .txt is added automatically", 125, 80, 249, 36)
  27. $anime = GUICtrlCreateRadio("Anime Show", 416, 16, 113, 17); to be used later
  28. GUICtrlSetState($anime, True) ; setting anime as default
  29. $manga = GUICtrlCreateRadio("Manga", 416, 32, 113, 17); to be used later
  30. $tableParse = GUICtrlCreateButton("Table thing", 24, 112, 75, 25)
  31. $getFile = GUICtrlCreateButton("Get file", 104, 112, 75, 25)
  32. $filePath = GUICtrlCreateLabel("Path : ", 184, 112, 350, 20)
  33. $change = GUICtrlCreateButton("Rename it", 106, 143, 75, 25)
  34. $result = GUICtrlCreateLabel("", 186, 143, 206, 25)
  35. $oIE = _IECreateEmbedded() ;making an embedded ie window
  36. GUICtrlCreateObj($oIE, 500, 500, 0, 0) ; moving said window out of the way
  37. $credits = GUICtrlCreateLabel("Anime info gatherer by Tommy Asmund Gunnar Kristiansen", 0, 200, 530, 17, BitOR($SS_CENTER, $SS_SUNKEN))
  38. GUICtrlSetState(-1, $GUI_DISABLE)
  39. GUICtrlSetTip(-1, "Duuh, I made this, what did you expect?")
  40. GUISetState(@SW_SHOW)
  41. TraySetState(2)
  42. #endregion Interface
  43.  
  44. #region variables
  45. Global $SearchURL = "www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+"
  46. Global $oldName ; the old filename
  47. Global $newName ; and the new one
  48. Global $path ; path to file
  49. Global $oldPath
  50. Global $fileEnding ; the file ending, like avi, mkv and so on.
  51. Global $filename = "dataz.txt"
  52. Global $readData
  53. Global $s_Destination
  54. #endregion variables
  55.  
  56. GUICtrlSetState($tableParse, $GUI_DISABLE)
  57.  
  58. While 1
  59.     $nMsg = GUIGetMsg()
  60.     Switch $nMsg
  61.         Case $GUI_EVENT_CLOSE
  62.             Exit
  63.         Case $getDataBtn
  64.             _findAnime() ; runs the anime finder function
  65.         Case $tableParse
  66.             _episodes() ; runs the episode parsing function
  67.         Case $getFile
  68.             _getFilepath()
  69.             _getfileinfo()
  70.         Case $change
  71.             _tName()
  72.             ;$s_Destination = "Great Teacher Onizuka - The Legend Begins.ogm"
  73.             _FileRename_($path, $s_Destination)
  74.             GUICtrlSetData($result, "File has been renamed to " & $s_Destination)
  75.     EndSwitch
  76. WEnd
  77.  
  78. Func _tName(); function to test rename system
  79.     $s_Destination = ""
  80.     $file = FileOpen(@ScriptDir &"\"& $filename)
  81.     $newName = FileReadLine($file,1)
  82.         If $file = -1 Then
  83.             MsgBox(0, "Error", "Unable to open file.")
  84.             Exit
  85.         EndIf
  86.     GUICtrlSetData($SaveFileBox,$newName)
  87.     $newName = $readData & " - " & $newName
  88.     $s_Destination = $newName & $fileEnding
  89.     FileClose($filename)
  90.     FileRecycle($filename)
  91. EndFunc
  92.  
  93. Func _getfileinfo() ; get the filename and the path of the file, and then the ending of the file
  94.     Local $path
  95.     $path = GUICtrlRead($filePath)
  96.     $split = StringSplit($path, "\", 2)
  97.     $telle = UBound($split) ; figure out how "big" the array is, then set that number to the $telle variable
  98.     $telle = $telle - 1 ; subtract one, because of reasons and stuff
  99.     $oldName = _ArrayToString($split, "", $telle) ; convert the array part with the information i need.
  100.     $fileEnding = StringRegExp($path,'\.ogm|\.avi|\.mkv|\.wmv',2)
  101.     $fileEnding = _ArrayToString($fileEnding,"") ; fetch the fileending
  102.     If $telle >= 2 Then
  103.         $oldPath = _ArrayToString($split, "\", 0, $telle - 1) ; get the path?
  104.     Else
  105.         $oldPath = $split[0]
  106.     EndIf
  107.     $oldPath = $oldPath & "\"
  108. EndFunc   ;==>_getfileinfo
  109.  
  110. Func _getFilepath() ; procures the path of the file you need to change the name of.
  111.     $path = FileOpenDialog("Select file", "x:\", "Video (*.mp4;*.mkv;*.avi;*.ogm;*.wmv)", 1 + 4)
  112.     GUICtrlSetData($filePath, $path)
  113.     ConsoleWrite($path)
  114. EndFunc   ;==>_getFilepath
  115.  
  116. Func _FileRename_($s_Source, $s_Destination, $i_Flag = 0) ; flag = 0 default (do not overwrite existing files) | flag = 1 (overwrite file) | flag = 8 (create path if it does not exist)
  117.     Return FileMove($s_Source, $s_Destination, $i_Flag) ; function by MrCreatoR @ the autoit forums
  118. EndFunc   ;==>_FileRename_
  119.  
  120. Func _episodes() ; get the episode names from ANN
  121.     GUICtrlSetData($statusLabel, "Data fetching progress: Working...")
  122.     Local $dataz
  123.     local $episodenumber
  124.     Local $resultData
  125.     Dim $regClean
  126.     Dim $getTables
  127.     $oTable = _IETableGetCollection($oIE, 7);the tablenumber on the webiste that lists the episodes
  128.     $getTables = _IETableWriteToArray($oTable)
  129.     ;_ArrayDisplay($getTables)
  130.     GUICtrlSetData($statusLabel, "Data fetching progress: Starting episode retrieval.")
  131.     FileOpen($filename, 2)
  132.     For $kolonne = 0 To UBound($getTables, 1) - 1
  133.         $resultData = $resultData & @LF
  134.         For $rad = 0 To UBound($getTables, 2) - 1
  135.             $episodenumber = $getTables[1][$rad] & " "
  136.             $episodenumber = StringRegExp($episodenumber,'\d{1,}',2)
  137.             $resultData = $getTables[3][$rad] & " "
  138.             $regClean = StringRegExp($resultData, '.+\n|.+\r', 2)
  139.             FileWrite($filename, $episodenumber[0] & " - " & $regClean[0])
  140.         Next
  141.     Next
  142.  
  143. ;   $episodenumber = $getTables[1][$rad] & " "
  144.     FileClose($filename)
  145.     GUICtrlSetData($statusLabel, "Data fetching progress: Episode listing fetched")
  146. EndFunc   ;==>_episodes
  147.  
  148. Func _findAnime() ;function for locating the anime
  149.     Local $choice
  150.     If GUICtrlRead($anime) = 1 Then ; decide if its manga or anime you search for
  151.         $choice = "tv"
  152.     Else
  153.         $choice = "manga"
  154.     EndIf
  155.     $readData = GUICtrlRead($nameInputTxt); read the name of the show, user input required
  156.     GUICtrlSetData($statusLabel, "Data fetching progress: Locating " & $readData & ".")
  157.     Local $urlread
  158.     Local $resultData
  159.     Local $latency = "5000" ; if needed, will add option to ask for it later
  160.     $searchVar = $SearchURL & $readData & " " & $choice ; combine name of show and search string to produce a valid URL
  161.     _IENavigate($oIE, $searchVar)
  162.     GUICtrlSetData($statusLabel, "Data fetching progress: Reading data.")
  163.     $resultData = _IEPropertyGet($oIE, "outerhtml")
  164.     $urlread = BinaryToString($resultData, 4) ; convert to usable data
  165.     Dim $regex[1]
  166.     $regex = StringRegExp($urlread, 'id=\d{1,6}', 2) ; extracting the ID of the anime from the data collected, it assumes first hit is correct.
  167.     ;_ArrayDisplay($regex)
  168.     $annURL = "http://www.animenewsnetwork.com/encyclopedia/anime.php?" ; just the default url for everything
  169.     $episodes = "&page=25" ; this one seems to be the default for all episode listings, for every show
  170.     $complete = $annURL & $regex[0] & $episodes ; combine the results of regex and everything
  171.     _IENavigate($oIE, $complete)
  172.     GUICtrlSetData($statusLabel, "Data fetching progress: Completed phase 1")
  173.     GUICtrlSetState($tableParse, $GUI_ENABLE)
  174. EndFunc   ;==>_findAnime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement