Commit c08a0136f6e59da468018395dcd627a77ec47203

Authored by Josh Klontz
1 parent 03ae5097

download now outputs metadata templates as well

app/br-download/br-download.cpp
... ... @@ -50,7 +50,7 @@ static bool json = false;
50 50 static bool permissive = false;
51 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 55 url = url.simplified();
56 56 if (url.isEmpty())
... ... @@ -88,6 +88,11 @@ static void process(QString url, QNetworkAccessManager &nam)
88 88  
89 89 const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
90 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 98 int main(int argc, char *argv[])
... ... @@ -99,7 +104,7 @@ int main(int argc, char *argv[])
99 104 if (!strcmp(argv[i], "-help" )) { help(); exit(EXIT_SUCCESS); }
100 105 else if (!strcmp(argv[i], "-json" )) json = true;
101 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 110 if (!url_provided) {
... ... @@ -109,6 +114,7 @@ int main(int argc, char *argv[])
109 114 const QByteArray line = file.readLine();
110 115 process(json ? QJsonDocument::fromJson(line).object().value("URL").toString()
111 116 : QString::fromLocal8Bit(line),
  117 + json ? line.simplified() : QByteArray(),
112 118 nam);
113 119 }
114 120 }
... ...