From ad0f081a3c5cf95defd05fd81722b14790a31eec Mon Sep 17 00:00:00 2001 From: zvon Date: Mon, 21 Jan 2019 20:30:14 +0100 Subject: [PATCH] Support utf-8 in show's name --- functions.cpp | 19 ++++++++++++++++++- functions.hpp | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/functions.cpp b/functions.cpp index ab45278..e4af999 100644 --- a/functions.cpp +++ b/functions.cpp @@ -1,6 +1,7 @@ #include "functions.hpp" #include "filesystem.hpp" #include +#include #include #include #include @@ -116,7 +117,7 @@ void iterateFS(std::map> &seasons, const std::string std::string getDefUrl( std::string show, const std::string &language, Curl &c ) { std::replace(show.begin(), show.end(), ' ', '+'); - auto source_code = c.execute("https://www.thetvdb.com/search?q=" + show + "&l=" + language); + auto source_code = c.execute("https://www.thetvdb.com/search?q=" + encodeUrl(show) + "&l=" + language); size_t order{}, pos{}; std::vector urls; while( true ) { @@ -194,3 +195,19 @@ bool findLanguage( const char *language ) { return false; } +std::string encodeUrl( const std::string &url ) { + //stolen from here - https://stackoverflow.com/questions/154536/encode-decode-urls-in-c + std::ostringstream encoded; + encoded.fill('0'); + encoded << std::hex; + for( auto &x : url ) { + if( std::isalnum(x) || x == '-' || x == '_' || x == '.' || x == '~' ) { + encoded << x; + continue; + } + encoded << std::uppercase << '%' << std::setw(2); + encoded << int(static_cast(x)) << std::nouppercase; + } + return encoded.str(); +} + diff --git a/functions.hpp b/functions.hpp index 01a75ab..63fae6f 100644 --- a/functions.hpp +++ b/functions.hpp @@ -21,4 +21,6 @@ void parseSeasonNumbers(std::set &seasons_num, const char *argument); void printLangs(); bool findLanguage( const char *language ); +std::string encodeUrl( const std::string &url ); + #endif