AutoHotkey Community

It is currently May 27th, 2012, 11:32 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 71 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject:
PostPosted: May 1st, 2011, 2:10 pm 
Offline

Joined: February 23rd, 2006, 7:43 pm
Posts: 168
Location: Portugal
Nazzal wrote:
Hello Pacheco,
Is this still working? I get error connection :(


Hi... Yes it's still working...
I've just renamed 7 episodes (of different shows) with it, without any problem...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 1st, 2011, 9:21 pm 
Offline
User avatar

Joined: November 19th, 2010, 9:54 am
Posts: 184
The executable works fine, not the script (.ahk file) anymore, No idea why!
I will just use it like that, have been using it for along time now, lovely work Pacheco :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 1st, 2011, 9:30 pm 
Offline

Joined: February 23rd, 2006, 7:43 pm
Posts: 168
Location: Portugal
Nazzal wrote:
The executable works fine, not the script (.ahk file) anymore, No idea why!
I will just use it like that, have been using it for along time now, lovely work Pacheco :)


But i use it in script form (AHK file)...
Don't know why isn't working on your side....

It might be a "internet explorer" problem... (as it uses it's resources to download stuff)...

Be sure that you can navigate through IE...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2011, 11:22 am 
Offline
User avatar

Joined: November 19th, 2010, 9:54 am
Posts: 184
That could be the problem as I always disable it since I use FF only.
Doesn't the executable use the same resources?!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2011, 2:58 am 
Offline

Joined: February 5th, 2010, 8:20 pm
Posts: 22
Nazzal wrote:
That could be the problem as I always disable it since I use FF only.
Doesn't the executable use the same resources?!


The executable probably compiles in a stand alone ie.dll of some sort to do the internet stuff.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2011, 3:35 pm 
Offline

Joined: January 21st, 2009, 1:06 pm
Posts: 63
I know its been a lifetime since i dropped in on this thread but Ive updated the first post with some more information and most importantly, a new version of SceneRenamer.

Pacheco and Paradox, you both do some seriously impressive work! I could have saved myself a lot of time writing new stuff in and troubleshooting it by just looking at what you guys have already been able to do. I didnt think to look at the thread for updates before I started working on my new revisions but I probably should have haha.

Heres the changelog additions
    1.60 (2011-Oct-10)
    - Added GuiDropFiles subroutine to add drag and drop support
    - Improved the ButtonRename subroutine so that all the files added by the user will be refershed into the listview after renaming
    -- Store the data from each row into Array_NewFiles while renaming. Once rename is complete, the filename array is parsed and used to add the files back into the listview
    - Code cleanup
    -- Misc variables that got assigned but never used, etc.
    -- Added a missing GuiControl -Redraw before file rename action
    - Users can now double-click on results in the "Show Picker" dialog box that appears when multiple matches from TheTVDB are returned.
    -- Utilizes the ShowPickerEvent subroutine and a g-label trigger for the listview
    - Fixed junk characters showing up in the "Show Picker" dialog box for series name and description
    -- StringReplace logic added to 2gui section
    - Added cache busting query string param to the URL called in the GetTVDBEpisodes functions
    -- Uses a random number in the query string to give a unique URL for instances where the same file is pulled frequently
    -- Reduces instances where the episode name is not returned due to corrupt Episode_Info.xml being downloaded from local machine cache
    - Fixed bug in the GetTVDBInfo subroutine where the previous entries EpisodeTitle would be used for any subsequent files that no ShowInfo was found on TheTVDB
    -- Clear the EpisodeTitle variable at the end of the subroutine
    1.70 (2011-Oct-11)
    - Added support for settings.ini
    -- HomeDirectory sets the location for "Add File/Folder" to start in
    -- FileExtensions is a CSV (no spaces) for file types that should be added to the listview
    -- Modifed ButtonAddFolder and ButtonAddFile to support the file extensions parsed from the ini
    - ButtonAddFile now allows you to select multiple files (aka multi-select)
    -- Added a parsing loop to properly handle the new data structure used by multi-select
    - Added ability to delete files from the listview by pressing the delete key
    -- Uses "ListView_Events" subroutine
    --- Del key to delete items
    --- Double-click to open folder
    - Restructured context menu labels
    -- Moved "Remove selected" label into existing multi-label subroutine used by the other context menu functions
    -- Added "Open Folder" context item for convenience
    - Changed date format in changelog
    - Fixed various spelling mistakes throughout script and comments


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2011, 3:55 pm 
Offline

Joined: January 21st, 2009, 1:06 pm
Posts: 63
Another quick release, just a fix for the GUI while renaming
    1.71 (2011-Oct-12)
    - Moved the LV_ModifyCol calls to happen after the LV_Add loop to prevent the GUI from twitching like mad while renaming


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2011, 12:56 pm 
Offline

Joined: February 5th, 2010, 8:20 pm
Posts: 22
Welcome back, I have also continued to work on my version of the renamer, but, have not been posting new versions here, and, I also got lazy about documenting my changes, so, it will be a pain for me to write the changelog, but, I will post an update soon, I will also need to merge in some of the changes I read in your changelog, looks interesting...

I was going to post an update a few months ago, but, I had a HDD crash and no recent backup, luckily, I did have an older version and was able to duplicate the changes fairly easily, but, the updated changelog was gone...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2011, 8:44 pm 
i also want to show my version of your script

Image

Code:
; SceneRenamer by strictlyfocused02
;
; AutoHotkey Version: 1.0.48+
;
; Script Function:
;   Extracts season and episode info from the filename
;   and uses that to retreive info from TheTVDB.com to rename
;   the file to a user-specified format

;   Special thanks to TheTVDB.com
;   This project would not have been possible without their top-notch API

#NoEnv

SendMode, Input
SetWorkingDir, %A_ScriptDir%
SetBatchLines , -1

WindowTitle = SceneRenamer

Gui, +Resize +MinSize
Gui, Add, Button, Default gButtonAddFolder vButtonAddFolder HWNDButtonAddFolder, &Add folder
Gui, Add, Button, x+20 gButtonAddFile vButtonAddFile HWNDButtonAddFile, &Add file
Gui, Add, Button, x+20 gButtonClear vButtonClear HWNDButtonClear, &Clear list
Gui, Add, Edit, +ReadOnly x+200 w400 vEditStatus HWNDEditStatus, Waiting for user to add/drop file(s)/folder(s)...

Gui, Add, ListView, xm r26 w800 -ReadOnly NoSort vMyListView HWNDMyListView, Name|Preview|Directory|Extension|TVDB Series ID No


Gui, Add, DropDownList, y+7 w250 AltSubmit vNameScheme HWNDNameScheme, (Show Title) - (SS)x(EE) - (Episode Title)||(Show Title) - S(SS)E(EE) - (Episode Title)|(SS)x(EE) - Episode Title|S(SS)E(EE) - (Episode Title)
Gui, Add, DropDownList, x+7  vLanguage HWNDLanguage sort, Deutsch - de||English - en|Italiano - it|Español - es|Française - fr|Nederlands - nl
Gui, Add, Checkbox, x+15 Checked vZero HWNDZero section, Pad with zero?
Gui, Add, Checkbox, y+1 Checked vOnlyOneShow HWNDOnlyOneShow, Only one show?
Gui, Add, Button, ys x+60 gButtonGetTVDBInfo vButtonGetTVDBInfo HWNDButtonGetTVDBInfo, &Get TVDB Info
Gui, Add, Button, x+60 gButtonRename vButtonRename HWNDButtonRename, &Rename files

Menu, MyContextMenu, Add, Play, ContextPlayFile
Menu, MyContextMenu, Add, Properties, ContextProperties
Menu, MyContextMenu, Add, Remove item, ContextRemoveItem
Menu, MyContextMenu, Add,
Menu, MyContextMenu, Add, Edit new filename, ContextEditNewFileName
Menu, MyContextMenu, Add, Get TVDB info, ContextGetTVDBInfo

Gui, Show,, %WindowTitle%
hwndWindow := WinExist()
LV_Change()
Return


GuiSize:
   Anchor("ButtonAddFolder", "")
   Anchor("ButtonAddFile", "")
   Anchor("ButtonClear", "")
   Anchor("EditStatus", "x",true)   
   Anchor("MyListView", "wh")
   Anchor("NameScheme", "y",true)
   Anchor("Language", "y",true)
   Anchor("Zero", "y",true)
   Anchor("OnlyOneShow", "y",true)
   Anchor("ButtonGetTVDBInfo", "yw",true)
   Anchor("ButtonRename", "xy")
Return



Esc::
GuiClose:
   ExitApp



GuiContextMenu:
   If A_GuiControl <> MyListView
       Return
   Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
Return

ContextPlayFile:
ContextProperties:
   FocusedRowNumber := LV_GetNext(0, "F")
   If not FocusedRowNumber
      return
   LV_GetText(FileName, FocusedRowNumber, 1)
   LV_GetText(FileDir, FocusedRowNumber, 3)
   IfInString A_ThisMenuItem, Play
      Run %FileDir%\%FileName%,, UseErrorLevel
   Else
      Run Properties "%FileDir%\%FileName%",, UseErrorLevel
   If ErrorLevel
      MsgBox Could not perform requested action on "%FileDir%\%FileName%".
return

ContextEditNewFileName:
   FocusedRowNumber := LV_GetNext(0, "F")
   If not FocusedRowNumber
      return
   LV_GetText(FileName, FocusedRowNumber, 1)
   LV_GetText(FileNameNew, FocusedRowNumber, 2)
   LV_GetText(FileDir, FocusedRowNumber, 3)
   LV_GetText(FileExt, FocusedRowNumber, 4)
   LV_GetText(SeriesID, FocusedRowNumber, 5)
   InputBox, RenamedFile  , Rename, Rename manualy your file`n%FileNameNew%,,,,,,,,%FileNameNew%
   If ErrorLevel or RenamedFile = ""
      return
   LV_Delete( FocusedRowNumber)
   LV_Insert( FocusedRowNumber, "", FileName , RenamedFile , FileDir , FileExt , SeriesID )
return


ContextGetTVDBInfo:
   FocusedRowNumberSave := LV_GetNext(0, "F")
   If not FocusedRowNumberSave
      return
   LV_GetText(LVFileName, FocusedRowNumberSave, 1)
   LV_GetText(LVFileDir, FocusedRowNumberSave, 3)
   LV_GetText(LVFileExt, FocusedRowNumberSave, 4)
   Gui, 4:margin ,10 ,10
   Gui, 4:Add, Text , w110 , Show name:
   ContextInfo := GetTVDBShows(LVFileName)
   StringSplit, ContextInfo , ContextInfo , `,
   Gui, 4:Add, Edit,y+1 w110 vGui4ShowName, % ContextInfo1
   Gui, 4:Add, Text ,y+5 w49 section, season:
   Gui, 4:Add, Edit,y+1 w49 vGui4Season, % GetSeasonNumber(LVFileName,FocusedRowNumberSave)
   Gui, 4:Add, Text ,ys w49, episode:
   Gui, 4:Add, Edit,y+1 w49 vGui4Episode, % GetEpisodeNumber(LVFileName)
   Gui, 4:Add, Button,xm w110 -wrap, OK
   Gui, 4:Show
return

4ButtonOK:
   Gui, 4:Submit, NoHide
   EpisodeInfo := GetTVDBEpisodes(ContextInfo2, Gui4Season , Gui4Episode)
   StringSplit , OutputArray, EpisodeInfo, `,
   Gui, 1: Default
   SeasonNumber = %OutputArray1%
   EpisodeNumber = %OutputArray2%
   EpisodeTitle = %OutputArray3%
   ShowName := ContextInfo1
   SeriesIDNo := ContextInfo2
   
   If EpisodeTitle
   {
      StringReplace, EpisodeTitle, EpisodeTitle, \, %A_Space%~%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, /, %A_Space%~%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, :, %A_Space%~%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, *, %A_Space%~%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, ?,, All
      StringReplace, EpisodeTitle, EpisodeTitle, &quot;, ', All
      StringReplace, EpisodeTitle, EpisodeTitle, <, %A_Space%less than%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, >, %A_Space%greater than%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, |, %A_Space%~%A_Space%, All
      StringReplace, EpisodeTitle, EpisodeTitle, &`#44;, `,, All
      StringReplace, EpisodeTitle, EpisodeTitle, &amp;, &, All
   }
   GuiControlGet, PadZero,, Zero
   If PadZero = 1
   {
      SeasonNumber := PadZero(SeasonNumber)
      EpisodeNumber := PadZero(EpisodeNumber)
   }
   GuiControlGet, NamingScheme,, NameScheme
   If NamingScheme = 1
   {
      If EpisodeTitle
         NewFileName = %ShowName% - %SeasonNumber%x%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
      Else
         NewFileName = %ShowName% - %SeasonNumber%x%EpisodeNumber%.%LVFileExt%
   }
   Else if NamingScheme = 2
   {
      If EpisodeTitle
         NewFileName = %ShowName% - S%SeasonNumber%E%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
      Else
         NewFileName = %ShowName% - S%SeasonNumber%E%EpisodeNumber%.%LVFileExt%
   }
   Else If NamingScheme = 3
   {
      If EpisodeTitle
         NewFileName = %SeasonNumber%x%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
      Else
         NewFileName = %SeasonNumber%x%EpisodeNumber%.%LVFileExt%
   }
   Else If NamingScheme = 4
   {
      If EpisodeTitle
         NewFileName = S%SeasonNumber%E%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
      Else
         NewFileName = S%SeasonNumber%E%EpisodeNumber%.%LVFileExt%
   }
   LV_Delete( FocusedRowNumberSave)
   LV_Insert( FocusedRowNumberSave, "", LVFileName , NewFileName , LVFileDir , LVFileExt , SeriesIDNo )
   LV_ModifyCol()
   LV_ModifyCol(4, 60)
   LV_ModifyCol(5, 110)  ; Expand "TVDB Series ID No" to keep the header visible

4GuiClose:
   Gui, 4: Destroy
return

ContextRemoveItem:
   RowNumber = 0
   Loop
   {
      RowNumber := LV_GetNext(RowNumber - 1)
      If not RowNumber
           Break
      LV_Delete(RowNumber)
   }
Return


GuiDropFiles:
   Gui +OwnDialogs
   Loop, parse, A_GuiEvent, `n
   {
      TargetFile = %A_LoopField%
      SplitPath, TargetFile,,, FileExt  ; Get the file extension
      If FileExt in avi,mkv,mp4,srt,divx,flv
      {
         SplitPath, TargetFile, FileName, TargetFolder
         LV_Add(Row, FileName, "", TargetFolder, FileExt)
         LV_ModifyCol()  ; Resize each column to fit
         LV_ModifyCol(2, 60)  ; Expand "Preview" to keep the header visible
         LV_ModifyCol(4, 60)  ; Expand "Extension" to keep the header visible
         LV_ModifyCol(5, 110)  ; Expand "Series ID No" to keep the header visible
         ControlSetText, Edit1, Added file %TargetFile%..., %WindowTitle%
      }else
      {
         TargetFolder := TargetFile  ; rename for better reading
         Loop, %TargetFolder%\*.* , , 1
         {
            FileName := A_LoopFileFullPath
            SplitPath, FileName,,, FileExt    ; Get the file extension
            IF FileName contains sample       ;if it´s only a sample skip it
               continue
            If FileExt in avi,mkv,mp4,srt,divx,flv
            {
               LV_Add(Row, A_LoopFileName, "", A_LoopFileDir, FileExt)               
               ControlSetText, Edit1, Added folder %TargetFolder%, %WindowTitle% 
            }
            LV_ModifyCol()  ; Resize each column to fit
         }
         GuiControl, +Redraw, MyListView  ; Turn redrawing back on
         LV_ModifyCol()  ; Resize each column to fit
         LV_ModifyCol(2, 60)  ; Expand "Preview" to keep the header visible
         LV_ModifyCol(4, 60)  ; Expand "Extension" to keep the header visible
         LV_ModifyCol(5, 110)  ; Expand "TVDB Series ID No" to keep the header visible
      }
   }
Return


ButtonAddFolder:
   Gui +OwnDialogs
   FileSelectFolder, TargetFolder,, 3, Select a folder:
   If not TargetFolder  ; The user pressed cancel
       Return
   StringRight, LastChar, TargetFolder, 1
   If LastChar = \
      StringTrimRight, TargetFolder, TargetFolder, 1
   GuiControl, -Redraw, MyListView ; Improves performance by disabling redrawing
   Loop, %TargetFolder%\*.* , , 1
   {
      FileName := A_LoopFileFullPath
      SplitPath, FileName,,, FileExt    ; Get the file extension
      IF FileName contains sample       ;if it´s only a sample skip it
         continue
      If FileExt in avi,mkv,mp4,srt,divx,flv
         LV_Add(Row, A_LoopFileName, "", A_LoopFileDir, FileExt)
   }
   GuiControl, +Redraw, MyListView  ; Turn redrawing back on
   LV_ModifyCol()  ; Resize each column to fit
   LV_ModifyCol(2, 60)  ; Expand "Preview" to keep the header visible
   LV_ModifyCol(4, 60)  ; Expand "Extension" to keep the header visible
   LV_ModifyCol(5, 110)  ; Expand "TVDB Series ID No" to keep the header visible
   ControlSetText, Edit1, Added folder %TargetFolder%, %WindowTitle%       
Return

ButtonAddFile:
   Gui +OwnDialogs
   FileSelectFile, TargetFile
   If not TargetFile
      Return
   SplitPath, TargetFile,,, FileExt  ; Get the file extension
   If FileExt in avi,mkv,mp4,srt,divx,flv
   {
      SplitPath, TargetFile, FileName, TargetFolder
      LV_Add(Row, FileName, "", TargetFolder, FileExt)
      LV_ModifyCol()  ; Resize each column to fit
      LV_ModifyCol(2, 60)  ; Expand "Preview" to keep the header visible
      LV_ModifyCol(4, 60)  ; Expand "Extension" to keep the header visible
      LV_ModifyCol(5, 110)  ; Expand "TVDB Series ID No" to keep the header visible
      ControlSetText, Edit1, Added file %TargetFile%..., %WindowTitle%
   }
Return

ButtonClear:
   TargetFolder =
   TargetFile =
   LV_Delete()
   LV_Destroy()
   LV_Change()
   ControlSetText, Edit1, Cleared Listview. Waiting for user to add/drop file(s)/folder(s)..., %WindowTitle%
Return

ButtonGetTVDBInfo:
   LV_GetText(LVFileName, 1, 1)
   If not LVFileName
   {
      Gui +OwnDialogs
      MsgBox, 0,Fatal Error!, You must select a file or folder before connecting to TheTVDB.com!
      Return
   }
   
   GuiControlGet, PadOnlyOneShow,, OnlyOneShow
   
   Loop
   {
      Gui +OwnDialogs
      RowNumber = %A_Index%
      LV_GetText(LVFileName, RowNumber, 1)  ; Get the filename
      If not LVFileName  ; Break the loop at the end of the list
         Break
      LV_GetText(LVFileDir, RowNumber, 3)  ; Get the file directory
      LV_GetText(LVFileExt, RowNumber, 4)  ; Get the file extension
     
      ShowName := GetShowName(LVFileName)
      StringUpper, UpperCurrSN, ShowName
     
      If A_Index > 1
      {
         LV_GetText(LVPrevFN, RowNumber - 1, 1)  ; Get the preceeding rows filename
         PrevShowName := GetShowName(LVPrevFN)
         StringUpper, UpperPrevSN, PrevShowName
         
      }

      If ((UpperCurrSN != UpperPrevSN) or (UpperCurrSN = ""))
      {
         If ((A_Index = 1) or (PadOnlyOneShow = 0))
            ShowInfo := GetTVDBShows(ShowName)
         StringSplit, ShowArray, ShowInfo, `,
         ShowName = %ShowArray1%
         SeriesIDNo = %ShowArray2%
      }
      Else
      {
         LV_GetText(LVPrevFN, RowNumber - 1, 2)  ; Get the preceeding rows new filename
         PrevShowName := GetShowName(LVPrevFN)
         ShowName = %PrevShowName%
         LV_GetText(SeriesIDNo, RowNumber - 1, 5)
      }
      UpperPrevSN =
      PrevShowName =
      SeasonNumber := GetSeasonNumber(LVFileName, RowNumber)
      EpisodeNumber := GetEpisodeNumber(LVFileName)
      ControlSetText, Edit1, Processing "%ShowName%" Season "%SeasonNumber%" Episode "%EpisodeNumber%", %WindowTitle%
      If SeriesIDNo
      {
         EpisodeInfo := GetTVDBEpisodes(SeriesIDNo, SeasonNumber, EpisodeNumber)
         StringSplit, OutputArray, EpisodeInfo, `,
         SeasonNumber = %OutputArray1%
         EpisodeNumber = %OutputArray2%
         EpisodeTitle = %OutputArray3%
         If EpisodeTitle
         {
            StringReplace, EpisodeTitle, EpisodeTitle, \, %A_Space%~%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, /, %A_Space%~%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, :, %A_Space%~%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, *, %A_Space%~%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, ?,, All
            StringReplace, EpisodeTitle, EpisodeTitle, &quot;, ', All
            StringReplace, EpisodeTitle, EpisodeTitle, <, %A_Space%less than%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, >, %A_Space%greater than%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, |, %A_Space%~%A_Space%, All
            StringReplace, EpisodeTitle, EpisodeTitle, &`#44;, `,, All
            StringReplace, EpisodeTitle, EpisodeTitle, &amp;, &, All
         }
      }
      GuiControlGet, PadZero,, Zero
      If PadZero = 1
      {
         SeasonNumber := PadZero(SeasonNumber)
         EpisodeNumber := PadZero(EpisodeNumber)
      }
      GuiControlGet, NamingScheme,, NameScheme
      If NamingScheme = 1
      {
         If EpisodeTitle
            NewFileName = %ShowName% - %SeasonNumber%x%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
         Else
            NewFileName = %ShowName% - %SeasonNumber%x%EpisodeNumber%.%LVFileExt%
      }
      Else if NamingScheme = 2
      {
         If EpisodeTitle
            NewFileName = %ShowName% - S%SeasonNumber%E%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
         Else
            NewFileName = %ShowName% - S%SeasonNumber%E%EpisodeNumber%.%LVFileExt%
      }
      Else If NamingScheme = 3
      {
         If EpisodeTitle
            NewFileName = %SeasonNumber%x%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
         Else
            NewFileName = %SeasonNumber%x%EpisodeNumber%.%LVFileExt%
      }
      Else If NamingScheme = 4
      {
         If EpisodeTitle
            NewFileName = S%SeasonNumber%E%EpisodeNumber% - %EpisodeTitle%.%LVFileExt%
         Else
            NewFileName = S%SeasonNumber%E%EpisodeNumber%.%LVFileExt%
      }
      LV_Modify(RowNumber, Col1, LVFileName, NewFileName, LVFileDir, LVFileExt, SeriesIDNo)
      LV_ModifyCol()
      LV_ModifyCol(4, 60)
      LV_ModifyCol(5, 110)  ; Expand "TVDB Series ID No" to keep the header visible

      If not EpisodeTitle
         LV_SetColor("-" . RowNumber, 0xFFFFFF, 0x0000FF)

      LVFileName =
      LVPrevFN =
      ShowArray1 =
      LV_CheckForDoubleEntrys(RowNumber , NewFileName)

   }
   ControlSetText, Edit1, Finished queuring TheTVDB.com. Ready to rename..., %WindowTitle%
   
   Return

ButtonRename:
   LV_GetText(LVNewFileName, 1, 2)
   If not LVNewFileName
   {
      Gui +OwnDialogs
      MsgBox, 0,Fatal Error!, You must scan your files against TheTVDB.com before you rename them!
      Return
   }
   Loop
   {
      RowNumber = %A_Index%
      LV_GetText(LVFileName, RowNumber, 1)  ; Get the original filename
      If not LVFileName  ; Break the loop at the end of the list
         Break
      LV_GetText(LVNewFileName, RowNumber, 2)  ; Get the new filename
      LV_GetText(LVFileDir, RowNumber, 3)  ; Get the file dir
      ControlSetText, Edit1, Renaming "%LVFileName%" to "%LVNewFileName%", %WindowTitle%
      FileMove, %LVFileDir%\%LVFileName%, %LVFileDir%\%LVNewFileName%  ; Finally, rename it
   }
   RenameCount := RowNumber - 1
   ControlSetText, Edit1, Finished renaming files! Refreshing file list., %WindowTitle%
   LV_Delete()
   Loop %LVFileDir%\*.*
   {
      FileName := A_LoopFileFullPath
      If not FileName
         Break
      SplitPath, FileName,,, FileExt  ; Get the file extension
      If FileExt in avi,mkv,mp4
         LV_Add(Row, A_LoopFileName, "", A_LoopFileDir, FileExt)
   }
   GuiControl, +Redraw, MyListView  ; Turn redrawing back on
   LV_ModifyCol()  ; Resize each column to fit
   LV_ModifyCol(2, 60)  ; Expand "Preview" to keep the header visible
   LV_ModifyCol(4, 60)  ; Expand "Extension" to keep the header visible
   LV_ModifyCol(5, 110)  ; Expand "TVDB Series ID No" to keep the header visible
   Return




;Provide a filename (greek.s01e01.avi) and this should return the show name
GetShowName(FileName)
{
   IfInString, FileName, .
      StringReplace, NormalName, FileName, ., %A_Space%, All
   IfInString, NormalName, _
      StringReplace, NormalName, NormalName, _, %A_Space%, All
   If RegExMatch(NormalName, "i)s[0-9][0-9]? ?e[0-9][0-9]?", SeasonAndEpisode)
   {
      StringGetPos, SeasonAndEpisodePos, NormalName, %SeasonAndEpisode%
      StringLeft, ShowName, NormalName, (SeasonAndEpisodePos - 1)
   }
   Else If RegExMatch(NormalName, "i)[0-9][0-9]?x[0-9][0-9]?", SeasonAndEpisode)
   {
      StringGetPos, SeasonAndEpisodePos, NormalName, %SeasonAndEpisode%
      StringLeft, ShowName, NormalName, (SeasonAndEpisodePos - 1)
   }
   Else If RegExMatch(NormalName, "[0-9][0-9][0-9][0-9]?", SeasonAndEpisode)
   {
      StringGetPos, SeasonAndEpisodePos, NormalName, %SeasonAndEpisode%
      StringLeft, ShowName, NormalName, (SeasonAndEpisodePos - 1)
   }
   Loop
   {
      StringRight, LastChar, ShowName, 1
      If (LastChar = "-" or LastChar = " ")
         StringTrimRight, ShowName, ShowName, 1
      Else
         Break
   }
   Return ShowName
}

;Provide a filename (greek.s01e01.avi) and this should return the season number
GetSeasonNumber(FileName, RowNumber)
{
   If RegExMatch(FileName, "i)s\K[0-9][0-9]?.?e[0-9][0-9]?", SeasonAndEpisode)
   {
      StringSplit, OutputArray, SeasonAndEpisode, e E, .
      SeasonNumber = %OutputArray1%
      RegExMatch(SeasonNumber, "[0-9][0-9]?", SeasonNumber)
      IfInString, SeasonNumber, 0
      {
         StringGetPos, ZeroLoc, SeasonNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, SeasonNumber, SeasonNumber, 1
      }
         
   }
   Else If RegExMatch(FileName, "i)[0-9][0-9]?x[0-9][0-9]?", SeasonAndEpisode)
   {
      StringSplit, OutputArray, SeasonAndEpisode, x X
      SeasonNumber = %OutputArray1%
      IfInString, SeasonNumber, 0
      {
         StringGetPos, ZeroLoc, SeasonNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, SeasonNumber, SeasonNumber, 1
      }
   }
   Else If RegExMatch(FileName, "i)[0-9][0-9][0-9][0-9]?", SeasonAndEpisode)
   {
      StringTrimRight, SeasonNumber, SeasonAndEpisode, 2
      IfInString, SeasonNumber, 0
      {
         StringGetPos, ZeroLoc, SeasonNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, SeasonNumber, SeasonNumber, 1
      }
   }
   
   Else If RegExMatch(FileName, "i)[0-9][0-9].[0-9][0-9]", SeasonAndEpisode)
   {
      StringLeft, SeasonNumber, SeasonAndEpisode, 2
      IfInString, SeasonNumber, 0
      {
         StringGetPos, ZeroLoc, SeasonNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, SeasonNumber, SeasonNumber, 1
      }
   }
   Else If RegExMatch(FileName, "i)[0-9][0-9]?.[0-9][0-9]", SeasonAndEpisode)
   {
      StringTrimRight, SeasonNumber, SeasonAndEpisode, 2
      RegExMatch(SeasonNumber, "i)[0-9][0-9]?", SeasonNumber)
      IfInString, SeasonNumber, 0
      {
         StringGetPos, ZeroLoc, SeasonNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, SeasonNumber, SeasonNumber, 1
      }
   }
   
   Else If RegExMatch(FileName, "[0-9][0-9]?", SeasonAndEpisode)
   {
      LV_GetText(FileDir, RowNumber, 3)
      SplitPath, FileDir,OutFileName,OutFileDir, FileExt
      RegExMatch(OutFileName, "[0-9][0-9]?", SeasonNumber)
      LV_GetText(Name, RowNumber, 1)
      SplitPath, Name, , , , Name
      if (OutFileName = Name)
      {

         SplitPath, OutFileDir,OutFileName,OutFileDir, FileExt
         RegExMatch(OutFileName, "[0-9][0-9]?", SeasonNumberalt)
         if (SeasonNumberalt != "")
            SeasonNumber := SeasonNumberalt
      }
 
      if (SeasonNumber = "")
         SeasonNumber := 1
     
      IfInString, SeasonNumber, 0
      {
         StringGetPos, ZeroLoc, SeasonNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, SeasonNumber, SeasonNumber, 1
      }
   }
   Return SeasonNumber
}

;Provide a filename (greek.s01e01.avi) and this should return the episode number
GetEpisodeNumber(FileName)
{
   If RegExMatch(FileName, "i)s\K[0-9][0-9]?.?e[0-9][0-9]?", SeasonAndEpisode)
   {
      StringSplit, OutputArray, SeasonAndEpisode, e E, .
      EpisodeNumber = %OutputArray2%
      IfInString, EpisodeNumber, 0
      {
         StringGetPos, ZeroLoc, EpisodeNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, EpisodeNumber, EpisodeNumber, 1
      }
   }
   Else If RegExMatch(FileName, "i)[0-9][0-9].?x[0-9][0-9]", SeasonAndEpisode)
   {
      StringSplit, OutputArray, SeasonAndEpisode, x X
      EpisodeNumber = %OutputArray2%
      IfInString, EpisodeNumber, 0
      {
         StringGetPos, ZeroLoc, EpisodeNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, EpisodeNumber, EpisodeNumber, 1
      }
   }
   Else If RegExMatch(FileName, "i)[0-9][0-9].?\K[0-9][0-9]", SeasonAndEpisode)
   {
      StringRight, EpisodeNumber, SeasonAndEpisode, 2
      IfInString, EpisodeNumber, 0
      {
         StringGetPos, ZeroLoc, EpisodeNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, EpisodeNumber, EpisodeNumber, 1
      }
   }
   Else If RegExMatch(FileName, "[0-9][0-9][0-9][0-9]?", SeasonAndEpisode)
   {
      StringRight, EpisodeNumber, SeasonAndEpisode, 2
      IfInString, EpisodeNumber, 0
      {
         StringGetPos, ZeroLoc, EpisodeNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, EpisodeNumber, EpisodeNumber, 1
      }
   }
   Else If RegExMatch(FileName, "[0-9][0-9].*", SeasonAndEpisode) ; "[0-9][0-9]?.*"   "\d+(?!.*\d+)"
   {     
     
      StringLeft, EpisodeNumber, SeasonAndEpisode, 2
      IfInString, EpisodeNumber, 0
      {
         StringGetPos, ZeroLoc, EpisodeNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, EpisodeNumber, EpisodeNumber, 1
      }
   }
   Else If RegExMatch(FileName, "\d+(?!.*\d+)", SeasonAndEpisode) ; "[0-9][0-9]?.*"   "\d+(?!.*\d+)"   "[0-9].*"
   {     
     
      StringLeft, EpisodeNumber, SeasonAndEpisode, 1
      IfInString, EpisodeNumber, 0
      {
         StringGetPos, ZeroLoc, EpisodeNumber, 0
         If ZeroLoc = 0
            StringTrimLeft, EpisodeNumber, EpisodeNumber, 1
      }
   }
   Return EpisodeNumber
}




;Provide a show name (greek) and it will return the TVDB data for the show name (Greek) and series ID (80301) as a CSV (Greek,80301)
GetTVDBShows(ShowName)
{
   Global SeriesName, SeriesIDNum
   IfExist, Series_ID.xml
      FileDelete, Series_ID.xml
   
   GuiControlGet, LanguageSelect,, Language
   StringRight , LanguageSelect, LanguageSelect , 2
   
   UrlDownloadToFile, http://www.thetvdb.com/api/GetSeries.php?seriesname="%ShowName%"&language=%LanguageSelect%, Series_ID.xml
   XPath_Load(xml, "Series_ID.xml")
   FileDelete, Series_ID.xml
   
   
   
   
   SeriesLanguage := XPath(xml, "/Data/Series/language/text()")   
   SeriesNameNodeCount := XPath(xml, "/Data/Series/SeriesName/Count()")   
   SeriesIDNum := XPath(xml, "/Data/Series/seriesid/text()")
   SeriesName := XPath(xml, "/Data/Series/SeriesName/text()")
   SeriesOverview := XPath(xml, "/Data/Series/Overview/text()")
   
   StringSplit, OutputArraySID, SeriesIDNum, `,
   StringSplit, OutputArraySN, SeriesName, `,
   StringSplit, OutputArraySO, SeriesOverview, `,
   StringSplit, OutputArrayLA, SeriesLanguage, `,
   
   
   Gui, 2: Default
   Gui, 2: +ToolWindow +Owner1
   Gui, 2: Add, ListView, xm r15 w600 gListViewTVDBShows, Show name|Show description|TVDB series ID no.
   Gui, 2: Add, Text, y+7
   Gui, 2: Add, Button, x+540, Cancel
   
   searchcount := 0
   Loop, %SeriesNameNodeCount%
   {   
         SeriesLanguage := OutputArrayLA%A_Index%
         if (SeriesLanguage != LanguageSelect)
            continue
         
         searchcount := searchcount +1
         
         SeriesIDNum := OutputArraySID%A_Index%
         SeriesName := OutputArraySN%A_Index%
         SeriesOverview := OutputArraySO%A_Index%
         
         IfInString, SeriesOverview, &#44`;
            StringReplace, SeriesOverview, SeriesOverview, &#44`;, `,, All
         If not SeriesOverview
            SeriesOverview = (No show description provided)
         LV_Add(Row, SeriesName, SeriesOverview, SeriesIDNum)
         LV_ModifyCol()
         LV_ModifyCol(3, 110)
   }
   if (searchcount <= 1)
   {
      Gui, 2:Destroy
      Gui, 1: Default
      searchcount := 0
   }
   else
   {
      Gui, 2: Show,,Which Show?
      Gui, 1: Default
      WinWaitClose, Which Show?   
   }
   
   If not SeriesName
   {
      SeriesName = %ShowName%
      InputBox, UserInput, Cannot find series, Please enter the series name,
      ShowName =
      SeriesIDNum =
      SeriesName =
      SeriesOverview =
      return GetTVDBShows(UserInput)
   }else
   {
   J = %SeriesName%,%SeriesIDNum%
   ShowName =
   SeriesIDNum =
   SeriesName =
   SeriesOverview =
   Return J
   }
}

   ;Labels required for Gui 2
   2GuiEscape:
   2GuiClose:
   2ButtonCancel:
   {
      Gui, 2: Destroy
      SeriesName =
      Return
   }
   ListViewTVDBShows:
   {
      FocusedRowNumber := LV_GetNext(0, "F")
      If not FocusedRowNumber
      {
         MsgBox, 0, Warning!, You must select a show or press cancel!
         Return
      }
      LV_GetText(SeriesName, FocusedRowNumber, 1)
      LV_GetText(SeriesIDNum, FocusedRowNumber, 3)
      FocusedRowNumber =
      Gui, 2: Destroy
      Return
   }


;Provide the "TVDB series ID", "season number" and "episode number" and this will return the TVDB season number, episode number, and episode title as a CSV (3,1,The Day After)
GetTVDBEpisodes(SeriesIDNum, SeasonNum, EpisodeNum)
{

   IfExist, Episode_Info.xml
      FileDelete, Episode_Info.xml
     
   GuiControlGet, LanguageSelect,, Language
   StringRight , LanguageSelect, LanguageSelect , 2
   
   UrlDownloadToFile, http://www.thetvdb.com/api/563E39CDC7F666DF/series/%SeriesIDNum%/default/%SeasonNum%/%EpisodeNum%/%LanguageSelect%.xml, Episode_Info.xml   
   XPath_Load(xml, "Episode_Info.xml")

   FileDelete, Episode_Info.xml
   SeasonNumber := XPath(xml, "/Data/Episode/SeasonNumber/text()")
   EpisodeNumber := XPath(xml, "/Data/Episode/EpisodeNumber/text()")
   EpisodeTitle := XPath(xml, "/Data/Episode/EpisodeName/text()")
   If not SeasonNumber
      SeasonNumber = %SeasonNum%
   If not EpisodeNumber
      EpisodeNumber = %EpisodeNum%
   K = %SeasonNumber%,%EpisodeNumber%,%EpisodeTitle%
   SeasonNumber =
   EpisodeNumber =
   EpisodeTitle =
   Return K
}

;Pads a variable with a preceeding zero
PadZero(VarToPad)
{
   VarToPadLen := StrLen(VarToPad)
   If VarToPadLen = 1
      VarToPad = 0%VarToPad%
   VarToPadLen =
   Return VarToPad
}


LV_CheckForDoubleEntrys(MaxRowNumber , MaxFileName)
{
   Loop , % MaxRowNumber -1
   {
      LV_GetText(Name, A_Index, 2)
     
      If Name = MaxFileName
      {
         LV_SetColor("-" . A_Index, 0xFFFFFF, 0x0000FF)
         LV_SetColor("-" . MaxRowNumber, 0xFFFFFF, 0x0000FF)
      }
   }   
}









/*********
*   LVCustomColors.ahk
*/

LV_Initialize(Gui_Number="", Control="", Column="")
{
   local hGUI, hLV
   ;Get either class or hWnd of control
   If !Control                                    ;Control omitted
   {
      If (Gui_Number > 99)
         hLV := Gui_Number
      Else                                    ;No hWnd => default
         Control = SysListView321
   }
   Else If RegExMatch(Control, "^[1-9]\d*$")            ;ClassNN Number provided
      Control = SysListView32%Control%
   Else If !RegExMatch(Control, "^(SysListView32)?[1-9]\d*$")   ;Not a ClassNN => control's associated var
   {
      If (!(Gui_Number > 0) || (Gui_Number > 99))
         Gui_Number = 1
      If _%Gui_Number%_%Control%_
         Return
      GuiControlGet, hLV, %Gui_Number%:hWnd, %Control%
      If ErrorLevel
         Return
      _%Gui_Number%_%Control%_ := hLV
   }                                          ;Otherwise, ClassNN was provided.
      
   If hLV
   {
      If (_%hLV%_ || !HWND2GuiNClass(hLV, Gui_Number, Control))
         Return
   }
   Else If Control                                 ;Control found/provided
   {
      If (!(Gui_Number > 0) || (Gui_Number > 99))
         Gui_Number = 1
      If _%Gui_Number%_%Control%_
         Return
      Gui, %Gui_Number%:+LastFoundExist
      If !(hGUI := WinExist())
         Return
      GuiControlGet, hLV, %Gui_Number%:HWND, %Control%
      If ErrorLevel
         Return
   }
   Else
      Return
   
   hLV+=0
   ;Save handle to quickly get it from gui+control
   _%Gui_Number%_%Control%_ := hLV
   ;Save gui and control to quickly get it from handle
   _%hLV%_ := Gui_Number "|" Control
   ;Save column containing indexes
   If !Column
      _%hLV%_Col_ = 1
   Else
      _%hLV%_Col_ := Column
   ;Maintain a list of registered handles for wm_notify to operate on every registered control
   If !_LTV_h_List_
      _LTV_h_List_ := "|" hLV "|"
   Else
      _LTV_h_List_ .= hLV "|"
   ;Maintain a list of modified indexes for disposal
   ;Colors bound to indexes
   _%hLV%_0_Text = |
   _%hLV%_0_Back = |
   ;Colors bound to lines
   _%hLV%_0_LText = |
   _%hLV%_0_LBack = |
   OnMessage( 0x4E, "WM_NOTIFY" )
   Return hLV
}

LV_Change(Gui_Number="", Control="", Select="", Column="")
{
   local hLV
   ;Get either class or hWnd of control
   If !Control                                    ;Control omitted
   {
      If (Gui_Number > 99)
         hLV := Gui_Number
      Else                                    ;No hWnd => default
         Control = SysListView321
   }
   Else If RegExMatch(Control, "^[1-9]\d*$")            ;ClassNN Number provided
      Control = SysListView32%Control%
   Else If !RegExMatch(Control, "^(SysListView32)?[1-9]\d*$")      ;Not a ClassNN or a NN => control's associated var
   {
      If (!(Gui_Number > 0) || (Gui_Number > 99))
         Gui_Number = 1
      If !(hLV := _%Gui_Number%_%Control%_)      ;May not have been initialized
      {
         If !(hLV := LV_Initialize(Gui_Number, Control, Column))
            Return
      }
   }                                          ;Otherwise, ClassNN was provided.
   
   If hLV
   {
      hLV+=0
      If !_%hLV%_      ;May not have been initialized
      {
         If !LV_Initialize(hLV, "", Column)
            Return
      }
      Loop, Parse, _%hLV%_, |
      {
         If (A_Index = 1)
            Gui_Number := A_LoopField
         Else
            Control := A_LoopField
      }
   }
   Else If Control                                 ;Control found/provided
   {
      If (!(Gui_Number > 0) || (Gui_Number > 99))
         Gui_Number = 1
      If !(hLV := _%Gui_Number%_%Control%_)      ;May not have been initialized
      {
         If !(hLV := LV_Initialize(Gui_Number, Control, Column))
            Return
      }
   }
   Else
      Return
   
   _LV_h_ := hLV+0
   If (Select != 0)
   {
      Gui, %Gui_Number%:Default
      Gui, ListView, %Control%
   }
   If (Column && (Column != _%hLV%_Col_))
      _%hLV%_Col_ := Column
   Return 1
}


LV_SetColor(Index="", TextColor="", BackColor="", Redraw=1)
{
   local i, j, L
   If !_LV_h_
      Return
   Index+=0
   If (Index < 0)
   {
      L = L
      i = 1
      Index := -Index-1
   }
   Else If (Index > 0)
   {
      i = 1
      Index--
   }   
   Else If ((Index = "-0") || (Index = "-"))
   {
      L = L
      Index = 0
      ControlGet, i, List, Count, , ahk_id %_LV_h_%
   }
   Else
   {
      Index = 0
      ControlGet, i, List, Count, , ahk_id %_LV_h_%
   }
   Loop, %i%
   {
      j := A_Index+Index
      If (TextColor != "")
      {
         If (TextColor >= 0)
         {
            If !InStr(_%_LV_h_%_0_%L%Text, "|" j "|")
               _%_LV_h_%_0_%L%Text .= j "|"
            _%_LV_h_%_%j%_%L%Text := TextColor
         }
         Else
         {
            _%_LV_h_%_%j%_%L%Text =
            StringReplace, _%_LV_h_%_0_%L%Text, _%_LV_h_%_0_%L%Text, |%j%|, |
         }
      }
      If (BackColor != "")
      {
         If (BackColor >= 0)
         {
            If !InStr(_%_LV_h_%_0_%L%Back, "|" j "|")
               _%_LV_h_%_0_%L%Back .= j "|"
            _%_LV_h_%_%j%_%L%Back := BackColor
         }
         Else
         {
            _%_LV_h_%_%j%_%L%Back =
            StringReplace, _%_LV_h_%_0_%L%Back, _%_LV_h_%_0_%L%Back, |%j%|, |   
         }
      }
   }
   If Redraw
      WinSet, Redraw,, ahk_id %_LV_h_%
   Return 1
}


LV_GetColor(Index, T="Text")      ;Index of the item from which to get color , T="Text" ; T="Back" , L=0 : linked to lines; L=1 : linked to rows
{
   local L
   If (Index<0)
   {
      L = L
      Index := -Index
   }
   Return _%_LV_h_%_%Index%_%L%%T%
}


LV_Destroy(Gui_Number="", Control="", DeactivateWMNotify="")
{
   local hLV
   ;Get either class or hWnd of control
   If !Control                                    ;Control omitted
   {
      If (Gui_Number > 99)
         hLV := Gui_Number
      Else                                    ;No hWnd => default
         Control = SysListView321
   }
   Else If Control RegExMatch(Control, "^[1-9]\d*$")                        ;ClassNN Number provided
      Control = SysListView32%Control%
   Else If !RegExMatch(Control, "^(SysListView32)?[1-9]\d*$")      ;Not a ClassNN or a NN => control's associated var
   {
      If (!(Gui_Number > 0) || (Gui_Number > 99))
         Gui_Number = 1
      If !(hLV := _%Gui_Number%_%Control%_)
         Return
   }                                          ;Otherwise, ClassNN was provided.
   
   If hLV
   {
      hLV+=0
      If !_%hLV%_
         Return
      Loop, Parse, _%hLV%_, |
      {
         If (A_Index = 1)
            Gui_Number := A_LoopField
         Else
            Control := A_LoopField
      }
   }
   Else If Control                                 ;Control found/provided
   {
      If (!(Gui_Number > 0) || (Gui_Number > 99))
         Gui_Number = 1
      If !(hLV := _%Gui_Number%_%Control%_)
         Return
   }
   Else
      Return

   Loop, Parse, _%hLV%_0_Text, |
      _%hLV%_%A_LoopField%_Text =
   _%hLV%_0_Text =
   Loop, Parse, _%hLV%_0_Back, |
      _%hLV%_%A_LoopField%_Back =
   _%hLV%_0_Back =
   Loop, Parse, _%hLV%_0_LText, |
      _%hLV%_%A_LoopField%_LText =
   _%hLV%_0_LText =
   Loop, Parse, _%hLV%_0_LBack, |
      _%hLV%_%A_LoopField%_LBack =
   _%hLV%_0_LBack =
   _%Gui_Number%_%Control%_ =
   _%hLV%_Col_ =
   _%hLV%_ =
   WinSet, Redraw,, ahk_id %hLV%
   StringReplace, _LTV_h_List_, _LTV_h_List_, |%hLV%|, |, A
   If ((_LTV_h_List_ = "|") && DeactivateWMNotify)
      OnMessage( 0x4E, "" )
   If (hLV = _LV_h_)
      _LV_h_ =
   
   Return 1
}


DecodeInteger( p_type, p_address, p_offset) ;, p_hex=false )
{
   ;old_FormatInteger := A_FormatInteger
   ;ifEqual, p_hex, 1, SetFormat, Integer, hex
   ;else, SetFormat, Integer, dec
   StringRight, size, p_type, 1
   loop, %size%
      value += *( ( p_address+p_offset )+( A_Index-1 ) ) << ( 8*( A_Index-1 ) )
   if ( size <= 4 and InStr( p_type, "u" ) != 1 and *( p_address+p_offset+( size-1 ) ) & 0x80 )
      value := -( ( ~value+1 ) & ( ( 2**( 8*size ) )-1 ) )
   ;SetFormat, Integer, %old_FormatInteger%
   return, value
}


EncodeInteger( p_value, p_size, p_address, p_offset )
{
   loop, %p_size%
      DllCall( "RtlFillMemory", "uint", p_address+p_offset+A_Index-1, "uint", 1, "uchar", p_value >> ( 8*( A_Index-1 ) ) )
}


;Retrieves gui number and classNN from hwnd of a gui control
HWND2GuiNClass(hWnd, ByRef Gui = "", ByRef Control = "")
{
   WinGetClass, Cc, ahk_id %hWnd%
   Loop, 99
   {
      Gui, %A_Index%:+LastFoundExist
      If !WinExist()
         Continue
      Gui_Number := A_Index
      Loop
      {
         GuiControlGet, hWCc, %Gui_Number%:HWND, %Cc%%A_Index%
         If !hWCc
            Break
         If (hWnd = hWCc)
         {
            Ctrl := Cc A_Index
            Break
         }
      }
      If Ctrl
      {
         Gui := A_Index
         Control := Ctrl
         Return 1
      }
   }
}


LV_WM_NOTIFY(p_l)
{
   local draw_stage, Current_Line, hLV, Index1, Index
   static IndexList
   Critical
   If InStr(_LTV_h_List_, "|" (hLV := DecodeInteger( "uint4", p_l, 0 )) "|")
   {
      If (DecodeInteger( "int4", p_l, 8 ) = -12)                  ; NM_CUSTOMDRAW
      {
         draw_stage := DecodeInteger( "uint4", p_l, 12 )
         If ( draw_stage = 1 )                                 ; CDDS_PREPAINT
         {
            ControlGet, IndexList, List, % "Col" _%hLV%_Col_, , ahk_id %hLV%
            If !RegexMatch(IndexList, "S)^([1-9]\d*\n)*[1-9]\d*$")      ;The index column must contain exclusively strictly positive decimal integers
               IndexList =
            Return, 0x20                                    ; CDRF_NOTIFYITEMDRAW
         }
         Else If ( draw_stage = 0x10001 )                        ; CDDS_ITEM
         {
            Current_Line := DecodeInteger( "uint4", p_l, 36 )+1
            If IndexList
               RegexMatch(IndexList, "S)(?:.*?\n){" Current_Line-1 "}(.*?)(?:\n|$)", Index)
            If (IndexList && (_%hLV%_%Index1%_Text != ""))
               EncodeInteger( _%hLV%_%Index1%_Text, 4, p_l, 48 )   ; indexed foreground
            Else If (_%hLV%_%Current_Line%_LText != "")
               EncodeInteger( _%hLV%_%Current_Line%_LText, 4, p_l, 48 )   ; line foreground
            If (IndexList && (_%hLV%_%Index1%_Back != ""))
               EncodeInteger( _%hLV%_%Index1%_Back, 4, p_l, 52 )   ; indexed background
            Else If (_%hLV%_%Current_Line%_LBack != "")
               EncodeInteger( _%hLV%_%Current_Line%_LBack, 4, p_l, 52 )   ; line background
         }
      }
   }

}


WM_NOTIFY( p_w, p_l, p_m )
{
   Critical
   ;/*
   ;Prevents column resizing, uncomment if resizing is buggy
   Index := DecodeInteger( "int4", p_l, 8 )
   If ((Index = -326) || (Index = -306))      ; HDN_BEGINTRACKA = -306, HDN_BEGINTRACKW = -326
      Return 1
   ;*/
      
   ;ADD YOUR CODE HERE   
      
   Return LV_WM_NOTIFY(p_l)
}



/*
>>>>CHANGELOG<<<<

1.0 (10-5-2009)
   - Original script
1.1 (10-6-2009)
   - Fixed a bug with adding a single file where the file would not be renamed
   -- Forgot to define the TargetFile's TargetFolder when updating the GUI
1.2 (10-13-2009)
   - Fixed another bug with adding a single file where the file would not be renamed
   - Fixed a bug with parsing the series overview where the non-comma delimiter (,) would be displayed
   -- Titans XPath replaces commas with "," (no quotes)
1.30 (11-8-2009)
   - Added a new method of selecting a show name when multiple results are returned
   -- Secondary ListView gui is displayed allowing the user to select the correct show
   - Script now compares the current filename against the previous filename (filenames converted to UPPERCASE)
   -- Drasitically reduces the number of requests against the TVDB and speeds everything up when renaming multiple shows all with the same name
   - Added a check and replace system for invalid filename characters
   -- StringReplace these chars \ / : * ? "" < > | with descriptive replacements
   - Fixed a bug in the GetEpisodeNumber() function
   -- A single digit season number would sometimes cause too few of the episode numbers to be returned when SeasonAndEpisode contained (e|x)
   - Tweaked GetSeasonNumber() and GetEpisodeNumber() to more reliably return correct data
   -- StringGetPos and String(Left|Right) were swapped for StringSplit to more predictably split SeasonAndEpisode regardless of (e|x) char location
   - Added a check to make sure files have a new filename in the preview column before renaming
   - Added a static window title which may be needed for various features in the future as well as making things look nicer :P
1.40 (11-15-2009)
   - Added status bar
   - Fixed a bug where a file would not have a preceeding zero added if no info was found on TheTVDB by adding PadZero() function
   -- Preceeding zero was only added in GetTVDBEpisodes() which means that if SeriesIDNo was blank (i.e. no info pulled from TheTVDB) the Season and Episode number would not get padded
1.41 (12-10-2009)
   - Fixed a serious bug where no results would be returned for ShowName inside the GetTVDBShows function would return the first result infinitely
   -- Had to clear the SeriesName var at the end of the function so that on the next loop iteration the correct var contents would exist
1.42 (12-11-2009)
   - Fixed a minor bug where the second time the GetTVDBInfo button was pressed, the first item in the list view would not actually be rescanned
   -- Had to clear the UpperPrevSN and PrevShowName vars so that the second time the button was pressed it would compare the correct names
   


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2011, 2:13 am 
Offline

Joined: February 5th, 2010, 8:20 pm
Posts: 22
looks good from the screenshot, guest, haven't actually tried it yet, but, I like the idea of detecting wrong info and allowing you to correct it that way...


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2012, 8:55 pm 
are there any updates on this? :D


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 71 posts ]  Go to page Previous  1, 2, 3, 4, 5

All times are UTC [ DST ]


Who is online

Users browsing this forum: MSN [Bot], nomissenrojb and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group