2

我正在尝试为 Javascript 中的文件计算正确的 OpenSubtitles 哈希码,但对于大文件,它无法正常工作 - 所以我认为文件大小存在问题(溢出)。此处描述了带有源代码的 OpenSubtitles 哈希:http: //trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes

我正在使用虚拟 RAR 文件(未打包)测试此代码 - http://www.opensubtitles.org/addons/avi/dummy.rar,正确结果是61f7751fc2a72bfb但此代码给出61f7751ec2a72bfb - 所以有一些错误。我不擅长 Javascript。我还发现其他人也遇到了类似的问题: http: //forum.opensubtitles.org/viewtopic.php?f =8&t=13243也许这可行:https ://github.com/ka2er/node-opensubtitles-api/blob/主/lib/opensubtitles.js

问题是,需要改变什么,所以我得到正确的哈希?谢谢。

function binl2hex(a)
{
    var b = 255;
    a[1] += a[0] >> 8;
    a[0] = a[0] & b;
    a[2] += a[1] >> 8;
    a[1] = a[1] & b;
    a[3] += a[2] >> 8;
    a[2] = a[2] & b;
    a[4] += a[3] >> 8;
    a[3] = a[3] & b;
    a[5] += a[4] >> 8;
    a[4] = a[4] & b;
    a[6] += a[5] >> 8;
    a[5] = a[5] & b;
    a[7] += a[6] >> 8;
    a[6] = a[6] & b;
    a[7] = a[7] & b;
    for (var d = "0123456789abcdef", e = "", c = 7; c > -1; c--) 
        e += d.charAt(a[c] >> 4 & 15) + d.charAt(a[c] & 15);
    return e
}

$(document).ready(function() 
{
    jQuery.event.props.push('dataTransfer');
    $('#search_field').bind('drop', function(e) 
    {
        var files = e.dataTransfer.files;
        $.each(files, function(index, file) 
        {
            if(files.length > 1) 
            {
                $('#top_msg').attr('class', 'msg warn');
                $('#top_msg').html('multiple files are <b>not supported</b> (yet)');   
                return false;
            }        

            if (!files[index].type.match('video.*') && !files[index].name.match(/\.(mkv)$/i)) 
            { 
                //|| !files[index].name.match('/mkv/i')
                $('#top_msg').attr('class', 'msg warn');            
                $('#top_msg').html('search works only for <b>video</b> files.');
                return false;
            }    

            $('#top_msg').html('<b>File upload and hashing in progress</b>...');
            $('#top_msg').attr('class', 'msg indicator');

            var b = 65536;        
            fs = file.size;
            var e = Array(8);
            for (var a = fs, f = 0; f < 8; f++) 
            {
                e[f] = a & 255;
                a = a >> 8
            }
            a = fs;    

            var c = file.slice(0, b);
            var g = new FileReader;   

            g.onloadend = function (h) 
            {
                if (h.target.readyState == FileReader.DONE) 
                {
                    for (var f = h.target.result, d = 0; d < f.length; d++) 
                        e[(d + 8) % 8] += f.charCodeAt(d);
                    c = file.slice(a - b);
                    var g = new FileReader;   

                    g.onloadend = function (c) 
                    {
                        var b = "languages";
                        if (c.target.readyState == FileReader.DONE) 
                        {
                            f = c.target.result;
                            for (d = 0; d < f.length; d++) 
                                e[(d + 8) % 8] += f.charCodeAt(d);  
                            lang = $("#SubLanguageID").multiselect("getChecked").map(function()
                            {
                                return this.value
                            }).get().join(",");
                            if (lang == "") 
                                lang = "all";
                            var url = "http://www.opensubtitles.org/" + $(location).attr('pathname').substr(1,2) + "/search/sublanguageid-" + lang + "/moviehash-" + binl2hex(e);
                            document.location = url;
                        }
                    };

                    g.readAsBinaryString(c)
                }
            };
            g.readAsBinaryString(c)
        });
    });
});   
4

0 回答 0