Skip to content

Commit

Permalink
Display in the status bar the remaining downloads from opensubtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
smplayer-dev committed Jan 3, 2024
1 parent a5735ef commit bf160e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/findsubtitles/findsubtitleswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ void FindSubtitlesWindow::showDownloadFailed() {

void FindSubtitlesWindow::showErrorOS(int, const QString & error) {
status->setText(error);
if (error.contains("299:")) {
status->setText(tr("Error: daily quota exceeded"));
}
}

void FindSubtitlesWindow::updateDataReadProgress(int done, int total) {
Expand Down Expand Up @@ -495,16 +498,15 @@ void FindSubtitlesWindow::itemActivated(const QModelIndex & index ) {
QString file_id = item->data(DATA_FILE_ID).toString();
qDebug() << "FindSubtitlesWindow::itemActivated: file_id:" << file_id;

int remaining_downloads;
if (download_link.isEmpty()) {
download_link = osclient->getDownloadLink(file_id);
download_link = osclient->getDownloadLink(file_id, &remaining_downloads);
item->setData(download_link);
}
qDebug() << "FindSubtitlesWindow::itemActivated: download link:" << download_link;

if (download_link.isEmpty()) {
// Failed to get the download link
QMessageBox::warning(this, tr("Error"),
tr("Failed to get the URL of the subtitle file.\nCheck your login credentials."));
return;
}

Expand All @@ -514,6 +516,7 @@ void FindSubtitlesWindow::itemActivated(const QModelIndex & index ) {
#else
QDesktopServices::openUrl( QUrl(download_link) );
#endif
status->setText(tr("Remaining downloads: %1").arg(remaining_downloads));
}

void FindSubtitlesWindow::download() {
Expand All @@ -531,12 +534,17 @@ void FindSubtitlesWindow::copyLink() {
QString download_link = item->data().toString();
QString file_id = item->data(DATA_FILE_ID).toString();
qDebug() << "FindSubtitlesWindow::copyLink: file_id:" << file_id;

int remaining_downloads;
if (download_link.isEmpty()) {
download_link = osclient->getDownloadLink(file_id);
download_link = osclient->getDownloadLink(file_id, &remaining_downloads);
item->setData(download_link);
}
qDebug() << "FindSubtitlesWindow::copyLink: link:" << download_link;
qApp->clipboard()->setText(download_link);
if (!download_link.isEmpty()) {
qApp->clipboard()->setText(download_link);
status->setText(tr("Remaining downloads: %1").arg(remaining_downloads));
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/findsubtitles/osclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void OSClient::search(const QString & hash, qint64 file_size, QString search_ter
emit searchFinished();
}

QString OSClient::getDownloadLink(const QString & file_id) {
QString OSClient::getDownloadLink(const QString & file_id, int * remaining_downloads) {
qDebug() << "OSClient::getDownloadLink:" << file_id;

// Try to login
Expand Down Expand Up @@ -224,6 +224,10 @@ QString OSClient::getDownloadLink(const QString & file_id) {
QVariantMap map = result[0];
if (map.contains("link")) {
link = map["link"].toString();
qDebug() << "OSClient::getDownloadLink: remaining:" << map["remaining"].toInt();
if (remaining_downloads) {
*remaining_downloads = map["remaining"].toInt();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/findsubtitles/osclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class OSClient : public QObject {
void setPassword(QString password) { os_password = password; };
QString password() { return os_password; };

QString getDownloadLink(const QString & file_id);
QString getDownloadLink(const QString & file_id, int * remaining_downloads = 0);

public slots:
void search(const QString & hash, qint64 file_size, QString search_term = QString(), QString languages = QString());
Expand Down
1 change: 1 addition & 0 deletions src/findsubtitles/qrestapi/qRestAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void qRestAPIPrivate::processReply(QNetworkReply* reply)
QString::number(static_cast<int>(reply->error())) + ": " +
reply->errorString(),
errorCode);
qDebug() << "Error response:" << reply->readAll();
}
else
{
Expand Down

0 comments on commit bf160e1

Please sign in to comment.