Gibbo Posted January 31, 2007 Share Posted January 31, 2007 I would have liked to post this in scripts and scraps, but the forum wont let me. Perhaps I am to new (this is my first post :"> ) Anyhow, here is the script. If anyone has any ideas or suggestions to improve it PLEASE let me know. (I am feeling like alot of it is a Kludge) CODE#include <IE.au3> $url = InputBox("Webpage", "Enter Website", ClipGet()) $baseDir = InputBox("BaseDir", "Enter Directory", "D:\EpisodeWorld\") $oIE = _IECreate($url) $aTitle = _GetTitle($oIE) $name = _CleanFilename($aTitle[1]) $status = $aTitle[2] $year = $aTitle[3] $season = _GetSeason($oIE) $totalSeasons = @extended $plot = _GetPlot($oIE) $aEpisodes = _GetEpisodes($oIE) _IEQuit($oIE) $titleDir = $baseDir & $name & " (" & $year & ")" DirCreate($titleDir) _WritePlot($plot, $titleDir) _CreateSeasons($season, $totalSeasons, $titleDir) _CreateEpisodes($aEpisodes, $titleDir, $name, $season) Func _CreateEpisodes($aEpisodes, $titleDir, $name, $season) $cols = UBound($aEpisodes) $rows = UBound($aEpisodes, 2) $dims = UBound($aEpisodes, 0) $output = "" For $r = 0 To UBound($aEpisodes, 2) - 1 $output = $output & @LF For $c = 0 To UBound($aEpisodes, 1) - 1 $aEpisodes[$c][$r] = StringStripWS($aEpisodes[$c][$r], 3) $output = $output & $aEpisodes[$c][$r] & " " Next Next ConsoleWrite($output) If $season = 0 Then $season = "1x00" Else $season = $season & "x00" EndIf $sCount = 0 $pCount = 0 For $r = 1 To UBound($aEpisodes, 2) - 1 If $season <> $aEpisodes[1][$r] Then If $aEpisodes[1][$r] <> "Special" Then If $aEpisodes[1][$r] <> "Pilot" Then $season = $aEpisodes[1][$r] EndIf EndIf If $aEpisodes[1][$r] = "Special" Then $sCount = $sCount + 1 $aEpisodes[1][$r] = $season & "[" & $sCount & "]" Else $sCount = 0 EndIf If $aEpisodes[1][$r] = "Pilot" Then $pCount = $pCount + 1 $aEpisodes[1][$r] = $season & "[" & $pCount & "]" Else $pCount = 0 EndIf $seasonDir = $titleDir & "\Season " & StringLeft($season, 1) $episode = $name & " - " & $aEpisodes[1][$r] & " - " & $aEpisodes[2][$r] $episode = _CleanFilename($episode) ; Debug line ;ConsoleWrite($seasonDir & "\" & $episode & @CR) _WriteBlank($seasonDir, $episode) Next EndFunc ;==>_CreateEpisodes Func _CleanFilename($filename) $filename = StringReplace($filename, "?", "") $filename = StringReplace($filename, "*", "") $filename = StringReplace($filename, ":", ";") $filename = StringReplace($filename, "\", ",") $filename = StringReplace($filename, "/", ",") $filename = StringReplace($filename, "|", ",") $filename = StringReplace($filename, "<", "[") $filename = StringReplace($filename, ">", "]") $filename = StringReplace($filename, '"', "'") Return $filename EndFunc ;==>_CleanFilename Func _WriteBlank($seasonDir, $episode) $file = FileOpen($seasonDir & "\" & $episode, 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to write: " & $seasonDir & "\" & $episode) Exit EndIf FileWrite($file, "") FileClose($file) EndFunc ;==>_WriteBlank Func _CreateSeasons($season, $totalSeasons, $titleDir) If $season = 0 Then For $seasonloop = 1 To $totalSeasons DirCreate($titleDir & "\Season " & $seasonloop) Next Else DirCreate($titleDir & "\Season " & $season) EndIf EndFunc ;==>_CreateSeasons Func _WritePlot($plot, $location) $file = FileOpen($location & "\plot.txt", 1) ConsoleWrite($location & "\plot.txt") ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open plot file.") Exit EndIf FileWrite($file, $plot) FileClose($file) EndFunc ;==>_WritePlot Func _GetTable($oIE, $tableNumber) $oTable = _IETableGetCollection($oIE, $tableNumber) $aTableData = _IETableWriteToArray($oTable) Return $aTableData EndFunc ;==>_GetTable Func _GetTitle($oIE) $titleTable = _GetTable($oIE, 3) $aTitle = StringSplit($titleTable[0][0], " - ", 1) ReDim $aTitle[uBound($aTitle) + 1] $aTitle[3] = StringStripWS(StringMid($aTitle[1], StringInStr($aTitle[1], "(") + 1, 4), 3) $aTitle[1] = StringStripWS(StringTrimRight($aTitle[1], StringLen($aTitle[1]) - StringInStr($aTitle[1], "(") + 2), 3) $aTitle[2] = StringStripWS($aTitle[2], 3) Return $aTitle EndFunc ;==>_GetTitle Func _GetSeason($oIE) $seasonTable = _GetTable($oIE, 2) $seasonTemp = $seasonTable[1][0] $aSeasonTemp = StringSplit($seasonTemp, @CRLF) For $seasonloop = 0 To UBound($aSeasonTemp) - 1 If StringLeft($aSeasonTemp[$seasonloop], 6) = "Season" Then $seasonTemp = $aSeasonTemp[$seasonloop] Next $seasonTemp = StringLeft($seasonTemp, StringInStr($seasonTemp, "All Seasons") - 3) $aSeasonTemp = StringSplit($seasonTemp, "-") $season = StringTrimLeft(StringStripWS($aSeasonTemp[1], 3), 7) If $season = "All" Then $season = 0 $seasons = StringStripWS($aSeasonTemp[2], 8) $aSeasons = StringSplit($seasons, "|") $maxSeason = $aSeasons[0] SetExtended($maxSeason) Return $season EndFunc ;==>_GetSeason Func _GetPlot($oIE) $plot = _GetTable($oIE, 6) Return $plot[1][0] EndFunc ;==>_GetPlot Func _GetEpisodes($oIE) $oEpisodeTable = _IEGetObjByName($oIE, "list") $episodeTable = _IETableWriteToArray($oEpisodeTable) Return $episodeTable EndFunc ;==>_GetEpisodes To use, simply visit www.episodeworld.com, look up a series you want to 'gather', and put the address from the address bar into the clipboard. then run the program. One day I would like to get my head around the GUI components and be able to make a side by side view of the episodes (on disk, and from page) and let the user match up items from one side with the other and do an auto rename. Something for the future. Link to comment Share on other sites More sharing options...
theguy0000 Posted January 31, 2007 Share Posted January 31, 2007 hmm...the post limit does seem to be causing a bit of a stir... and yes, you cannot post in example scripts until you have 10 posts. The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
Gibbo Posted February 2, 2007 Author Share Posted February 2, 2007 (edited) The second part to all this, the renamer. I'm posting my progress in the hope that someone will be able to point out better ways to do things (and perhaps to simplify the code) Also someone may find thease usefull. The program below takes the files you load into the bad names box and renames them acording to the names in the good names box. Was quite a learning experiance. CODE#include <GuiConstants.au3> #include <file.au3> #include <GuiList.au3> #Include <GuiListView.au3> #include <Math.au3> Const $defaultGoodDir = "C:\" Const $defaultBadDir = "C:\" GUICreate("MyGUI", 790, 690, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $goodNamesList = GUICtrlCreateList("", 10, 20, 370, 578) $goodNamesGroup = GUICtrlCreateGroup("Correct Names", 0, 0, 390, 640) $goodNamesOpenButton = GUICtrlCreateButton("Open Dir", 10, 600, 80, 30) $goodUpButton = GUICtrlCreateButton("Up", 210, 600, 80, 30) $goodDownButton = GUICtrlCreateButton("Down", 300, 600, 80, 30) $badNamesGroup = GUICtrlCreateGroup("Incorrect Names", 400, 0, 390, 640) $badNamesList = GUICtrlCreateList("", 410, 20, 370, 578) $badNamesOpenButton = GUICtrlCreateButton("Open Dir", 410, 600, 80, 30) $badUpButton = GUICtrlCreateButton("Up", 610, 600, 80, 30) $badDownButton = GUICtrlCreateButton("Down", 700, 600, 80, 30) $renameButton = GUICtrlCreateButton("Rename", 700, 650, 80, 30) $closeButton = GUICtrlCreateButton("Close", 10, 650, 80, 30) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $closeButton ExitLoop Case $msg = $goodNamesOpenButton $goodDir = _stripFile(FileOpenDialog("Choose Directory", $defaultGoodDir, "All (*.*)", 2)) _getFileNames($goodNamesList, $goodDir) Case $msg = $badNamesOpenButton $badDir = _stripFile(FileOpenDialog("Choose Directory", $defaultBadDir, "All (*.*)", 2)) _getFileNames($badNamesList, $badDir) Case $msg = $goodUpButton _moveListItem($goodNamesList, -1) Case $msg = $badUpButton _moveListItem($badNamesList, -1) Case $msg = $goodDownButton _moveListItem($goodNamesList, 1) Case $msg = $badDownButton _moveListItem($badNamesList, 1) Case $msg = $renameButton _rename($goodNamesList, $badNamesList, $badDir) _getFileNames($badNamesList, $badDir) Case Else ;;; EndSelect Sleep(10) WEnd Exit Func _rename($list1, $list2, $badDir) $smallestList = _Min(_GUICtrlListCount($list1), _GUICtrlListCount($list2)) ConsoleWrite($smallestList) For $file = 0 To $smallestList - 1 ConsoleWrite($badDir & _GUICtrlListGetText($list2, $file) & " , " & $badDir & _GUICtrlListGetText($list1, $file)) FileMove($badDir & _GUICtrlListGetText($list2, $file), $badDir & _GUICtrlListGetText($list1, $file)) Next EndFunc ;==>_rename Func _moveListItem($list, $direction) $itemToMove = _GUICtrlListSelectedIndex($list) Select Case $direction = -1 $limit = 0 Case $direction = 1 $limit = _GUICtrlListCount($list) Case Else Return EndSelect If $itemToMove = $limit Then Return Else $ret = _GUICtrlListSwapString($list, $itemToMove + $direction, $itemToMove) EndIf $ret = _GUICtrlListSelectIndex($list, $itemToMove + $direction) EndFunc ;==>_moveListItem Func _stripFile($directory) $directory = StringLeft($directory, StringInStr($directory, "\", 0, -1)) Return $directory EndFunc ;==>_stripFile Func _getFileNames($list, $directory) $goodList = _FileListToArray($directory, "*.*", 1) ; list files to an array. If (Not IsArray($goodList)) Or (@error = 1) Then MsgBox(262208, "Error", "No Files Found.", 5) Return EndIf GUICtrlSetData($list, "") ; set list to empty. For $x = 1 To $goodList[0] ; for loop to place the files in the list. GUICtrlSetData($list, $goodList[$x] & "|", 1) Next EndFunc ;==>_getFileNames Edited February 2, 2007 by Gibbo Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now