1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "osclient.h"
|
---|
20 | #include "version.h"
|
---|
21 |
|
---|
22 | OSClient::OSClient(QObject* parent) : QObject(parent), logged_in(false), search_size(0) {
|
---|
23 | rpc = new MaiaXmlRpcClient(QUrl("http://api.opensubtitles.org/xml-rpc"), this);
|
---|
24 | }
|
---|
25 |
|
---|
26 | void OSClient::setServer(const QString & server) {
|
---|
27 | rpc->setUrl(QUrl(server));
|
---|
28 | }
|
---|
29 |
|
---|
30 | void OSClient::setProxy(const QNetworkProxy & proxy) {
|
---|
31 | rpc->setProxy(proxy);
|
---|
32 | }
|
---|
33 |
|
---|
34 | void OSClient::login() {
|
---|
35 | qDebug("OSClient::login");
|
---|
36 |
|
---|
37 | QString user_agent = "SMPlayer v" + stableVersion();
|
---|
38 | qDebug("OSClient::login: user agent: %s", user_agent.toUtf8().constData());
|
---|
39 |
|
---|
40 | QVariantList args;
|
---|
41 |
|
---|
42 | args << "" << "" << "" << user_agent;
|
---|
43 |
|
---|
44 | rpc->call("LogIn", args,
|
---|
45 | this, SLOT(responseLogin(QVariant &)),
|
---|
46 | this, SLOT(gotFault(int, const QString &)));
|
---|
47 | }
|
---|
48 |
|
---|
49 | void OSClient::search(const QString & hash, qint64 file_size) {
|
---|
50 | #ifdef Q_OS_WIN
|
---|
51 | qDebug("OSClient::search: hash: %s, file_size: %I64d", hash.toUtf8().constData(), file_size);
|
---|
52 | #else
|
---|
53 | qDebug("OSClient::search: hash: %s, file_size: %lld", hash.toUtf8().constData(), file_size);
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | search_hash = hash;
|
---|
57 | search_size = file_size;
|
---|
58 |
|
---|
59 | #if 0
|
---|
60 | if (logged_in) {
|
---|
61 | doSearch();
|
---|
62 | } else {
|
---|
63 | connect(this, SIGNAL(loggedIn()), this, SLOT(doSearch()));
|
---|
64 | login();
|
---|
65 | }
|
---|
66 | #else
|
---|
67 | connect(this, SIGNAL(loggedIn()), this, SLOT(doSearch()));
|
---|
68 | login();
|
---|
69 | #endif
|
---|
70 | }
|
---|
71 |
|
---|
72 | void OSClient::doSearch() {
|
---|
73 | qDebug("OSClient::doSearch");
|
---|
74 |
|
---|
75 | QVariantMap m;
|
---|
76 | m["sublanguageid"] = "all";
|
---|
77 | m["moviehash"] = search_hash;
|
---|
78 | m["moviebytesize"] = QString::number(search_size);
|
---|
79 |
|
---|
80 | QVariantList list;
|
---|
81 | list.append(m);
|
---|
82 |
|
---|
83 | QVariantList args;
|
---|
84 | args << token << QVariant(list);
|
---|
85 |
|
---|
86 | /*
|
---|
87 | for (int n=0; n < args.count(); n++) {
|
---|
88 | qDebug("%d = %d (%s)", n, args[n].type(), args[n].typeName());
|
---|
89 | }
|
---|
90 | */
|
---|
91 |
|
---|
92 | rpc->call("SearchSubtitles", args,
|
---|
93 | this, SLOT(responseSearch(QVariant &)),
|
---|
94 | this, SLOT(gotFault(int, const QString &)));
|
---|
95 | }
|
---|
96 |
|
---|
97 | void OSClient::responseLogin(QVariant &arg) {
|
---|
98 | qDebug("OSClient::responseLogin");
|
---|
99 |
|
---|
100 | QVariantMap m = arg.toMap();
|
---|
101 | QString status = m["status"].toString();
|
---|
102 | QString t = m["token"].toString();
|
---|
103 |
|
---|
104 | qDebug("OSClient::responseLogin: status: %s", status.toLatin1().constData());
|
---|
105 | qDebug("OSClient::responseLogin: token: %s", t.toLatin1().constData());
|
---|
106 |
|
---|
107 | if (status == "200 OK") {
|
---|
108 | token = t;
|
---|
109 | logged_in = true;
|
---|
110 | emit loggedIn();
|
---|
111 | } else {
|
---|
112 | emit loginFailed();
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | void OSClient::responseSearch(QVariant &arg) {
|
---|
117 | qDebug("OSClient::responseSearch");
|
---|
118 |
|
---|
119 | QVariantMap m = arg.toMap();
|
---|
120 | QString status = m["status"].toString();
|
---|
121 |
|
---|
122 | qDebug("OSClient::responseSearch: status: %s", status.toLatin1().constData());
|
---|
123 | //qDebug("count: %d", m.count());
|
---|
124 |
|
---|
125 | /*
|
---|
126 | QMapIterator<QString, QVariant> i(m);
|
---|
127 | while (i.hasNext()) {
|
---|
128 | i.next();
|
---|
129 | qDebug("key: %s", i.key().toLatin1().constData());
|
---|
130 | }
|
---|
131 | */
|
---|
132 |
|
---|
133 | if (status != "200 OK") {
|
---|
134 | emit searchFailed();
|
---|
135 | return;
|
---|
136 | }
|
---|
137 |
|
---|
138 | QVariantList data = m["data"].toList();
|
---|
139 | qDebug("OSClient::responseSearch: data count: %d", data.count());
|
---|
140 |
|
---|
141 | for (int n = 0; n < data.count(); n++) {
|
---|
142 | OSSubtitle sub;
|
---|
143 |
|
---|
144 | //qDebug("%d: type: %d (%s)", n, data[n].type(), data[n].typeName());
|
---|
145 | QVariantMap m = data[n].toMap();
|
---|
146 |
|
---|
147 | sub.releasename = m["MovieReleaseName"].toString();
|
---|
148 | sub.movie = m["MovieName"].toString();
|
---|
149 | sub.link = m["ZipDownloadLink"].toString();
|
---|
150 | sub.date = m["SubAddDate"].toString();
|
---|
151 | sub.iso639 = m["ISO639"].toString();
|
---|
152 | sub.rating = m["SubRating"].toString();
|
---|
153 | sub.comments = m["SubAuthorComment"].toString();
|
---|
154 | sub.format = m["SubFormat"].toString();
|
---|
155 | sub.language = m["LanguageName"].toString();
|
---|
156 | sub.user = m["UserNickName"].toString();
|
---|
157 | sub.files = "1";
|
---|
158 |
|
---|
159 | s_list.append(sub);
|
---|
160 |
|
---|
161 | /*
|
---|
162 | qDebug("MovieName: %s", sub.movie.toLatin1().constData());
|
---|
163 | qDebug("MovieReleaseName: %s", sub.releasename.toLatin1().constData());
|
---|
164 | //qDebug("SubFileName: %s", m["SubFileName"].toString().toLatin1().constData());
|
---|
165 | //qDebug("SubDownloadLink: %s", m["SubDownloadLink"].toString().toLatin1().constData());
|
---|
166 | qDebug("ZipDownloadLink: %s", sub.link.toLatin1().constData());
|
---|
167 | qDebug("SubAddDate: %s", sub.date.toLatin1().constData());
|
---|
168 | qDebug("ISO639: %s", sub.iso639.toLatin1().constData());
|
---|
169 | qDebug("SubRating: %s", sub.rating.toLatin1().constData());
|
---|
170 | qDebug("SubAuthorComment: %s", sub.comments.toLatin1().constData());
|
---|
171 | qDebug("SubFormat: %s", sub.format.toLatin1().constData());
|
---|
172 | qDebug("LanguageName: %s", sub.language.toLatin1().constData());
|
---|
173 | qDebug("UserNickName: %s", sub.user.toLatin1().constData());
|
---|
174 | qDebug("=======");
|
---|
175 | */
|
---|
176 | }
|
---|
177 |
|
---|
178 | emit searchFinished();
|
---|
179 | }
|
---|
180 |
|
---|
181 | void OSClient::gotFault(int error, const QString &message) {
|
---|
182 | qDebug("OSClient::gotFault: error: %d, message: %s", error, message.toUtf8().constData());
|
---|
183 | emit errorFound(error, message);
|
---|
184 | }
|
---|
185 |
|
---|
186 | #include "moc_osclient.cpp"
|
---|