From 0566191821b68dfefbf560660742f10eae0e56f5 Mon Sep 17 00:00:00 2001 From: Ripose Date: Sun, 18 Feb 2024 22:05:58 -0700 Subject: [PATCH] src/audio/audioplayer: change to follow redirects JapanesePod101 recently changed their API so it redicts cross origin to a new website called innovativelanguage.com. This breaks Memento because Qt's default behavior doesn't follow redirects cross origin. This fixes the issue by following redirects regardless. It also changes the default JapanesePod101 URL to use HTTPS and not ignore SSL errors since that works now. --- src/audio/audioplayer.cpp | 13 +++++++++---- src/util/constants.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/audio/audioplayer.cpp b/src/audio/audioplayer.cpp index d4cc0d2..f8d81ab 100644 --- a/src/audio/audioplayer.cpp +++ b/src/audio/audioplayer.cpp @@ -125,11 +125,16 @@ AudioPlayerReply *AudioPlayer::playAudio(QString url, QString hash) /* File does not exist so fetch it */ AudioPlayerReply *audioReply = new AudioPlayerReply; - QNetworkReply *reply = m_manager->get(QNetworkRequest(QUrl(url))); + QNetworkRequest req{QUrl(url)}; + req.setAttribute( + QNetworkRequest::RedirectPolicyAttribute, + QNetworkRequest::UserVerifiedRedirectPolicy + ); + QNetworkReply *reply = m_manager->get(std::move(req)); connect( - reply, &QNetworkReply::sslErrors, - reply, qOverload<>(&QNetworkReply::ignoreSslErrors) - ); // God help me + reply, &QNetworkReply::redirected, + reply, &QNetworkReply::redirectAllowed + ); connect(reply, &QNetworkReply::finished, this, [=] { QTemporaryFile *file = nullptr; diff --git a/src/util/constants.h b/src/util/constants.h index 09723c8..1701d41 100644 --- a/src/util/constants.h +++ b/src/util/constants.h @@ -85,7 +85,7 @@ namespace Constants constexpr const char *NAME_DEFAULT = "JapanesePod101"; constexpr const char *URL = "url"; - constexpr const char *URL_DEFAULT = "http://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji={expression}&kana={reading}"; + constexpr const char *URL_DEFAULT = "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji={expression}&kana={reading}"; constexpr const char *TYPE = "type"; constexpr AudioSourceType TYPE_DEFAULT = AudioSourceType::File;