2019-01-07 22:24:28 +00:00
|
|
|
#include <algorithm>
|
2020-01-16 10:12:22 +00:00
|
|
|
#include <iostream>
|
2019-02-04 16:39:48 +00:00
|
|
|
#include <map>
|
|
|
|
|
2019-07-12 21:10:40 +00:00
|
|
|
#include "filesystem.hpp"
|
2020-01-15 21:20:44 +00:00
|
|
|
#include "functions.hpp"
|
|
|
|
#include "tv_rename.hpp"
|
|
|
|
|
|
|
|
#include "json.hpp"
|
|
|
|
using json = nlohmann::json;
|
2019-07-12 21:10:40 +00:00
|
|
|
|
2019-01-23 19:46:03 +00:00
|
|
|
#ifndef GUI
|
|
|
|
|
2018-09-22 22:50:42 +00:00
|
|
|
#include <sstream>
|
2019-01-07 22:24:28 +00:00
|
|
|
#include <vector>
|
2019-01-23 19:46:03 +00:00
|
|
|
|
|
|
|
#endif
|
2018-09-22 22:50:42 +00:00
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
2020-01-15 21:20:44 +00:00
|
|
|
#include <codecvt>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <locale>
|
|
|
|
#include <windows.h>
|
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
constexpr const char_t *dir_divider = L"\\";
|
|
|
|
|
|
|
|
#define cout std::wcout
|
|
|
|
#define cerr std::wcerr
|
|
|
|
#define cin std::wcin
|
|
|
|
|
2020-01-15 21:20:44 +00:00
|
|
|
#define toString( a ) utf8_to_wstring( a )
|
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
constexpr const char_t *dir_divider = "/";
|
|
|
|
|
|
|
|
#define cout std::cout
|
|
|
|
#define cerr std::cerr
|
|
|
|
#define cin std::cin
|
|
|
|
|
|
|
|
#define TEXT( a ) a
|
2020-01-15 21:20:44 +00:00
|
|
|
#define toString( a ) a
|
2019-02-04 16:39:48 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-01-15 22:59:39 +00:00
|
|
|
string api_token;
|
2020-01-15 21:20:44 +00:00
|
|
|
Request r;
|
2020-01-15 09:00:25 +00:00
|
|
|
|
|
|
|
std::vector< std::pair< string, string > >
|
|
|
|
searchShow( const string &show, const string &language ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
|
|
|
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
|
|
|
r.addHeader( TEXT( "Accept-Language: " ) + language );
|
2020-01-15 09:00:25 +00:00
|
|
|
|
|
|
|
auto encoded_show = encodeUrl( show );
|
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
auto j =
|
|
|
|
json::parse( r.get( TEXT( "/search/series?name=" ) + encoded_show ) );
|
2020-01-15 09:00:25 +00:00
|
|
|
|
|
|
|
std::vector< json > results;
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( j["data"].is_array() ) {
|
2020-01-15 09:00:25 +00:00
|
|
|
results = j["data"].get< std::vector< json > >();
|
|
|
|
} else {
|
2020-01-15 22:59:39 +00:00
|
|
|
cout << toString( j ) << std::endl;
|
2020-01-15 09:00:25 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::pair< string, string > > ret;
|
|
|
|
|
|
|
|
// find all possible shows
|
|
|
|
for ( auto &x : results ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
auto show = toString( x["seriesName"].get< std::string >() );
|
|
|
|
auto id = toString( std::to_string( x["id"].get< int >() ) );
|
|
|
|
ret.emplace_back( show, id );
|
2020-01-15 09:00:25 +00:00
|
|
|
}
|
2020-01-15 21:20:44 +00:00
|
|
|
r.clearHeader();
|
2020-01-15 09:00:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-16 10:12:22 +00:00
|
|
|
#ifndef GUI
|
2020-01-15 09:00:25 +00:00
|
|
|
// get show's ID
|
2020-01-18 21:19:17 +00:00
|
|
|
string getShowId( const string &show, const string &language ) {
|
2020-01-15 09:00:25 +00:00
|
|
|
size_t order{}, pos{};
|
|
|
|
auto search_results = searchShow( show, language );
|
2020-01-17 13:03:22 +00:00
|
|
|
for ( const auto &x : search_results ) {
|
2020-01-15 09:00:25 +00:00
|
|
|
cout << ++order << ". " << x.first << std::endl;
|
|
|
|
}
|
2020-01-15 22:59:39 +00:00
|
|
|
cout << "Which TV Show is the right one? " << std::flush;
|
2020-01-15 09:00:25 +00:00
|
|
|
cin >> pos;
|
|
|
|
cin.clear();
|
|
|
|
cin.ignore( 1, '\n' );
|
2020-01-17 13:03:22 +00:00
|
|
|
return search_results[pos - 1].second;
|
2020-01-15 09:00:25 +00:00
|
|
|
}
|
2020-01-16 10:12:22 +00:00
|
|
|
#endif
|
2020-01-15 09:00:25 +00:00
|
|
|
|
|
|
|
string showNameFromId( const string &id, const string &language ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
|
|
|
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
|
|
|
r.addHeader( TEXT( "Accept-Language: " ) + language );
|
2020-01-15 09:00:25 +00:00
|
|
|
|
2020-01-15 21:20:44 +00:00
|
|
|
auto j = json::parse( r.get( TEXT( "/series/" ) + id ) );
|
2020-01-15 09:00:25 +00:00
|
|
|
|
2020-01-15 21:20:44 +00:00
|
|
|
// TODO check if got json
|
2020-01-17 13:03:22 +00:00
|
|
|
std::string show =
|
|
|
|
j["data"].get< json >()["seriesName"].get< std::string >();
|
2020-01-15 21:20:44 +00:00
|
|
|
return toString( show );
|
2020-01-15 09:00:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
// get names for all episodes for a given season
|
2020-01-15 09:00:25 +00:00
|
|
|
std::vector< string > getEpisodeNames( const string &id, const string &season,
|
2020-01-17 13:03:22 +00:00
|
|
|
const string &language,
|
|
|
|
bool dvd = false ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
|
|
|
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
|
|
|
r.addHeader( TEXT( "Accept-Language: " ) + language );
|
|
|
|
string page = TEXT( "1" );
|
|
|
|
string season_query = TEXT( "airedSeason=" );
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( dvd )
|
2020-01-15 21:20:44 +00:00
|
|
|
season_query = TEXT( "dvdSeason=" );
|
2019-02-04 16:39:48 +00:00
|
|
|
std::vector< string > episodes;
|
2020-01-15 09:00:25 +00:00
|
|
|
do {
|
|
|
|
episodes.resize( episodes.size() * 2 );
|
2020-01-15 21:20:44 +00:00
|
|
|
auto j = json::parse( r.get( TEXT( "/series/" ) + id +
|
2020-01-17 13:03:22 +00:00
|
|
|
TEXT( "/episodes/query?" ) + season_query +
|
|
|
|
season + TEXT( "&page=" ) + page ) );
|
|
|
|
if ( j["data"].is_array() ) {
|
2020-01-15 09:00:25 +00:00
|
|
|
auto epdata = j["data"].get< std::vector< json > >();
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( episodes.size() < epdata.size() )
|
2020-01-15 09:00:25 +00:00
|
|
|
episodes.resize( epdata.size() );
|
|
|
|
for ( auto &x : epdata ) {
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( x["episodeName"].is_string() ) {
|
|
|
|
if ( dvd ) {
|
2020-01-15 09:00:25 +00:00
|
|
|
size_t index = x["dvdEpisodeNumber"].get< size_t >();
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( index > episodes.size() )
|
2020-01-15 09:00:25 +00:00
|
|
|
episodes.resize( index );
|
|
|
|
index--;
|
2020-01-17 13:03:22 +00:00
|
|
|
episodes[index] =
|
|
|
|
toString( x["episodeName"].get< std::string >() );
|
2020-01-15 09:00:25 +00:00
|
|
|
} else {
|
|
|
|
size_t index = x["airedEpisodeNumber"].get< size_t >();
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( index > episodes.size() )
|
2020-01-15 09:00:25 +00:00
|
|
|
episodes.resize( index );
|
|
|
|
index--;
|
2020-01-17 13:03:22 +00:00
|
|
|
episodes[index] =
|
|
|
|
toString( x["episodeName"].get< std::string >() );
|
2020-01-15 21:34:01 +00:00
|
|
|
// some eps have whitespace at the end
|
2020-01-17 13:03:22 +00:00
|
|
|
while ( isspace( episodes[index].back() ) )
|
2020-01-15 21:34:01 +00:00
|
|
|
episodes[index].pop_back();
|
2020-01-15 09:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-07 22:24:28 +00:00
|
|
|
} else {
|
2020-01-17 13:03:22 +00:00
|
|
|
cerr << "Couldn't find episode names for season " << season
|
|
|
|
<< " of show " << showNameFromId( id, language ) << std::endl;
|
2019-01-07 22:24:28 +00:00
|
|
|
}
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( j["links"]["next"].is_null() )
|
2020-01-15 09:00:25 +00:00
|
|
|
break;
|
2020-01-15 21:20:44 +00:00
|
|
|
page = toString( std::to_string( j["links"]["next"].get< size_t >() ) );
|
2020-01-17 13:03:22 +00:00
|
|
|
} while ( 1 );
|
2020-01-15 21:20:44 +00:00
|
|
|
r.clearHeader();
|
2019-01-17 16:08:51 +00:00
|
|
|
return episodes;
|
2019-01-07 22:24:28 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
std::vector<
|
|
|
|
std::pair< std::pair< int, string >, std::pair< string, string > > >
|
2020-01-15 09:00:25 +00:00
|
|
|
getRenamedFiles( const string &show, int season, const string id,
|
2019-02-04 16:39:48 +00:00
|
|
|
const string &language, const string &pattern,
|
2020-01-17 13:03:22 +00:00
|
|
|
const bool &linux, const std::map< int, string > &files,
|
|
|
|
bool dvd ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
auto season_num = toString( std::to_string( season ) );
|
2020-01-15 09:00:25 +00:00
|
|
|
auto episodes = getEpisodeNames( id, season_num, language, dvd );
|
2019-01-07 22:24:28 +00:00
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
if ( episodes.empty() )
|
2019-01-29 16:50:19 +00:00
|
|
|
return {};
|
2019-01-23 21:57:52 +00:00
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
if ( files.empty() )
|
2019-01-29 16:50:19 +00:00
|
|
|
return {};
|
2019-01-23 19:46:03 +00:00
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
std::vector<
|
|
|
|
std::pair< std::pair< int, string >, std::pair< string, string > > >
|
2019-02-04 16:39:48 +00:00
|
|
|
renamed_files;
|
|
|
|
|
|
|
|
for ( const auto &x : files ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
auto last = x.second.find_last_of( dir_divider );
|
2019-02-04 16:39:48 +00:00
|
|
|
string og_name;
|
|
|
|
string dir;
|
|
|
|
if ( last == string::npos ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
og_name = x.second;
|
2019-02-04 16:39:48 +00:00
|
|
|
dir = TEXT( "." );
|
2019-01-04 19:18:18 +00:00
|
|
|
} else {
|
2020-01-15 21:20:44 +00:00
|
|
|
og_name = x.second.substr( last + 1 );
|
|
|
|
dir = x.second.substr( 0, last );
|
2019-01-04 19:18:18 +00:00
|
|
|
}
|
2020-01-15 21:20:44 +00:00
|
|
|
unsigned long ep_num = x.first - 1;
|
2019-02-04 16:39:48 +00:00
|
|
|
|
2020-01-15 21:20:44 +00:00
|
|
|
if ( ep_num < episodes.size() ) {
|
2019-02-04 16:39:48 +00:00
|
|
|
auto pos = og_name.find_last_of( TEXT( "." ) );
|
2019-01-23 13:08:40 +00:00
|
|
|
// get desired filename
|
2020-01-15 21:20:44 +00:00
|
|
|
auto name = compilePattern( pattern, season, x.first,
|
2020-01-17 13:03:22 +00:00
|
|
|
og_name.substr( 0, pos ),
|
|
|
|
episodes[ep_num], show ) +
|
2019-02-04 16:39:48 +00:00
|
|
|
og_name.substr( pos );
|
2019-02-02 21:27:18 +00:00
|
|
|
// replace '/' with '|'
|
2019-02-04 16:39:48 +00:00
|
|
|
for ( size_t i = 0; i < name.size(); i++ ) {
|
|
|
|
if ( name[i] == '/' ) {
|
2019-02-02 21:27:18 +00:00
|
|
|
name[i] = '|';
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 13:08:40 +00:00
|
|
|
// replace characters illegal in windows if desired
|
2019-02-04 16:39:48 +00:00
|
|
|
if ( !linux ) {
|
|
|
|
name.erase( std::remove_if( name.begin(), name.end(),
|
|
|
|
[]( char_t x ) {
|
|
|
|
return x == '?' || x == '"' ||
|
|
|
|
x == '\\' || x == '*';
|
|
|
|
} ),
|
|
|
|
name.end() );
|
|
|
|
size_t max{ name.size() };
|
|
|
|
for ( size_t i = 0; i < max; i++ ) {
|
|
|
|
if ( name[i] == '|' ) {
|
2019-02-02 21:27:18 +00:00
|
|
|
name[i] = '-';
|
2019-02-04 16:39:48 +00:00
|
|
|
} else if ( name[i] == '<' ) {
|
2019-01-07 22:24:28 +00:00
|
|
|
name[i] = 'i';
|
2019-02-04 16:39:48 +00:00
|
|
|
name.insert( i + 1, TEXT( "s less than" ) );
|
2019-01-07 22:24:28 +00:00
|
|
|
max += 11;
|
|
|
|
} else if ( name[i] == '>' ) {
|
|
|
|
name[i] = 'i';
|
2019-02-04 16:39:48 +00:00
|
|
|
name.insert( i + 1, TEXT( "s more than" ) );
|
2019-01-07 22:24:28 +00:00
|
|
|
max += 11;
|
|
|
|
} else if ( name[i] == ':' ) {
|
|
|
|
name[i] = ' ';
|
2019-02-04 16:39:48 +00:00
|
|
|
name.insert( i + 1, 1, '-' );
|
2019-01-07 22:24:28 +00:00
|
|
|
max++;
|
|
|
|
}
|
|
|
|
}
|
2019-02-04 16:39:48 +00:00
|
|
|
for ( size_t i = 0; i < max; i++ ) {
|
|
|
|
if ( name[i] == ' ' && name[i + 1] == ' ' ) {
|
|
|
|
name.erase( i, 1 );
|
2019-02-02 21:27:18 +00:00
|
|
|
max--;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 19:18:18 +00:00
|
|
|
}
|
2019-02-04 16:39:48 +00:00
|
|
|
renamed_files.emplace_back(
|
2020-01-17 13:03:22 +00:00
|
|
|
std::pair< int, string >( x.first, dir ),
|
|
|
|
std::pair< string, string >( og_name, name ) );
|
2019-01-04 19:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-23 21:57:52 +00:00
|
|
|
return renamed_files;
|
2019-01-29 16:50:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 10:12:22 +00:00
|
|
|
std::vector< std::pair< string, string > > getLangs() {
|
|
|
|
std::vector< std::pair< string, string > > langs;
|
|
|
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
|
|
|
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
|
|
|
auto j = json::parse( r.get( TEXT( "/languages" ) ) );
|
|
|
|
r.clearHeader();
|
|
|
|
auto langs_json = j["data"].get< std::vector< json > >();
|
|
|
|
for ( auto &x : langs_json ) {
|
|
|
|
langs.emplace_back( toString( x["abbreviation"].get< std::string >() ),
|
|
|
|
toString( x["name"].get< std::string >() ) );
|
|
|
|
}
|
|
|
|
return langs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool authenticate( const std::string &api_key ) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
r.setServer( TEXT( "api.thetvdb.com" ) );
|
|
|
|
#else
|
|
|
|
r.setServer( "https://api.thetvdb.com" );
|
|
|
|
#endif
|
|
|
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
|
|
|
r.addHeader( TEXT( "Content-Type: application/json" ) );
|
2020-01-17 13:03:22 +00:00
|
|
|
auto j = json::parse(
|
|
|
|
r.post( TEXT( "/login" ), "{ \"apikey\": \"" + api_key + "\" }" ) );
|
2020-01-16 10:12:22 +00:00
|
|
|
api_token = toString( j["token"].get< std::string >() );
|
|
|
|
r.clearHeader();
|
|
|
|
// TODO check return code
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:54:26 +00:00
|
|
|
void singleSeason( const string &path, const string &show, int season, string id,
|
2019-02-04 16:39:48 +00:00
|
|
|
const string &language, const string &pattern,
|
2020-01-15 09:00:25 +00:00
|
|
|
const bool &linux, const bool &trust,
|
2020-01-15 21:20:44 +00:00
|
|
|
std::map< int, string > *files_ptr, bool print, bool dvd ) {
|
2020-01-16 10:12:22 +00:00
|
|
|
#ifndef GUI
|
2020-01-15 09:00:25 +00:00
|
|
|
if ( id.empty() )
|
|
|
|
id = getShowId( show, language );
|
2020-01-16 10:12:22 +00:00
|
|
|
#endif
|
2019-01-29 16:50:19 +00:00
|
|
|
|
2020-01-15 21:20:44 +00:00
|
|
|
std::map< int, std::map< int, string > > *found_files = nullptr;
|
2019-01-29 16:50:19 +00:00
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
if ( files_ptr == nullptr ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
found_files = new std::map< int, std::map< int, string > >;
|
|
|
|
iterateFS( *found_files, path );
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( found_files->find( season ) != found_files->end() )
|
|
|
|
files_ptr = &( *found_files )[season];
|
2020-01-15 21:20:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( files_ptr == nullptr ) {
|
2020-01-15 21:20:44 +00:00
|
|
|
cerr << "Couldn't find episodes with season " << season << std::endl;
|
|
|
|
return;
|
2019-01-29 16:50:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 09:00:25 +00:00
|
|
|
auto renamed_files = getRenamedFiles( show, season, id, language, pattern,
|
|
|
|
linux, *files_ptr, dvd );
|
2019-01-29 16:50:19 +00:00
|
|
|
|
2020-01-17 19:28:44 +00:00
|
|
|
if( renamed_files.empty() )
|
|
|
|
goto end;
|
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
if ( print || !trust ) {
|
|
|
|
for ( auto renamed = renamed_files.begin();
|
|
|
|
renamed != renamed_files.end(); ++renamed ) {
|
2019-06-04 19:54:00 +00:00
|
|
|
cout << renamed->second.first << " --> " << renamed->second.second
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2019-01-07 22:24:28 +00:00
|
|
|
|
2019-06-04 19:54:00 +00:00
|
|
|
if ( !trust ) {
|
|
|
|
cout << "Does this seem ok? (y/n) ";
|
|
|
|
string response;
|
|
|
|
cin >> response;
|
|
|
|
cin.clear();
|
|
|
|
cin.ignore( 1, '\n' );
|
|
|
|
if ( response[0] != 'y' && response[0] != 'Y' )
|
|
|
|
return;
|
|
|
|
}
|
2019-01-04 19:18:18 +00:00
|
|
|
}
|
2019-01-07 22:24:28 +00:00
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
for ( auto renamed = renamed_files.begin(); renamed != renamed_files.end();
|
|
|
|
++renamed ) {
|
2020-01-17 13:03:22 +00:00
|
|
|
FSLib::rename(
|
|
|
|
renamed->first.second + dir_divider + renamed->second.first,
|
|
|
|
renamed->first.second + dir_divider + renamed->second.second );
|
|
|
|
if ( found_files == nullptr ) {
|
|
|
|
files_ptr[0][renamed->first.first] =
|
|
|
|
renamed->first.second + dir_divider + renamed->second.second;
|
2020-01-15 21:20:44 +00:00
|
|
|
}
|
2019-01-04 19:18:18 +00:00
|
|
|
}
|
2019-01-29 16:50:19 +00:00
|
|
|
|
2020-01-17 19:28:44 +00:00
|
|
|
end:
|
2019-02-04 16:39:48 +00:00
|
|
|
if ( found_files != nullptr ) {
|
2019-01-29 16:50:19 +00:00
|
|
|
delete found_files;
|
|
|
|
}
|
2018-09-22 22:50:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 19:54:26 +00:00
|
|
|
void singleSeason( const string &path, const string &show, int season, string id,
|
2020-01-15 21:20:44 +00:00
|
|
|
const string &language, const string &pattern,
|
|
|
|
const size_t &flags, std::map< int, string > *files_ptr,
|
|
|
|
bool print ) {
|
|
|
|
singleSeason( path, show, season, id, language, pattern, flags & TV_LINUX,
|
|
|
|
flags & TV_TRUST, files_ptr, print, flags & TV_DVD );
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:10:40 +00:00
|
|
|
#ifndef GUI
|
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
void multipleSeasons( const string &path, string &show,
|
2020-01-15 21:20:44 +00:00
|
|
|
const std::set< int > seasons, const string &language,
|
|
|
|
const string &pattern, const size_t &flags ) {
|
|
|
|
std::map< int, std::map< int, string > > season_map;
|
|
|
|
iterateFS( season_map, path );
|
2020-01-15 09:00:25 +00:00
|
|
|
auto id = getShowId( show, language );
|
2020-01-17 13:03:22 +00:00
|
|
|
for ( auto &x : season_map ) {
|
|
|
|
if ( seasons.find( x.first ) != seasons.end() ) {
|
|
|
|
singleSeason( path, show, x.first, id, language, pattern,
|
|
|
|
flags & TV_LINUX, flags & TV_TRUST, &x.second,
|
|
|
|
flags & TV_DVD );
|
2020-01-15 21:20:44 +00:00
|
|
|
}
|
2019-01-17 16:08:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 16:39:48 +00:00
|
|
|
void allSeasons( const string &path, string &show, const string &language,
|
2020-01-15 21:20:44 +00:00
|
|
|
const string &pattern, const size_t &flags ) {
|
|
|
|
std::map< int, std::map< int, string > > seasons;
|
2019-02-04 16:39:48 +00:00
|
|
|
// get all season number from this directory and subdirectories
|
|
|
|
iterateFS( seasons, path );
|
2020-01-15 21:20:44 +00:00
|
|
|
auto id = getShowId( show, language );
|
2020-01-17 13:03:22 +00:00
|
|
|
for ( auto &x : seasons ) {
|
|
|
|
singleSeason( path, show, x.first, id, language, pattern,
|
|
|
|
flags & TV_LINUX, flags & TV_TRUST, &x.second,
|
|
|
|
flags & TV_DVD );
|
2020-01-15 21:20:44 +00:00
|
|
|
}
|
2020-01-15 09:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void printLangs() {
|
|
|
|
for ( auto &x : getLangs() )
|
|
|
|
cout << x.first << " - " << x.second << std::endl;
|
|
|
|
}
|
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
#endif
|
|
|
|
|
2020-01-15 09:00:25 +00:00
|
|
|
bool findLanguage( const char_t *language ) {
|
|
|
|
for ( auto &x : getLangs() ) {
|
|
|
|
if ( x.first == language )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-17 13:03:22 +00:00
|
|
|
bool validID( const string &id ) {
|
|
|
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
|
|
|
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
|
|
|
|
|
|
|
r.get( TEXT( "/series/" ) + id );
|
|
|
|
|
|
|
|
return r.lastResponseCode() == 200;
|
|
|
|
}
|