]> Some of my projects - AniAddCLI.git/commitdiff
Add ed2k option.
authorAPTX <marek321@gmail.com>
Sun, 15 Jan 2012 16:49:18 +0000 (17:49 +0100)
committerAPTX <marek321@gmail.com>
Sun, 15 Jan 2012 16:49:18 +0000 (17:49 +0100)
aniaddcli.cpp
aniaddcli.h
main.cpp

index c3e495337f341c3565c266f403f9205ed6e7b873..4942303126bd0ea99c1083cf48bc6daea20b8266 100644 (file)
@@ -5,7 +5,7 @@
 #include <QFileInfo>
 
 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()
index 2d1ce841f5711773dd7e837914c6ce9b8193329c..d50290922a3adb420f90b842dd5f85f3ba6b22ae 100644 (file)
@@ -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;
index 1365ff9daf95ac705570ef17bcbc6c6d356a23b7..d47b4069fc844f3ca45ccffa8c9916ad9885a91e 100644 (file)
--- 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();
 }