From f2270fed4dfbbe3051b7cb228f70a6cfe22dce16 Mon Sep 17 00:00:00 2001 From: Ricardo <10128951+smplayer-dev@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:04:07 +0100 Subject: [PATCH] Pass the season and episode numbers to the search on OpenSubtitles. --- src/findsubtitles/osclient.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/findsubtitles/osclient.cpp b/src/findsubtitles/osclient.cpp index d056914ea..735c91f1c 100644 --- a/src/findsubtitles/osclient.cpp +++ b/src/findsubtitles/osclient.cpp @@ -21,6 +21,8 @@ #include "qrestapi/qGirderAPI.h" #include "qrestapi/qRestResult.h" + +#include #include #define API_SERVER "https://api.opensubtitles.com/api/v1" @@ -93,6 +95,17 @@ void OSClient::search(const QString & hash, qint64 file_size, QString search_ter search_term = search_term.replace(" ", "+").toLower(); + if (!search_term.isEmpty()) { + QRegExp regex("(?:S(\\d{1,2})E(\\d{1,2})|(\\d{1,2})x(\\d{1,2}))", Qt::CaseInsensitive); + int pos = regex.indexIn(search_term); + if (pos > -1) { + QString season = regex.cap(1).isEmpty() ? regex.cap(3) : regex.cap(1); + QString episode = regex.cap(2).isEmpty() ? regex.cap(4) : regex.cap(2); + par["season_number"] = season; + par["episode_number"] = episode; + } + } + switch (search_method) { case Filename: par["query"] = search_term; @@ -102,7 +115,9 @@ void OSClient::search(const QString & hash, qint64 file_size, QString search_ter break; case HashAndFilename: par["query"] = search_term; - par["moviehash"] = hash; + if (!hash.isEmpty()) { + par["moviehash"] = hash; + } break; default: return; @@ -111,7 +126,7 @@ void OSClient::search(const QString & hash, qint64 file_size, QString search_ter #if 1 QString par_str; foreach(const QString &key, par.keys()) { - par_str += key + ": " + par.value(key) + ", "; + par_str += key + ": '" + par.value(key) + "', "; } qDebug() << "OSClient::search: parameters:" << par_str; #endif