Commit c08a0136f6e59da468018395dcd627a77ec47203
1 parent
03ae5097
download now outputs metadata templates as well
Showing
1 changed file
with
8 additions
and
2 deletions
app/br-download/br-download.cpp
| @@ -50,7 +50,7 @@ static bool json = false; | @@ -50,7 +50,7 @@ static bool json = false; | ||
| 50 | static bool permissive = false; | 50 | static bool permissive = false; |
| 51 | static bool url_provided = false; | 51 | static bool url_provided = false; |
| 52 | 52 | ||
| 53 | -static void process(QString url, QNetworkAccessManager &nam) | 53 | +static void process(QString url, const QByteArray &metadata, QNetworkAccessManager &nam) |
| 54 | { | 54 | { |
| 55 | url = url.simplified(); | 55 | url = url.simplified(); |
| 56 | if (url.isEmpty()) | 56 | if (url.isEmpty()) |
| @@ -88,6 +88,11 @@ static void process(QString url, QNetworkAccessManager &nam) | @@ -88,6 +88,11 @@ static void process(QString url, QNetworkAccessManager &nam) | ||
| 88 | 88 | ||
| 89 | const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); | 89 | const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); |
| 90 | br_append_utemplate_contents(stdout, reinterpret_cast<const unsigned char*>(hash.data()), reinterpret_cast<const unsigned char*>(hash.data()), 3, data.size(), reinterpret_cast<const unsigned char*>(data.data())); | 90 | br_append_utemplate_contents(stdout, reinterpret_cast<const unsigned char*>(hash.data()), reinterpret_cast<const unsigned char*>(hash.data()), 3, data.size(), reinterpret_cast<const unsigned char*>(data.data())); |
| 91 | + | ||
| 92 | + if (!metadata.isEmpty()) { | ||
| 93 | + const QByteArray metadataHash = QCryptographicHash::hash(metadata, QCryptographicHash::Md5); | ||
| 94 | + br_append_utemplate_contents(stdout, reinterpret_cast<const unsigned char*>(hash.data()), reinterpret_cast<const unsigned char*>(metadataHash.data()), 2, metadata.size() + 1 /* include null terminator */, reinterpret_cast<const unsigned char*>(metadata.data())); | ||
| 95 | + } | ||
| 91 | } | 96 | } |
| 92 | 97 | ||
| 93 | int main(int argc, char *argv[]) | 98 | int main(int argc, char *argv[]) |
| @@ -99,7 +104,7 @@ int main(int argc, char *argv[]) | @@ -99,7 +104,7 @@ int main(int argc, char *argv[]) | ||
| 99 | if (!strcmp(argv[i], "-help" )) { help(); exit(EXIT_SUCCESS); } | 104 | if (!strcmp(argv[i], "-help" )) { help(); exit(EXIT_SUCCESS); } |
| 100 | else if (!strcmp(argv[i], "-json" )) json = true; | 105 | else if (!strcmp(argv[i], "-json" )) json = true; |
| 101 | else if (!strcmp(argv[i], "-permissive")) permissive = true; | 106 | else if (!strcmp(argv[i], "-permissive")) permissive = true; |
| 102 | - else { url_provided = true; process(argv[i], nam); } | 107 | + else { url_provided = true; process(argv[i], QByteArray(), nam); } |
| 103 | } | 108 | } |
| 104 | 109 | ||
| 105 | if (!url_provided) { | 110 | if (!url_provided) { |
| @@ -109,6 +114,7 @@ int main(int argc, char *argv[]) | @@ -109,6 +114,7 @@ int main(int argc, char *argv[]) | ||
| 109 | const QByteArray line = file.readLine(); | 114 | const QByteArray line = file.readLine(); |
| 110 | process(json ? QJsonDocument::fromJson(line).object().value("URL").toString() | 115 | process(json ? QJsonDocument::fromJson(line).object().value("URL").toString() |
| 111 | : QString::fromLocal8Bit(line), | 116 | : QString::fromLocal8Bit(line), |
| 117 | + json ? line.simplified() : QByteArray(), | ||
| 112 | nam); | 118 | nam); |
| 113 | } | 119 | } |
| 114 | } | 120 | } |