Made a small tool for my own amusement to download (swe/eng) subtitles from diffrents sources and opensubtitles is one of the best ones and now I wanted to contribute by adding uploding fuctionality in my code but don't understand how the subtitlehash is calculated , I use the same code (see below) as I use to calculate moviehash but it's not a match with the subtitlehash on the subtitle downloaded.
For example: Bones.S04E01E02.720p.HDTV.X264-DIMENSION
Moviehash = d51ed8ab9b5c436a
When I download the english srt it has subtitlehash = 56df05ef3ba83fd82252ae09ef2e6051
If i calculate a hash for the download srt file using the same code as I use for movies I get hash = 5faa63a7aa5429e4
Why is the subtitle hash longer than the movie hash ? And how should I calculate it ?
Code: Select all
{
class MovieHash
{
public static byte[] ComputeMovieHash(string filename)
{
byte[] result;
using (Stream input = File.OpenRead(filename))
{
result = ComputeMovieHash(input);
}
return result;
}
public static byte[] ComputeMovieHash(Stream input)
{
long lhash, streamsize;
streamsize = input.Length;
lhash = streamsize;
long i = 0;
byte[] buffer = new byte[sizeof(long)];
while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
{
i++;
lhash += BitConverter.ToInt64(buffer, 0);
}
input.Position = Math.Max(0, streamsize - 65536);
i = 0;
while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
{
i++;
lhash += BitConverter.ToInt64(buffer, 0);
}
input.Close();
byte[] result = BitConverter.GetBytes(lhash);
Array.Reverse(result);
return result;
}
public static string ToHexadecimal(byte[] bytes)
{
StringBuilder hexBuilder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
hexBuilder.Append(bytes[i].ToString("x2"));
}
return hexBuilder.ToString();
}
}
}