Support utf-8 in show's name

This commit is contained in:
zvon 2019-01-21 20:30:14 +01:00
parent 81bf7e3588
commit ad0f081a3c
2 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include "functions.hpp"
#include "filesystem.hpp"
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <curl/curl.h>
#include <stdlib.h>
@ -116,7 +117,7 @@ void iterateFS(std::map<int, std::set<std::string>> &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<std::string> 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<unsigned char>(x)) << std::nouppercase;
}
return encoded.str();
}

View File

@ -21,4 +21,6 @@ void parseSeasonNumbers(std::set<int> &seasons_num, const char *argument);
void printLangs();
bool findLanguage( const char *language );
std::string encodeUrl( const std::string &url );
#endif