Last active
August 29, 2015 14:14
-
-
Save wolfgangkarall/d96b181292738e0278d8 to your computer and use it in GitHub Desktop.
Calculating hashes for video files as used by MythTV in the DB table videometadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on Debian/Ubuntu: | |
// - install libqt4-dev | |
// - put file into a directory called mythhash | |
// - run: | |
// qmake -project | |
// qmake | |
// make | |
// C++ headers | |
#include <iostream> | |
using namespace std; | |
// Qt headers | |
#include <QtCore> | |
#include <QDataStream> | |
#include <QFileInfo> | |
#include <QFile> | |
#include <QDebug> | |
QString FileHash(QString filename) | |
{ | |
QFile file(filename); | |
QFileInfo fileinfo(file); | |
qint64 initialsize = fileinfo.size(); | |
quint64 hash = 0; | |
if (initialsize == 0) | |
return QString("NULL"); | |
if (file.open(QIODevice::ReadOnly)) | |
hash = initialsize; | |
else | |
{ | |
return QString("NULL"); | |
} | |
file.seek(0); | |
QDataStream stream(&file); | |
stream.setByteOrder(QDataStream::LittleEndian); | |
for (quint64 tmp = 0, i = 0; i < 65536/sizeof(tmp); i++) | |
{ | |
stream >> tmp; | |
hash += tmp; | |
} | |
file.seek(initialsize - 65536); | |
for (quint64 tmp = 0, i = 0; i < 65536/sizeof(tmp); i++) | |
{ | |
stream >> tmp; | |
hash += tmp; | |
} | |
file.close(); | |
QString output = QString("%1").arg(hash, 0, 16); | |
return output; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication app(argc, argv); | |
if (argc == 1) { | |
std::cout << "Usage: mythhash <file>" << std::endl; | |
exit(1); | |
} else { | |
QString filename = QString::fromUtf8(argv[1]); | |
QString filehash = FileHash(filename); | |
std::string utf8_text = filehash.toUtf8().constData(); | |
std::cout << utf8_text << std::endl; | |
exit(0); | |
} | |
} | |
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment