Hi,
I have many movies with subtitles but no internet connection.
Is it somehow possible to hash the movie and subtitle files offline
and upload the subtitles, when I have an internet connection ?
Code: Select all
#include <iostream>
#include <fstream>
using namespace std;
int MAX(int x, int y)
{
if((x) > (y))
return x;
else
return y;
}
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
;
uint64_t compute_hash(ifstream& f)
{
uint64_t hash, fsize;
f.seekg(0, ios::end);
fsize = f.tellg();
f.seekg(0, ios::beg);
hash = fsize;
for(uint64_t tmp = 0, i = 0; i < 65536/sizeof(tmp) && f.read((char*)&tmp, sizeof(tmp)); hash += tmp, i++);
f.seekg(MAX(0, (uint64_t)fsize - 65536), ios::beg);
for(uint64_t tmp = 0, i = 0; i < 65536/sizeof(tmp) && f.read((char*)&tmp, sizeof(tmp)); hash += tmp, i++);
return hash;
}
int getfilesize(ifstream& f)
{
int filesize;
f.seekg(0, ios::end);
filesize = f.tellg();
f.seekg(0, ios::beg);
return filesize;
}
int main(int argc, char *argv[])
{
ifstream f;
uint64_t myhash;
int fileSize;
// for(int i=0; i < argc; i++)
// cout<<argv[i]<<endl;
// f.open("/Volumes/video/TV/Lost/Lost S03E01.avi", ios::in|ios::binary|ios::ate); // Replace as adequate, obviously
f.open(argv[1], ios::in|ios::binary|ios::ate);
if (!f.is_open()) {
cerr << "Error opening file" << endl;
return 1;
}
myhash = compute_hash(f);
fileSize = getfilesize(f);
/*
// Try all possible printf combinations we can think of
printf("Hash should be 332c83338820e4f6\n");
printf("I64d: %I64d\n", myhash); // Borland BCC or MS VC++
printf("Ld: %Ld\n", myhash); // Borland BCC
printf("lld: %lld\n", myhash); // gcc
printf("I64x: %016I64x(hex)\n", myhash); // Borland BCC or Microsoft VC++ hex
printf("Lx: %016Lx(hex)\n", myhash);// Borland BCC hex
printf("llx: %016llx(hex)\n", myhash); // gcc hex
printf("I64x: %I64x(hex)\n", myhash); // Borland BCC or Microsoft VC++ hex
printf("Lx: %Lx(hex)\n", myhash);// Borland BCC hex
printf("llx: %llx(hex)\n", myhash); // gcc hex
*/
printf("%i\t%llx\t%s\n", fileSize, myhash, argv[1]); // gcc hex
f.close();
return 0;
}
Code: Select all
Moviename.avi opensubtitles_hash
Maybe I'm missing something here, but the way the hash is made, from what I've seen, shouldn't have be impacted by the size of the file.I have many many films without subtitles, and when I search for this collections new subtitles, I must wait and create hashes from all of them every time.
Option: Store hashes will be nice. In first time program calculate hash, and store it for disk (ex. in the same dir like video file, .hash). And in Search procedure program finds if exist hash for video file on the disk, if not, calcute them, if yes, skip generate and use this file.
When I have ~40 700-1.4GB films, and check it periodically all the time, this feature will help a lot for me.
James: I did understand you the first time. And my answer was directed to what you asked: Storing hashes does not significantly impact the time the program will finally take to run. Your HDD scrambling probably has more to do with waking from sleep (or standby) mode thant with generating the hash itself.well i dont know how are hashes calculated, but my HDD always scrambling for 5-10 sec...
This is unnecessary for those who search subtitles for a few films, but fine options for me and those users, who has plenty of films and search frequently for new subs.
And, I think this isn't hard to implement...
Users browsing this forum: No registered users and 26 guests