Datenshi Posted December 20, 2009 Share Posted December 20, 2009 (edited) This function does the same hash calculation as hosted here, HashSourceCodes. With it, you could build a script which downloads subtitles for any movie files you may have, Opensubtitles.org has a custom API which accepts this hash checksum and its practically bulletproof when it comes to accurate subs.Autenticity's script rewritten by Datenshi, and speed optimized. This is about 100% faster, but is written for AutoIT v3.3.2.0#cs Hash code is based on Media Player Classic. It calculates: size + 64bit checksum of the first and last 64k (even if they overlap because the file is smaller than 128k). Authors: Authenticity & Emanuel "Datenshi" Lindgren @ AutoIT Forums. AutoIT v3.3.2.0 #ce Func _Compute_Hash($sFileName) Local $hFile, $tRet, $tTmp, $iFileSize, $iRead, $iChunk, $iI $hFile = FileOpen($sFileName, 16) If Not $hFile Then Return SetError(1, 0, 0) $iFileSize = FileGetSize($sFileName) $iChunk = 65536 If $iFileSize < $iChunk * 2 Then FileClose($hFile) Return SetError(2, 0, 0) EndIf $tRet = DllStructCreate("uint64") $tTmp = DllStructCreate("uint64") DllStructSetData($tRet, 1, $iFileSize) For $iI = 0 To ($iChunk / 8) - 1 DllStructSetData($tTmp, 1, FileRead($hFile, 8)) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next FileSetPos($hFile, $iFileSize - $iChunk, 0) For $iI = 0 To ($iChunk / 8) - 1 DllStructSetData($tTmp, 1, FileRead($hFile, 8)) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next FileClose($hFile) Return SetError(0, 0, _HEX(DllStructGetData($tRet, 1))) EndFunc Func _HEX($iValue) Return StringFormat("%#.8x%.8x", $iValue / 4294967296, $iValue) EndFuncAuthenticity's written for AutoIT v3.3.0.0expandcollapse popup#include <Constants.au3> #include <WinAPI.au3> Func _Compute_Hash($sFileName) Local $hFile, $tRet, $tTmp, $pTmp, $iFileSize, $iRead, $iChunk, $iI $hFile = _WinAPI_CreateFile($sFileName, 2, 2, 6) If Not $hFile Then Return SetError(1, 0, 0) $iFileSize = _WinAPI_SetFilePointer($hFile, 0, $FILE_END) $iChunk = 65536 If $iFileSize < $iChunk * 2 Then _WinAPI_CloseHandle($hFile) Return SetError(2, 0, 0) EndIf $tRet = DllStructCreate("uint64") $tTmp = DllStructCreate("uint64") $pTmp = DllStructGetPtr($tTmp) DllStructSetData($tRet, 1, $iFileSize) _WinAPI_SetFilePointer($hFile, 0, $FILE_BEGIN) For $iI = 0 To ($iChunk/8)-1 _WinAPI_ReadFile($hFile, $pTmp, 8, $iRead) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next _WinAPI_SetFilePointer($hFile, MAX(0, $iFileSize-$iChunk), $FILE_BEGIN) For $iI = 0 To ($iChunk/8)-1 _WinAPI_ReadFile($hFile, $pTmp, 8, $iRead) DllStructSetData($tRet, 1, DllStructGetData($tRet, 1) + DllStructGetData($tTmp, 1)) Next _WinAPI_CloseHandle($hFile) Return SetError(0, 0, DllStructGetData($tRet, 1)) EndFunc Func MAX($a, $b) If $a > $b Then Return $a Return $b EndFunc Func _HEX($iValue) Return StringFormat("%#.8x%.8x", $iValue/4294967296, $iValue) EndFunc Edited December 20, 2009 by Datenshi RapidQueuer 2.4 - For Rapidshare.comOpensubtitles Hashing FuncRevision3 PlayerGTPlayer BetaIMDB & Poster Grabber v1.3Fetgrek.com - My Website Link to comment Share on other sites More sharing options...
jaja714 Posted June 25, 2014 Share Posted June 25, 2014 I hear you are using this for opensubtitles.org but I never saw any follow-up examples regarding how to actually make the call given the movie title. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 25, 2014 Moderators Share Posted June 25, 2014 jaja714,The first post in this thread dates from nearly 5 years ago and the OP has not been online for over 3 years - and you expect an answer? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts