From f495312ae91d1719145011f1f4bccf95dce2320a Mon Sep 17 00:00:00 2001 From: APTX Date: Sun, 15 Jan 2012 17:49:18 +0100 Subject: [PATCH] Add ed2k option. --- aniaddcli.cpp | 12 ++++++++---- aniaddcli.h | 3 ++- main.cpp | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/aniaddcli.cpp b/aniaddcli.cpp index c3e4953..4942303 100644 --- a/aniaddcli.cpp +++ b/aniaddcli.cpp @@ -5,7 +5,7 @@ #include AniAddCli::AniAddCli(QObject *parent) : - QObject(parent), printHash(false), cout(stdout, QIODevice::WriteOnly), showNewVersionInfo(false), closing(false), errorPrinted(false) + QObject(parent), printHash(false), printEd2k(false), cout(stdout, QIODevice::WriteOnly), showNewVersionInfo(false), closing(false), errorPrinted(false) { AniDBUdpClient::Client::instance()->setIdlePolicy(AniDBUdpClient::ImmediateLogoutIdlePolicy);; connect(AniDBUdpClient::Client::instance(), SIGNAL(connectionError()), this, SLOT(handleError())); @@ -30,7 +30,7 @@ void AniAddCli::setState(const AniDBUdpClient::MyListState &state) m_state = state; } -void AniAddCli::process(const QStringList &files, bool rename, bool add, bool setState, bool hash) +void AniAddCli::process(const QStringList &files, bool rename, bool add, bool setState, bool hash, bool ed2k) { foreach(const QString &fileName, files) { @@ -63,10 +63,11 @@ void AniAddCli::process(const QStringList &files, bool rename, bool add, bool se file->setState(m_state); - if (hash) + if (hash || ed2k) { file->hash(); - printHash = true; + printHash = hash; + printEd2k = ed2k; } if (rename) file->rename(); @@ -161,6 +162,9 @@ void AniAddCli::handleStatusUpdate(AniDBUdpClient::File::Action action, AniDBUdp if (printHash && action == AniDBUdpClient::File::Hashing && state == AniDBUdpClient::File::Success) cout << "[HASH] " << file->file().fileName() << " - " << file->ed2k() << endl; + + if (printEd2k && action == AniDBUdpClient::File::Adding && state == AniDBUdpClient::File::Failure && !file->ed2k().isEmpty()) + cout << "[ED2K] ed2k://|file|" << file->file().fileName() << "|" << file->file().size() << "|" << file->ed2k() << "|/" << endl; } void AniAddCli::handleError() diff --git a/aniaddcli.h b/aniaddcli.h index 2d1ce84..d502909 100644 --- a/aniaddcli.h +++ b/aniaddcli.h @@ -17,7 +17,7 @@ public: AniDBUdpClient::MyListState state() const; void setState(const AniDBUdpClient::MyListState &state); - void process(const QStringList &files, bool rename = true, bool add = true, bool setState = true, bool hash = false); + void process(const QStringList &files, bool rename = true, bool add = true, bool setState = true, bool hash = false, bool ed2k = false); @@ -38,6 +38,7 @@ private: AniDBUdpClient::MyListState m_state; bool printHash; + bool printEd2k; bool showNewVersionInfo; bool closing; bool errorPrinted; diff --git a/main.cpp b/main.cpp index 1365ff9..d47b406 100644 --- a/main.cpp +++ b/main.cpp @@ -98,6 +98,8 @@ int main(int argc, char *argv[]) opts.add("no-update-state", "Do not update state", QxtCommandOptions::NoValue, 3); opts.add("hash", "Print hash", QxtCommandOptions::NoValue, 4); opts.add("no-hash", "Do not print hash", QxtCommandOptions::NoValue, 4); + opts.add("ed2k", "Print ed2k URIs for files which failed to be added", QxtCommandOptions::NoValue, 5); + opts.add("no-ed2k", "Do not print ed2k URIs", QxtCommandOptions::NoValue, 5); opts.addSection("Account settings"); opts.add("user", "AniDB user name", QxtCommandOptions::ValueRequired); @@ -146,6 +148,7 @@ int main(int argc, char *argv[]) bool add = true; bool setState = true; bool hash = false; + bool ed2k = false; // Read settings from config if (!opts.count("no-config")) @@ -158,6 +161,7 @@ int main(int argc, char *argv[]) add = s.value("add", add).toBool(); setState = s.value("setState", setState).toBool(); hash = s.value("hash", hash).toBool(); + ed2k = s.value("ed2k", ed2k).toBool(); s.endGroup(); s.beginGroup("account"); c->setUser(s.value("user", "").toString()); @@ -204,6 +208,10 @@ int main(int argc, char *argv[]) hash = true; if (opts.count("no-hash")) hash = false; + if (opts.count("ed2k")) + ed2k = true; + if (opts.count("no-ed2k")) + ed2k = false; if (opts.count("user")) c->setUser(opts.value("user").toString()); @@ -252,7 +260,8 @@ int main(int argc, char *argv[]) cout << " Add: " << (add ? "Yes" : "No") << endl; cout << " Rename: " << (rename ? "Yes" : "No") << endl; cout << " Update State: " << (setState ? "Yes" : "No") << endl; - cout << " Print Hash: " << (hash ? "Yes" : "No") << endl << endl; + cout << " Print Hash: " << (hash ? "Yes" : "No") << endl; + cout << " Print ed2k: " << (ed2k ? "Yes" : "No") << endl << endl; cout << "Account settings:" << endl; cout << " User: " << c->user() << endl; @@ -283,6 +292,7 @@ int main(int argc, char *argv[]) s.setValue("add", add); s.setValue("setState", setState); s.setValue("hash", hash); + s.setValue("ed2k", ed2k); s.endGroup(); s.beginGroup("account"); s.setValue("user", c->user()); @@ -313,7 +323,7 @@ int main(int argc, char *argv[]) AniAddCli t; t.setState(state); - t.process(opts.positional(), rename, add, setState, hash); + t.process(opts.positional(), rename, add, setState, hash, ed2k); return a.exec(); } -- 2.52.0