Jump to content

Anime lookup and episode renamer (WIP)


TagK
 Share

Recommended Posts

So, I am an anime nerd.

I decided to make myself a tool, that fetches the episode information from a certain anime i provide the name of. Store the data in a csv file and then eventually rename the files in a "proper" fashion. . I typed out a lot of comments, in order for myself to keep track. A bit excessive probably but better than none i guess.

Example :

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

^ a randomly selected file

Take that show name, fetch the episode information from the website and store it like this kinda

"04 Torogai's Writings"

Then change the filename to

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

Here is what I have written so far.

___ work in progress ___

#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("Url Downloader", 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) ; will eventually be the progress thing. placeholder for now
$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 defect 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.
;ConsoleWrite($outHTML)
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)
;ConsoleWrite($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
$ffs = $annURL & $regex[0]& $episodes ; combine the results of the regex with the 2 previous url variables. I was a bit annoyed when i made this, will change it later.
$2ndLoad = _IECreate($ffs, 0, 1) ; show the episode page.

EndFunc ;==>_findAnime

That code worked earlier today, but somehow it no longer does, I have no idea why. But I have probably been sitting to long with this to see it. Probably something basic somewhere.

The next step is to get the episode data from the page. They have stored it in tables

so I figured this should do it, if i where to add it to my function in the code above. But after messing around a bit. Failing to understand the errors, I learned I needed to attach and create certain objects and I ground to a halt as its late.

_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)

My todo list at the moment is:

Fix the finder

add episode retriever

Allow user to decide between anime and manga

add rename module / 50%

add filescanner for locating episodes based on a folder selection

So if any of you have any tips, feedback or something else. I would love to hear it.

Current full code as of 19.09 2012

#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

https://www.dropbox.com/sh/oinuqnklegri31n/mHRO6zct0Q

^Dropbox of my development folder, has a compiled version, and a tiny howto image, started with version numbers and so on.

Edited by TagK

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

I cannot see an edit post button :thumbsdown: , but I have fixed one of the typing mistakes in the code

$fileVar = $SaveFileBox ; get filename for temporary storage <- This one is now fixed, also known as line 43 inside the _findAnime function,

--> 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
****\Url Downloader.au3 (62) : ==> Subscript used with non-Array variable.:
$ffs = $annURL & $regex[0] & $episodes
$ffs = $annURL & $regex^ ERROR

These are the errors I am working with, I cannot fathom how the regex variable suddenly is no longer an array. If I where to guess... it would be that the website does not load fast enough or something.

The _IE errors, well they just appeared recently, but they have not caused the app to crash, only the regex array has.

This post was originally ment to be edited in the one above, but I do not see an edit button. Probably have to be approved by the admins to get that. So for now, excuse the double post.

"updated" code below:

#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("Url Downloader", 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 = "https://www.google.no/search?q="
$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 fucked now...
;ConsoleWrite($resultData)

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.
;ConsoleWrite($outHTML)
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)
;ConsoleWrite($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
$ffs = $annURL & $regex[0] & $episodes ; combine the results ofthe r
$2ndLoad = _IECreate($ffs, 0, 1)

EndFunc ;==>_findAnime

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

In terms of what you need to do next in your script I don't really have any ideas sorry however I came across something in your script that you might be able to improve on. You use _IEDocReadHTML which I think might do pretty much the same job as _INetGetSource however I am unsure on this. But the point I am trying to get across is that if you are only using the browser to get the source code of the website then _INetGetSource might be a faster option as It wont go to the bother of opening a whole internet explorer window and navigating to the website. Not sure if this is of any help but it might be or maybe I'm completely missing the point lol.

Link to comment
Share on other sites

Thanks for the reply Venix!

The reason I was not able to use the inet function, is because the website renders the information i need to get inside a javascript. And if I used _INetGetSource i just get the raw html, that calls the javascript function.

It is however possible that I have missed something in this function, so if its possible for me to extract the same information with that command, naturally i will toss that filthy IE thing out of the window and put fire to it.

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

The reason I was not able to use the inet function, is because the website renders the information i need to get inside a javascript. And if I used _INetGetSource i just get the raw html, that calls the javascript function.

I see, that explains it I guess I learn something new everyday :). Edited by Venix
Link to comment
Share on other sites

ANN doesn't have its own search function, as you see it uses a google search. You may get faster results by using a search URL like this:

SearchURL = "www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+"

So for example look at this search query:

www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+akira

http://www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+akira

This gets you the same results as using their website. It may be faster than using ANN to do the initial search for you.

You could even add what type you are looking for. For example, Akira has 2 main types of entries:

(manga)

(movie)

You could use these variables in your search query, for example:

www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+akira+(movie)

Edited by Tripredacus
Link to comment
Share on other sites

Genious, then I can get rid of that AWFUL _IE bit, I noticed they used google in their javascript, but it never dawned on me to use them myself.

I will alter my script as soon as I have eaten dinner to see what I can do next.

However, I still need to extract the tables with episode information from the animenewsnetwork site.

I'll work abit on this to see where I end up.

Thank you for the feedback Tripredacus.

Edit:

It seems the google results also are in javascript, so I still have to use the ie library, but at least it seems faster.

I'm going to work a bit more on this, to see if there are any loopholes I can use.

Edit 2

This is so much fun now that I have a source that responds in a timely fashion.

This is the current state of the _findAnime function. I it appears to be stable.

Now I just need to get the tables to work the way I want, in order to get this to work without opening a window of IE on your desktop, I created a 0x0 pixel embedded browser in the UI, and moved it 500 pixels out of frame.

$oIE = _IECreateEmbedded()

GUICtrlCreateObj($oIE,500,500,0,0)

Func _findAnime() ;function for locating the anime
local $urlread
$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
ConsoleWrite($searchVar)
$resultData = _IENavigate($oIE,$searchVar)
$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.
$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
$resultData = _IENavigate($oIE,$complete)
$resultData = _IETableGetCollection($oIE,"0")
$tables = _IETableWriteToArray($resultData, True)
EndFunc

Edit 3 :P I do love that edit button.

I have learned that I need to access the table below, so if any of you have a trick that will allow this, I am most appriciative. Its like the 10th or so table in the source code.

<TABLE CLASS="episode-list" BORDER=0 CELLSPACING=0>

I was thinking of downloading the source, locating that class with regex, then extract everything untill the end of the table, then store that and create a new object for the IE to take care and then read into an array.

Probably the most cumbersome way to do this. So I am open to suggestions.

Edit 4 - "A new dawn, but someone pooped in my milk"

Found a way to get hold of the table information using regex, but sadly something, and i believe its animenewsnetwork's page is so unreliable, that my $regex array turns up empty, and thus the tool fails.

This happens now and then, basically halts my trials. But I can bypass this and just "get" the source manually, then work on a separate script to work out the kinks in reading the episode data into something usable.

*brains hard*

Edited by TagK

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

Excuse the doublepost, but the edits was getting lengthy.

I have written a function that gets the information i need, well at least kinda.

I need it to loop so that it keeps reading into the sourcefile and just keeps saving the matches to my regex.

Is there a way to add "do this to the entire file" in autoit with regex?

#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!", 532, 164, 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)
$Radio1 = GUICtrlCreateRadio("Anime Show", 416, 16, 113, 17); to be used later
GUICtrlSetState($Radio1,True) ; setting anime as default
$Radio2 = GUICtrlCreateRadio("Manga", 416, 32, 113, 17); to be used later
$tableParse = GUICtrlCreateButton("Table thing", 32, 112, 75, 25)
GUISetState(@SW_SHOW)
$oIE = _IECreateEmbedded() ;making an embedded ie window
GUICtrlCreateObj($oIE,500,500,0,0) ; moving said window out of the way
#endregion Interface

#region variables

Global $SearchURL = "www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+"

#endregion

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


Func _episodes()
local $dataz
local $filename = "dataz.txt"
local $resultData
Local $complete ; temporary to test, will eventually add global to it
$complete = "www.animenewsnetwork.com/encyclopedia/anime.php?id=1139&page=25"
$resultData = _IENavigate($oIE,$complete)
$resultData = _IEBodyReadHTML($oIE)
FileOpen("tableS.txt",2)
FileWrite("tableS.txt", $resultData)
FileClose("tableS.txt")
FileOpen($filename,1)
$dataz = StringRegExp($resultData,'<DIV>\w+.+</DIV>', 2)
_FileWriteFromArray($filename,$dataz)
FileClose($filename)
GUICtrlSetData($SaveFileBox,"Done...")
EndFunc


Func _findAnime() ;function for locating the anime
local $urlread
Local $resultData
local $latency = "000" ; if needed, will add option to ask for it later
$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
ConsoleWrite($searchVar)
_IENavigate($oIE,$searchVar)
;Sleep($latency)
_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)
Sleep($latency)
$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
ConsoleWrite($complete)
_IENavigate($oIE,$complete)
;_IEQuit($oIE)
Sleep($latency)
$getTables = _INetGetSource($complete)
FileOpen("kilde.txt",2)
FileWrite("kilde.txt",$getTables)
FileClose("kilde.txt")
ConsoleWrite("done")
;$resultData = _IETableGetCollection($oIE,"0")
;$tables = _IETableWriteToArray($resultData, False)
;_ArrayDisplay($tables)
EndFunc ;==>_findAnime

I have been looking into this :

While 1
Local $line = FileReadLine($file)
If @error = -1 Then ExitLoop
MsgBox(0, "Line read:", $line)
WEnd

from the help file, but whenewer i try this, i get an infinite loop, it does not read the "eof" from the file for some reason, I dont see where I am doing it wrong.

FileOpen($filename,1)
While 1
Local $line = FileReadLine($filename)
If @error = -1 Then ExitLoop
$dataz = StringRegExp($resultData,'<DIV>\w+.+</DIV>', 2)
_FileWriteFromArray($filename,$dataz)
WEnd
FileClose($filename)

Thanks for reading.

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

  • 2 weeks later...

I was always thinkign of making an Anime list program that keep track of the anime you have seen; put it into a list, and sort it into Genre, but, for on-going anime, this would be an awesome way to check for updates to see if a new ep has been made.

^_^

Yeah, that is part of the plan, eventually.

If you want to keep track of whats going on you can always check the current version in my dropbox.

This is anyway the current look of the app, if you wonder why the buttons are grayed out, its because they are enabled in sequence to make sure you do it the right order. :)

Posted Image

#cs ---------------
Anime tool, work in progress.

By Tommy Asmund Gunnar Kristiansen - September 2012
#ce ---------------


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <IE.au3>
#include <Inet.au3>
#include <array.au3>
#include <file.au3>
#region Interface ; all the stuff, with a bunch of x,y width, height coordinates and so on
$MainForm = GUICreate("Anime rename tool! ---Work In Progress---", 835, 651, 791, 177)
GUISetIcon(@ScriptDir & "Luffys-flag-2.ico", -1)
$nameInputTxt = GUICtrlCreateInput("Type Name Here", 24, 16, 377, 21)
$getDataBtn = GUICtrlCreateButton("Fetch data", 24, 48, 80, 25)
$statusLabel = GUICtrlCreateLabel("Data fetching progress: Idle", 106, 53, 299, 24)
$anime = GUICtrlCreateRadio("Anime Show", 416, 16, 113, 17)
GUICtrlSetState($anime, True) ; setting anime as default
$manga = GUICtrlCreateRadio("Manga", 416, 32, 113, 17)
$tableParse = GUICtrlCreateButton("Get episode list", 24, 80, 80, 25)
$getFile = GUICtrlCreateButton("Select file", 104, 80, 80, 25)
$filePath = GUICtrlCreateLabel("Here is the path to the file", 184, 80, 650, 20)
$change = GUICtrlCreateButton("Read path", 105, 105, 80, 25)
$result = GUICtrlCreateLabel("", 186, 105, 299, 25)
$oIE = _IECreateEmbedded() ;making an embedded ie window
GUICtrlCreateObj($oIE, 99999, 99999, 0, 0) ; moving said window out of the way
$credits = GUICtrlCreateLabel("Anime rename tool by Tommy Asmund Gunnar Kristiansen", 220, 630, 400, 17, BitOR($SS_CENTER, $SS_SUNKEN))
$EpisodeListBox = GUICtrlCreateList("", 8, 176, 377, 422, BitOR($WS_BORDER, $WS_VSCROLL))
GUICtrlSetData(-1, "")
$FileListBox = GUICtrlCreateList("", 416, 176, 369, 422, BitOR($WS_BORDER, $WS_VSCROLL))
$listboxlabelEpisode = GUICtrlCreateLabel("Below will the episodes found be listed.", 16, 152, 188, 17)
$listboxlabelFiles = GUICtrlCreateLabel("Below the files found will be listed.", 456, 152, 164, 17)
$PreviewName = GUICtrlCreateButton("Preview names", 24, 105, 80, 25)
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 - the full path to the file. ex : c:animeshownamefilename.mp4
Global $oldPath ; old file path - the one that is without the filename ex : c:animeshowname
Global $fileEnding ; the file ending, like avi, mkv and so on.
Global $filename = "dataz.txt" ; the filename i use to store the dataz in.
Global $readData ; variable for storing data in basically
Global $s_Destination ; variable for the final name change of the file
#endregion variables

GUICtrlSetState($tableParse, $GUI_DISABLE) ; disable all the buttons but the first one, so that you have to do stuff in the correct order.
GUICtrlSetState($getFile, $GUI_DISABLE) ; ^
GUICtrlSetState($change, $GUI_DISABLE) ; ^
GUICtrlSetState($PreviewName, $GUI_DISABLE) ; ^


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
FileRecycle($filename)
Exit
Case $getDataBtn
_findAnime() ; runs the anime finder function
Case $tableParse
_episodes() ; runs the episode parsing function
Case $getFile
_getFilepath()
_getfileinfo()
_tName()
Case $change
_magic()
;_FileRename_($path, $s_Destination)
GUICtrlSetData($result, $oldPath & $s_Destination)
Case $PreviewName
MsgBox(0,"Not functional yet","Normally, this would change the right side list to show what the new names would be." & @CRLF _
& "Then allow you to say if you want this or not and finally save the new filenames to disk.")
EndSwitch
WEnd

Func _magic() ; call the array $filelist to get the name of ALL the files in the directory.
Local $telle
local $test
Local $skriv
Local $mappe
local $Trash[2]
$Trash[0] = "Thumbs.db"
$Trash[1] = ".sfv"

local $filelist = _FileListToArray($oldPath) ; read filenames from the path to array
GUICtrlSetData($FileListBox,"") ; clean out the listbox ready for a new set of entries
$derp = _ArrayToString($filelist,", ",1)
$episodetall = StringRegExp($derp,'s-s(d{1,})|_(d{1,})_?[',3)


while 1
$telle = 0
$findTrash = _ArraySearch($filelist,$Trash[$telle])
;ConsoleWrite(@CRLF & @CRLF & $findTrash)
if $findTrash > 0 Then
_ArrayDelete($filelist,$findTrash)
Else
ExitLoop

EndIf
$telle = $telle + 1
WEnd
_ArrayDelete($filelist, 0)
$mappe = UBound($filelist) -1
for $telle = 0 to $mappe
GUICtrlSetData($FileListBox,$filelist[$telle]) ; write the array to the listbox, for the filenames
Next

GUICtrlSetState($PreviewName, $GUI_ENABLE) ; enable the button
EndFunc

Func _tName(); New name creation system
$s_Destination = ""
$file = FileOpen(@ScriptDir &""& $filename) ; open the file "dataz.txt" in the same directory as the script is in ----- Maybe alter to read from listbox
$newName = FileReadLine($file,1) ; read the first line of information in the file, to be later expanded to keep reading
If $file = -1 Then ; breaks out of the application if it fails
MsgBox(0, "Error", "Unable to open the DATAZ.txt file, closing program.")
Exit
EndIf
$newName = $readData & " - " & $newName ; combining search name and episode name from file
$newName = StringTrimRight($newName,1) ; remove an extra space from the end of the string, happens due to how the tables are downloaded and stored.
$s_Destination = $newName & $fileEnding ; final combine of strings to produce the final name
FileClose($filename) ; close open file
FileRecycle($filename) ; delete it
EndFunc ;==> _tName

Func _getfileinfo() ; get the filename and the path of the file, and then the ending of the file
$path = GUICtrlRead($filePath) ; read the filepath you just gave it
$split = StringSplit($path, "", 2) ; read the entire path into an array, sepparated by the  delimiter.
$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) ; looking for the various file endings it supports for now, can be expanded later
$fileEnding = _ArrayToString($fileEnding,"") ; Store the file type in a standard variable
If $telle >= 2 Then ; figure out how to best split the path
$oldPath = _ArrayToString($split, "", 0, $telle - 1) ; get the path based on earlier split variable
Else
$oldPath = $split[0]
EndIf
$oldPath = $oldPath & "" ; add a  to the end of the path, for example "C:path" to "C:path" - this is to make the file rename later possible
GUICtrlSetState($change, $GUI_ENABLE) ; enable the next button
EndFunc ;==>_getfileinfo
;==>_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) ; read the tables from internet explored module
GUICtrlSetData($statusLabel, "Data fetching progress: Starting episode retrieval.")
FileOpen($filename, 2) ; create the file for storing the results of the tables
For $kolonne = 0 To UBound($getTables, 1) - 1 ; count how many types of data there is in the table
$resultData = $resultData & @LF
Next


For $rad = 0 To UBound($getTables, 2) - 1 ; counts how many parts there is to the array
$episodenumber = $getTables[1][$rad] & " " ; figure out how many episodes there are
$episodenumber = StringRegExp($episodenumber,'d{1,}',2) ; fetch the episode number without any additional bits, and store it.
$resultData = $getTables[3][$rad] & " " ; get the episode name from the array and store it
$regClean = StringRegExp($resultData, '.+n|.+r', 2) ; clean the name up a bit
FileWrite($filename, $episodenumber[0] & " - " & $regClean[0]) ; write a temporary file with the dataz in it.
$dataz = $episodenumber[0] & " - " & $regClean[0]
GUICtrlSetData($EpisodeListBox,$dataz) ; populates the listview
_ArrayAdd($resultData,$dataz)
Next
_ArrayDisplay($resultData)

FileClose($filename) ; close the file
GUICtrlSetData($statusLabel, "Data fetching progress: Episode listing fetched")
GUICtrlSetState($getFile, $GUI_ENABLE) ; enable the next button
EndFunc ;==>_episodes

#cs ---------------

COMPLETED FUNCTIONS BELOW THIS MARKER!!!!

#ce ----------------


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) ; initiate the search system by feeding the search variable to the IE window hidden in the app
GUICtrlSetData($statusLabel, "Data fetching progress: Reading data.")
$resultData = _IEPropertyGet($oIE, "outerhtml") ; read the html result as if we where looking at the page
$urlread = BinaryToString($resultData, 4) ; convert to usable data
Dim $regex[1] ; just creating an array for storing the data from the search
$regex = StringRegExp($urlread, 'id=d{1,6}', 2) ; extracting the ID of the anime from the data collected, it assumes first hit is correct.
$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) ; go to the episode listing page.
GUICtrlSetData($statusLabel, "Data fetching progress: Found and stored the information")
GUICtrlSetState($tableParse, $GUI_ENABLE) ; the next button enables itself
EndFunc ;==>_findAnime

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) ; openfile dialoge window, allows multiple file selections, but must have at least one.
GUICtrlSetData($filePath, $path) ; writes the original filename and path into a label
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

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...