Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_Icon=Luffys-flag-2.ico
- #AutoIt3Wrapper_Res_Description=Anime information tool, designed to fetch episode information and then process files.
- #AutoIt3Wrapper_Res_Fileversion=0.1.0.2
- #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
- #AutoIt3Wrapper_Res_Language=1033
- #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <IE.au3>
- #include <Inet.au3>
- #include <array.au3>
- #include <file.au3>
- #region Interface
- $MainForm = GUICreate("Anime info gatherer!", 531, 218, 192, 124)
- GUISetIcon(@ScriptDir & "\Luffys-flag-2.ico", -1)
- $nameInputTxt = GUICtrlCreateInput("Type Name Here", 24, 16, 377, 21)
- $getDataBtn = GUICtrlCreateButton("Fetch data", 24, 48, 75, 25)
- $statusLabel = GUICtrlCreateLabel("Data fetching progress: Completed / Progress / Writing to CSV", 106, 53, 299, 24)
- $SaveFileBox = GUICtrlCreateInput("", 32, 80, 90, 21)
- $SavefileLabel = GUICtrlCreateLabel("Type the name of the file for temporary storage, testing only, .txt is added automatically", 125, 80, 249, 36)
- $anime = GUICtrlCreateRadio("Anime Show", 416, 16, 113, 17); to be used later
- GUICtrlSetState($anime, True) ; setting anime as default
- $manga = GUICtrlCreateRadio("Manga", 416, 32, 113, 17); to be used later
- $tableParse = GUICtrlCreateButton("Table thing", 24, 112, 75, 25)
- $getFile = GUICtrlCreateButton("Get file", 104, 112, 75, 25)
- $filePath = GUICtrlCreateLabel("Path : ", 184, 112, 350, 20)
- $change = GUICtrlCreateButton("Rename it", 106, 143, 75, 25)
- $result = GUICtrlCreateLabel("", 186, 143, 206, 25)
- $oIE = _IECreateEmbedded() ;making an embedded ie window
- GUICtrlCreateObj($oIE, 500, 500, 0, 0) ; moving said window out of the way
- $credits = GUICtrlCreateLabel("Anime info gatherer by Tommy Asmund Gunnar Kristiansen", 0, 200, 530, 17, BitOR($SS_CENTER, $SS_SUNKEN))
- GUICtrlSetState(-1, $GUI_DISABLE)
- GUICtrlSetTip(-1, "Duuh, I made this, what did you expect?")
- GUISetState(@SW_SHOW)
- TraySetState(2)
- #endregion Interface
- #region variables
- Global $SearchURL = "www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+"
- Global $oldName ; the old filename
- Global $newName ; and the new one
- Global $path ; path to file
- Global $oldPath
- Global $fileEnding ; the file ending, like avi, mkv and so on.
- Global $filename = "dataz.txt"
- Global $readData
- Global $s_Destination
- #endregion variables
- GUICtrlSetState($tableParse, $GUI_DISABLE)
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $getDataBtn
- _findAnime() ; runs the anime finder function
- Case $tableParse
- _episodes() ; runs the episode parsing function
- Case $getFile
- _getFilepath()
- _getfileinfo()
- Case $change
- _tName()
- ;$s_Destination = "Great Teacher Onizuka - The Legend Begins.ogm"
- _FileRename_($path, $s_Destination)
- GUICtrlSetData($result, "File has been renamed to " & $s_Destination)
- EndSwitch
- WEnd
- Func _tName(); function to test rename system
- $s_Destination = ""
- $file = FileOpen(@ScriptDir &"\"& $filename)
- $newName = FileReadLine($file,1)
- If $file = -1 Then
- MsgBox(0, "Error", "Unable to open file.")
- Exit
- EndIf
- GUICtrlSetData($SaveFileBox,$newName)
- $newName = $readData & " - " & $newName
- $s_Destination = $newName & $fileEnding
- FileClose($filename)
- FileRecycle($filename)
- EndFunc
- Func _getfileinfo() ; get the filename and the path of the file, and then the ending of the file
- Local $path
- $path = GUICtrlRead($filePath)
- $split = StringSplit($path, "\", 2)
- $telle = UBound($split) ; figure out how "big" the array is, then set that number to the $telle variable
- $telle = $telle - 1 ; subtract one, because of reasons and stuff
- $oldName = _ArrayToString($split, "", $telle) ; convert the array part with the information i need.
- $fileEnding = StringRegExp($path,'\.ogm|\.avi|\.mkv|\.wmv',2)
- $fileEnding = _ArrayToString($fileEnding,"") ; fetch the fileending
- If $telle >= 2 Then
- $oldPath = _ArrayToString($split, "\", 0, $telle - 1) ; get the path?
- Else
- $oldPath = $split[0]
- EndIf
- $oldPath = $oldPath & "\"
- EndFunc ;==>_getfileinfo
- Func _getFilepath() ; procures the path of the file you need to change the name of.
- $path = FileOpenDialog("Select file", "x:\", "Video (*.mp4;*.mkv;*.avi;*.ogm;*.wmv)", 1 + 4)
- GUICtrlSetData($filePath, $path)
- ConsoleWrite($path)
- EndFunc ;==>_getFilepath
- 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)
- Return FileMove($s_Source, $s_Destination, $i_Flag) ; function by MrCreatoR @ the autoit forums
- EndFunc ;==>_FileRename_
- Func _episodes() ; get the episode names from ANN
- GUICtrlSetData($statusLabel, "Data fetching progress: Working...")
- Local $dataz
- local $episodenumber
- Local $resultData
- Dim $regClean
- Dim $getTables
- $oTable = _IETableGetCollection($oIE, 7);the tablenumber on the webiste that lists the episodes
- $getTables = _IETableWriteToArray($oTable)
- ;_ArrayDisplay($getTables)
- GUICtrlSetData($statusLabel, "Data fetching progress: Starting episode retrieval.")
- FileOpen($filename, 2)
- For $kolonne = 0 To UBound($getTables, 1) - 1
- $resultData = $resultData & @LF
- For $rad = 0 To UBound($getTables, 2) - 1
- $episodenumber = $getTables[1][$rad] & " "
- $episodenumber = StringRegExp($episodenumber,'\d{1,}',2)
- $resultData = $getTables[3][$rad] & " "
- $regClean = StringRegExp($resultData, '.+\n|.+\r', 2)
- FileWrite($filename, $episodenumber[0] & " - " & $regClean[0])
- Next
- Next
- ; $episodenumber = $getTables[1][$rad] & " "
- FileClose($filename)
- GUICtrlSetData($statusLabel, "Data fetching progress: Episode listing fetched")
- EndFunc ;==>_episodes
- Func _findAnime() ;function for locating the anime
- Local $choice
- If GUICtrlRead($anime) = 1 Then ; decide if its manga or anime you search for
- $choice = "tv"
- Else
- $choice = "manga"
- EndIf
- $readData = GUICtrlRead($nameInputTxt); read the name of the show, user input required
- GUICtrlSetData($statusLabel, "Data fetching progress: Locating " & $readData & ".")
- Local $urlread
- Local $resultData
- Local $latency = "5000" ; if needed, will add option to ask for it later
- $searchVar = $SearchURL & $readData & " " & $choice ; combine name of show and search string to produce a valid URL
- _IENavigate($oIE, $searchVar)
- GUICtrlSetData($statusLabel, "Data fetching progress: Reading data.")
- $resultData = _IEPropertyGet($oIE, "outerhtml")
- $urlread = BinaryToString($resultData, 4) ; convert to usable data
- Dim $regex[1]
- $regex = StringRegExp($urlread, 'id=\d{1,6}', 2) ; extracting the ID of the anime from the data collected, it assumes first hit is correct.
- ;_ArrayDisplay($regex)
- $annURL = "http://www.animenewsnetwork.com/encyclopedia/anime.php?" ; just the default url for everything
- $episodes = "&page=25" ; this one seems to be the default for all episode listings, for every show
- $complete = $annURL & $regex[0] & $episodes ; combine the results of regex and everything
- _IENavigate($oIE, $complete)
- GUICtrlSetData($statusLabel, "Data fetching progress: Completed phase 1")
- GUICtrlSetState($tableParse, $GUI_ENABLE)
- EndFunc ;==>_findAnime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement