Sign in to follow this  
Followers 0
Datenshi

Opensubtitles.org Hashing Func

3 posts in this topic

#1 ·  Posted (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)
EndFunc

Authenticity's written for AutoIT v3.3.0.0

#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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0