Jump to content



Photo

Opensubtitles.org Hashing Func


  • Please log in to reply
No replies to this topic

#1 Datenshi

Datenshi

    Prodigy

  • Active Members
  • PipPipPip
  • 179 posts

Posted 20 December 2009 - 06:21 PM

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
Plain Text         
#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) EndFunc


Authenticity's written for AutoIT v3.3.0.0
Plain Text         
#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 by Datenshi, 20 December 2009 - 06:22 PM.











0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users