Gå til innhold

[autoit] Anime episode navn verktøy


Anbefalte innlegg

Holder på med å skrive et verktøy som lar meg hente informasjon om en anime serie fra nett, så ta den informasjonen og deretter endre filnavnet slik at det blir mer informativt.

 

For eksempel :

[A-Kraze]_Seirei_no_Moribito_-_04_[E2B27ECF].mkv

^ en tilfeldig fil valgt fra en serie

 

 

Ta navnet fra den serien, hente informasjonen fra en nettside og lagre den slik ca i ett variabel:

 

"04 Torogai's Writings"

 

Så skal programmet endre filnavnet fra det orginale over til noe slikt som dette:

 

Seirei no Moribito - 04 - Torogai's Writings.mkv

 

Koden skrevet ligger i spoilern.

 

beklageligvis krever denne koden en aktiv IE installasjon på din maskin, så de av dere som har deaktivert IE via legg til/fjern programmer, må desverre aktivere den igjen for å teste. Den innebygde inetread funksjonen var ikke "god" nok for mitt bruk, så da var _ie funksjonene neste alternativ.

 

 

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <array.au3>

#region Interface
$MainForm = GUICreate("Anime episode renamer", 439, 130, 192, 124)
$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)
$searchURL = "http://www.animenewsnetwork.com/search?q="
$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)
GUISetState(@SW_SHOW)
#endregion Interface

While 1
$nMsg = GUIGetMsg()
	Switch $nMsg
		 Case $GUI_EVENT_CLOSE
			 Exit
		 Case $getDataBtn
			 _findAnime() ; runs the anime finder function - somehow its defective now...
	 EndSwitch
WEnd


Func _findAnime() ;function for locating the anime
	 $readData = GUICtrlRead($nameInputTxt) ; read the name of the show, user input required
	 $searchVar = $searchURL & $readData ; combine name of show and search string to produce a valid URL
	 ;$urlfix = _IECreate($searchVar,0,0) ; one of many attempts to defeat errors, disregard for now.
	  $urlread = _IEDocReadHTML($searchVar) ; read the page's html for the info i need.
	  $resultData = BinaryToString($urlread, 4) ; convert to usable data
	  Dim $fileVar
	  $fileVar = $SaveFileBox ; get filename for temporary storage
	  FileOpen($fileVar, 2)
	  FileWrite($fileVar, $resultData)
	  Dim $tempvar = ""
	  $propGet = _IECreate($searchVar, 0, 1) ; here i fetch the property i later have to go all REGEX on.
	  GUICtrlSetData($SaveFileBox, "Waiting.") ; just a bit of feedback to user
	  Sleep(500)
	  $outHTML = _IEPropertyGet($propGet, "outerhtml") ; finally loaded the page in the "hidden IE window", getting the bit where my data is.
	  GUICtrlSetData($SaveFileBox, "Waiting..")
	  Sleep(2000)
	  GUICtrlSetData($SaveFileBox, "fetching website")
	  Sleep(5000)
	  Dim $regex[1]
	  $regex = StringRegExp($outHTML, 'id=\d{1,6}', 2) ; extracting the ID of the anime from the data collected, it assumes first hit is correct.
	  Sleep(500)
	  $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
	  $ffs = $annURL & $regex[0] & $episodes ; combine the results ofthe r
	  $2ndLoad = _IECreate($ffs, 0, 1)
EndFunc ;==>_findAnime

 

 

 

Denne koden fungerte fint her om dagen, men nå er den plutselig defekt.

 

I mellomtiden har jeg sett nærmere på å hente ut informasjonen som ligger i en tabell og lagre denne i et array.

 

 

_IEAttach(
dim $getTables[3] ; randomly selected number as i am not 100% certain of how to work with arrays yet
dim $tables[4] ; see comment above.
$getTables = _IETableGetCollection($ffs,0) ; read the tables from the url in the $ffs variable, then all lines to follow is trying to get tables out of the thing
ConsoleWrite($getTables)
$tables = _IETableWriteToArray($getTables)
urlread = _IEBodyReadHTML($2ndLoad)
;ConsoleWrite($urlread)
_ArrayDisplay($urlread)

 

 

 

Denne koden skal til legges till i _findAnime funksjonen når jeg løser crashen.

 

Intill da er den lagt på is, er ikke mye vits i å legge til funksjoner når programmet kræsjer før man kommer så langt.

 

Appropå kræsj,

 

Dette er outputten

 

--> IE.au3 V2.4-0 Error from function _IEDocReadHTML, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IECreate (Browser Object Creation Failed)
--> IE.au3 V2.4-0 Error from function _IEPropertyGet, $_IEStatus_InvalidDataType
****\anime episode renamer.au3 (62) : ==> Subscript used with non-Array variable.:
$ffs = $annURL & $regex[0] & $episodes
$ffs = $annURL & $regex^ ERROR

 

 

All input og hjelp mottas med stor takknemlighet.

Lenke til kommentar
  • 2 uker senere...
Videoannonse
Annonse

Hær va det ikke mye interesse nei, men har nu kommet en del nermere sluttresultate æ jakte på.

Hær e i allefall koden min så langt, kos dokker.

 

 

 

#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!", 533, 192, 192, 124)
$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("Completed", 186, 143, 206, 25)
$oIE = _IECreateEmbedded() ;making an embedded ie window
GUICtrlCreateObj($oIE,500,500,0,0) ; moving said window out of the way
GUISetState(@SW_SHOW)
#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
#endregion
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
 ;$change og $result
EndSwitch
WEnd
Func _getfileinfo() ; get the filename and the path 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.
if $telle >= 2 then
 $oldPath = _ArrayToString($split,"\",0, $telle - 1) ; get the path?
  else
 $oldPath = $split[0]
EndIf
$oldPath = $oldPath & "\"
ConsoleWrite(@CRLF & @CRLF & $oldPath & @CRLF)
ConsoleWrite(@CRLF & $oldname & @CRLF)
EndFunc
Func _getFilepath() ; procures the path of the file you need to change the name of.
local $path
 $path = FileOpenDialog("Select file","x:\", "Video (*.mp4;*.mkv;*.avi)",1+4)
GUICtrlSetData($filePath, $path)
ConsoleWrite($path)
EndFunc
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
Func _episodes() ; get the episode names from ANN
GUICtrlSetData($statusLabel,"Data fetching progress: Working...")
local $dataz
local $filename = "dataz.txt"
local $resultData
dim $regClean
dim $getTables
$oTable = _IETableGetCollection($oIE,7)
$getTables = _IETableWriteToArray($oTable)
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
   $resultData = $getTables[3][$rad] & " "
   $regClean = StringRegExp($resultData,'.+\n|.+\r',2)
   FileWrite($filename,$regClean[0])
  Next
 Next
GUICtrlSetData($statusLabel,"Data fetching progress: Episode listing fetched")
EndFunc
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

 

Endret av Dwagon
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...