realslacker Posted March 17, 2011 Share Posted March 17, 2011 I created this script to help my auto-sort daily show episodes, maybe someone else will find it useful.This script uses by SmOke_N as well as the windows version of wget.expandcollapse popup#include <FileListToArrayEx.au3> #include <File.au3> $regkey = "HKEY_CURRENT_USER\Software\Brooksworks\DailyShowEpNamer" $apikey = RegRead($regkey,"apikey") ; API Key from thetvdb.com $season = RegRead($regkey,"season") ; last found season $episode = RegRead($regkey,"episode") ; last found episode If $apikey == "" Then $apikey = InputBox("TheTVDB API Key","Please enter your API Key for thetvdb.com:") RegWrite($regkey,"apikey","REG_SZ",$apikey) EndIf If $season == "" Or $episode == "" Then $season = InputBox("Season","Please enter the starting season:") $episode = InputBox("Episode","Please enter the starting episode:") RegWrite($regkey,"season","REG_DWORD",$season) RegWrite($regkey,"episode","REG_DWORD",$episode) ElseIf @MON&"-"&@MDAY == "01-01" Then $season = $season + 1 $episode = 1 RegWrite($regkey,"season","REG_DWORD",$season) RegWrite($regkey,"episode","REG_DWORD",$episode) EndIf If $CmdLine[0] == 0 Then MsgBox(0,"Error","Must supply directory to scan as first argument.") Exit EndIf $DirToScan = $CmdLine[1] If FileExists($DirToScan) == 0 Then MsgBox(0,"Error","Supplied directory does not exist.") Exit EndIf $aDownloads = _FileListToArrayEx($DirToScan,"*.avi;*.mkv;*.mpg;*.mpeg",1) If $aDownloads == 0 Then Exit EndIf For $i = 1 To $aDownloads[0] If StringRegExp($aDownloads[$i],"(?i)daily.show.\d{4}.\d{2}.\d{2}") Then $sFileName = StringRegExpReplace($aDownloads[$i],".*\\([^\\]*)\z","\1") $sDirName = StringRegExpReplace($aDownloads[$i],"(.*\\)[^\\]*\z","\1") $sEpDate = StringRegExpReplace($sFileName,".*(\d{4}).(\d{2}).(\d{2}).*","\1-\2-\3") $sEpExt = StringRegExpReplace($sFileName,".*(\.[a-z]{3,4})\z","\1") $sXML = _SearchEpByDate($sEpDate) $season = StringRegExpReplace($sXML,"(?s).*<SeasonNumber>(\d+)</SeasonNumber>.*","\1") $episode = StringRegExpReplace($sXML,"(?s).*<EpisodeNumber>(\d+)</EpisodeNumber>.*","\1") $dest = $sDirName&"The Daily Show with Jon Stewart - S"&$season&"E"&$episode&$sEpExt FileMove($aDownloads[$i],$dest,9) RegWrite($regkey,"episode","REG_DWORD",$episode) EndIf Next Func _SearchEpByDate($date) RunWait("wget http://www.thetvdb.com/api/"&$apikey&"/series/71256/default/"&$season&"/"&$episode&"/en.xml --output-document=temp-ds-ep-namer.xml",@TempDir) Local $sXML = FileRead(@TempDir&"\temp-ds-ep-namer.xml") FileDelete(@TempDir&"\temp-ds-ep-namer.xml") Local $sEpDate = StringRegExpReplace($sXML,"(?s).*<FirstAired>(.*?)</FirstAired>.*","\1") Local $cmp = _EpDateCmp($sEpDate,$date) If $cmp == 0 Then Return $sXML ElseIf $cmp == -1 Then $episode = $episode + 1 Return _SearchEpByDate($date) ElseIf $cmp == 1 Then $episode = $episode - 1 Return _SearchEpByDate($date) EndIf EndFunc Func _EpDateCmp($a,$b) $a = StringReplace($a,"-","") $b = StringReplace($b,"-","") If $a < $b Then Return -1 ElseIf $b < $a Then Return 1 Else Return 0 EndIf EndFuncI know the code is not the cleanest, and possibly not the best but it works for me. 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