From 3d4c3553427f7524a762d43d671e76d4c2bdd452 Mon Sep 17 00:00:00 2001 From: zvon Date: Sat, 26 Jan 2019 00:50:26 +0100 Subject: [PATCH] Use thetvdb name of show in '%show' --- functions.cpp | 15 ++++++++------- functions.hpp | 2 +- tv_rename.cpp | 8 ++++---- tv_rename.hpp | 6 +++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/functions.cpp b/functions.cpp index 2ac5120..8797349 100644 --- a/functions.cpp +++ b/functions.cpp @@ -148,20 +148,20 @@ void findSeasons(std::map> &seasons, const std::strin } } -std::string getDefUrl( std::string show, const std::string &language, Curl &c ) { +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=" + encodeUrl(show) + "&l=" + language); size_t order{}, pos{}; - std::vector urls; + std::vector> urls; while( true ) { pos = source_code.find("/ser", pos); if( pos != std::string::npos ) { auto end = source_code.find(">", pos); end--; - urls.push_back(source_code.substr(pos, end - pos)); - pos = end + 2; - end = source_code.find("<", pos); - std::cout << ++order << ". " << source_code.substr(pos, end - pos) << std::endl; + auto end2 = source_code.find("<", end + 2); + urls.emplace_back(source_code.substr(end + 2, end2 - end - 2), source_code.substr(pos, end - pos)); + std::cout << ++order << ". " << urls.back().first << std::endl; + pos = end2; } else { break; } @@ -170,7 +170,8 @@ std::string getDefUrl( std::string show, const std::string &language, Curl &c ) std::cin >> pos; std::cin.clear(); std::cin.ignore(1, '\n'); - return "https://www.thetvdb.com" + urls[pos-1]; + show = urls[pos-1].first; + return "https://www.thetvdb.com" + urls[pos-1].second; } void printHelp() { diff --git a/functions.hpp b/functions.hpp index 8df1f5f..a635c3b 100644 --- a/functions.hpp +++ b/functions.hpp @@ -14,7 +14,7 @@ #ifndef GUI -std::string getDefUrl( std::string show, const std::string &language, Curl &c ); +std::string getDefUrl( std::string &show, const std::string &language, Curl &c ); void findSeason(std::set &files, int season, const std::string &path); void findSeasons(std::map> &seasons, const std::string &path, const std::set &season_numbers); void printHelp(); diff --git a/tv_rename.cpp b/tv_rename.cpp index 4542464..99941b2 100644 --- a/tv_rename.cpp +++ b/tv_rename.cpp @@ -49,7 +49,7 @@ void defaultSingleSeasonReturn() { #ifdef GUI std::vector>> singleSeason( const std::string &show, int season, std::string url, const std::string &language, const std::string &pattern, const bool &linux, Curl &c, const std::set &files) { #else -void singleSeason( const std::string &path, const std::string &show, int season, std::string url, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c, std::set const *files_ptr) { +void singleSeason( const std::string &path, std::string &show, int season, std::string url, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c, std::set const *files_ptr) { #endif #ifndef GUI @@ -169,20 +169,20 @@ void singleSeason( const std::string &path, const std::string &show, int season, } #ifndef GUI -void multipleSeasons( const std::string &path, const std::string &show, const std::map> &seasons, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c) { +void multipleSeasons( const std::string &path, std::string &show, const std::map> &seasons, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c) { auto url = getDefUrl(show, language, c); for( const auto &x : seasons ) { singleSeason( path, show, x.first, url, language, pattern, linux, trust, c, &x.second); } } -void multipleSeasons( const std::string &path, const std::string &show, const std::set seasons, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c) { +void multipleSeasons( const std::string &path, std::string &show, const std::set seasons, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c) { std::map> season_map; findSeasons(season_map, path, seasons); multipleSeasons(path, show, season_map, language, pattern, linux, trust, c); } -void allSeasons( const std::string &path, const std::string &show, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c) { +void allSeasons( const std::string &path, std::string &show, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c) { std::map> seasons; //get all season number from this directory and subdirectories iterateFS(seasons, path); diff --git a/tv_rename.hpp b/tv_rename.hpp index ff791d1..914eea9 100644 --- a/tv_rename.hpp +++ b/tv_rename.hpp @@ -12,9 +12,9 @@ std::vector>> singleS #else -void singleSeason( const std::string &path, const std::string &show, int season, std::string url, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c, std::set const *files=nullptr); -void multipleSeasons( const std::string &path, const std::string &show, const std::set seasons, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c); -void allSeasons( const std::string &path, const std::string &show, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c); +void singleSeason( const std::string &path, std::string &show, int season, std::string url, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c, std::set const *files=nullptr); +void multipleSeasons( const std::string &path, std::string &show, const std::set seasons, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c); +void allSeasons( const std::string &path, std::string &show, const std::string &language, const std::string &pattern, const bool &linux, const bool &trust, Curl &c); #endif