Fix windows problems
This commit is contained in:
parent
01cf6d289a
commit
758af6ff6b
@ -372,7 +372,7 @@ string compilePattern( const string &pattern, int season, int episode,
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
std::wstring getDBName() {
|
std::wstring getDBName() {
|
||||||
return userHome() + L"\\tv_rename\\database.db";
|
return userHome() + L"\\tv_rename\\database.db";
|
||||||
@ -400,7 +400,7 @@ string sanitize( const string &str ) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareDB( const std::string &_pattern ) {
|
void prepareDB( const string &_pattern ) {
|
||||||
SQLite::Database db{};
|
SQLite::Database db{};
|
||||||
try {
|
try {
|
||||||
db.open( getDBName(), SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE );
|
db.open( getDBName(), SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE );
|
||||||
@ -462,9 +462,13 @@ void addToDB( string &show, const string &path, const string &language,
|
|||||||
TEXT( "INSERT OR IGNORE INTO SHOWS ( TVID, SHOW, PATH, LANGUAGE, DVD ) "
|
TEXT( "INSERT OR IGNORE INTO SHOWS ( TVID, SHOW, PATH, LANGUAGE, DVD ) "
|
||||||
"VALUES ( '" ) +
|
"VALUES ( '" ) +
|
||||||
sanitize( id ) + TEXT( "', '" ) + sanitize( show ) + TEXT( "', '" ) +
|
sanitize( id ) + TEXT( "', '" ) + sanitize( show ) + TEXT( "', '" ) +
|
||||||
sanitize( absolute ) + TEXT( "', '" ) + sanitize( language ) + "', " +
|
sanitize( absolute ) + TEXT( "', '" ) + sanitize( language ) + TEXT( "', " ) +
|
||||||
( dvd ? TEXT( "1" ) : TEXT( "0" ) ) + TEXT( " );" ) );
|
( dvd ? TEXT( "1" ) : TEXT( "0" ) ) + TEXT( " );" ) );
|
||||||
|
#ifdef _WIN32
|
||||||
|
string show_id = std::to_wstring( db.lastRowID() );
|
||||||
|
#else
|
||||||
string show_id = std::to_string( db.lastRowID() );
|
string show_id = std::to_string( db.lastRowID() );
|
||||||
|
#endif
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
string pattern{};
|
string pattern{};
|
||||||
db.exec( TEXT( "SELECT PATH FROM SHOWS WHERE TVID == 'pattern';" ),
|
db.exec( TEXT( "SELECT PATH FROM SHOWS WHERE TVID == 'pattern';" ),
|
||||||
@ -477,7 +481,7 @@ void addToDB( string &show, const string &path, const string &language,
|
|||||||
auto size = seasons.size();
|
auto size = seasons.size();
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
cout << "Renaming" << std::endl;
|
cout << "Renaming" << std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
@ -498,7 +502,7 @@ void addToDB( string &show, const string &path, const string &language,
|
|||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
cout << "Adding to database" << std::endl;
|
cout << "Adding to database" << std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
@ -521,7 +525,7 @@ void addToDB( string &show, const string &path, const string &language,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
void cleanUpLine() {
|
void cleanUpLine() {
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
int width;
|
int width;
|
||||||
@ -573,14 +577,14 @@ void refreshDB( bool linux ) {
|
|||||||
pattern );
|
pattern );
|
||||||
|
|
||||||
cout << "Refreshing database" << std::endl << std::endl << std::endl;
|
cout << "Refreshing database" << std::endl << std::endl << std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for ( auto &show : shows ) {
|
for ( auto &show : shows ) {
|
||||||
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
|
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
|
||||||
cleanUpLine();
|
cleanUpLine();
|
||||||
cout << "Refreshing " << show[TEXT( "SHOW" )] << std::endl;
|
cout << "Refreshing " << show[TEXT( "SHOW" )] << std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
@ -639,7 +643,7 @@ void updateDB( bool linux ) {
|
|||||||
pattern );
|
pattern );
|
||||||
|
|
||||||
cout << "Updating database" << std::endl << std::endl << std::endl;
|
cout << "Updating database" << std::endl << std::endl << std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for ( auto &show : shows ) {
|
for ( auto &show : shows ) {
|
||||||
@ -648,7 +652,7 @@ void updateDB( bool linux ) {
|
|||||||
}
|
}
|
||||||
cleanUpLine();
|
cleanUpLine();
|
||||||
cout << "Updating " << show[TEXT( "SHOW" )] << std::endl;
|
cout << "Updating " << show[TEXT( "SHOW" )] << std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
std::unordered_set< string > episodes;
|
std::unordered_set< string > episodes;
|
||||||
@ -768,7 +772,7 @@ void removeFromDB( const string &path ) {
|
|||||||
db.exec( TEXT( "DELETE FROM SHOWS WHERE ID == " ) + show_id + TEXT( ";" ) );
|
db.exec( TEXT( "DELETE FROM SHOWS WHERE ID == " ) + show_id + TEXT( ";" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< std::unordered_map< std::string, std::string > > dbGetShows() {
|
std::vector< std::unordered_map< string, string > > dbGetShows() {
|
||||||
SQLite::Database db{};
|
SQLite::Database db{};
|
||||||
try {
|
try {
|
||||||
db.open( getDBName(), SQLite::OPEN_READWRITE );
|
db.open( getDBName(), SQLite::OPEN_READWRITE );
|
||||||
@ -776,7 +780,7 @@ std::vector< std::unordered_map< std::string, std::string > > dbGetShows() {
|
|||||||
cerr << "Can't open database, make sure it exists" << std::endl;
|
cerr << "Can't open database, make sure it exists" << std::endl;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
std::vector< std::unordered_map< std::string, std::string > > ret;
|
std::vector< std::unordered_map< string, string > > ret;
|
||||||
db.exec( TEXT( "SELECT * FROM SHOWS;" ), ret );
|
db.exec( TEXT( "SELECT * FROM SHOWS;" ), ret );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -791,7 +795,7 @@ void changeDB( size_t index, const string &path, const string &language,
|
|||||||
cerr << "Can't open database, make sure it exists" << std::endl;
|
cerr << "Can't open database, make sure it exists" << std::endl;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
#ifndef WIN32
|
#ifndef _WIN32
|
||||||
string show_id = std::to_string( index );
|
string show_id = std::to_string( index );
|
||||||
#else
|
#else
|
||||||
string show_id = std::to_wstring( index );
|
string show_id = std::to_wstring( index );
|
||||||
@ -801,13 +805,17 @@ void changeDB( size_t index, const string &path, const string &language,
|
|||||||
TEXT( "', SHOW = '" ) + sanitize( real_show ) +
|
TEXT( "', SHOW = '" ) + sanitize( real_show ) +
|
||||||
TEXT( "', PATH = '" ) + sanitize( absolute ) +
|
TEXT( "', PATH = '" ) + sanitize( absolute ) +
|
||||||
TEXT( "', LANGUAGE = '" ) + sanitize( language ) +
|
TEXT( "', LANGUAGE = '" ) + sanitize( language ) +
|
||||||
TEXT( "', DVD = " + ( dvd ? TEXT( "1" ) : TEXT( "0" ) ) +
|
TEXT( "', DVD = " ) + ( dvd ? TEXT( "1" ) : TEXT( "0" ) ) +
|
||||||
" WHERE ID == " + show_id + ";" ) );
|
TEXT( " WHERE ID == " ) + show_id + TEXT( ";" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshSingleDB( const size_t &index, bool linux ) {
|
void refreshSingleDB( const size_t &index, bool linux ) {
|
||||||
std::vector< std::unordered_map< string, string > > shows;
|
std::vector< std::unordered_map< string, string > > shows;
|
||||||
|
#ifdef _WIN32
|
||||||
|
string show_id = std::to_wstring( index );
|
||||||
|
#else
|
||||||
string show_id = std::to_string( index );
|
string show_id = std::to_string( index );
|
||||||
|
#endif
|
||||||
SQLite::Database db{};
|
SQLite::Database db{};
|
||||||
try {
|
try {
|
||||||
db.open( getDBName(), SQLite::OPEN_READWRITE );
|
db.open( getDBName(), SQLite::OPEN_READWRITE );
|
||||||
@ -815,10 +823,10 @@ void refreshSingleDB( const size_t &index, bool linux ) {
|
|||||||
cerr << "Can't open database, make sure it exists" << std::endl;
|
cerr << "Can't open database, make sure it exists" << std::endl;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
db.exec( "DELETE FROM EPISODES WHERE SHOWID == " + show_id + ";" );
|
db.exec( TEXT( "DELETE FROM EPISODES WHERE SHOWID == " ) + show_id + TEXT( ";" ) );
|
||||||
db.exec(
|
db.exec(
|
||||||
TEXT( "SELECT TVID, SHOW, PATH, LANGUAGE, DVD FROM SHOWS WHERE ID == " +
|
TEXT( "SELECT TVID, SHOW, PATH, LANGUAGE, DVD FROM SHOWS WHERE ID == " ) +
|
||||||
show_id + ";" ),
|
show_id + TEXT( ";" ),
|
||||||
shows );
|
shows );
|
||||||
|
|
||||||
std::unordered_map< string, string > &show = shows[0];
|
std::unordered_map< string, string > &show = shows[0];
|
||||||
@ -830,11 +838,11 @@ void refreshSingleDB( const size_t &index, bool linux ) {
|
|||||||
cout << "Refreshing " << show[TEXT( "SHOW" )] << std::endl
|
cout << "Refreshing " << show[TEXT( "SHOW" )] << std::endl
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
|
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
|
@ -45,7 +45,7 @@ getPossibleShows( string show, const string &language );
|
|||||||
|
|
||||||
string userHome();
|
string userHome();
|
||||||
|
|
||||||
void prepareDB( const std::string &_pattern = "" );
|
void prepareDB( const string &_pattern = TEXT( "" ) );
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
void addToDB( string &show, const string &path, const string &language,
|
void addToDB( string &show, const string &path, const string &language,
|
||||||
bool linux, bool dvd );
|
bool linux, bool dvd );
|
||||||
|
@ -46,7 +46,7 @@ constexpr const char_t *dir_divider = "/";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
std::string api_token = "";
|
string api_token;
|
||||||
Request r;
|
Request r;
|
||||||
|
|
||||||
std::vector< std::pair< string, string > >
|
std::vector< std::pair< string, string > >
|
||||||
@ -64,7 +64,7 @@ searchShow( const string &show, const string &language ) {
|
|||||||
if( j["data"].is_array() ) {
|
if( j["data"].is_array() ) {
|
||||||
results = j["data"].get< std::vector< json > >();
|
results = j["data"].get< std::vector< json > >();
|
||||||
} else {
|
} else {
|
||||||
cout << j << std::endl;
|
cout << toString( j ) << std::endl;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ string getShowId( string &show, const string &language ) {
|
|||||||
for( const auto &x : search_results ) {
|
for( const auto &x : search_results ) {
|
||||||
cout << ++order << ". " << x.first << std::endl;
|
cout << ++order << ". " << x.first << std::endl;
|
||||||
}
|
}
|
||||||
cout << "Which TV Show is the right one? ";
|
cout << "Which TV Show is the right one? " << std::flush;
|
||||||
cin >> pos;
|
cin >> pos;
|
||||||
cin.clear();
|
cin.clear();
|
||||||
cin.ignore( 1, '\n' );
|
cin.ignore( 1, '\n' );
|
||||||
@ -133,13 +133,13 @@ std::vector< string > getEpisodeNames( const string &id, const string &season,
|
|||||||
if( index > episodes.size() )
|
if( index > episodes.size() )
|
||||||
episodes.resize( index );
|
episodes.resize( index );
|
||||||
index--;
|
index--;
|
||||||
episodes[index] = toString( x["episodeName"].get< string >() );
|
episodes[index] = toString( x["episodeName"].get< std::string >() );
|
||||||
} else {
|
} else {
|
||||||
size_t index = x["airedEpisodeNumber"].get< size_t >();
|
size_t index = x["airedEpisodeNumber"].get< size_t >();
|
||||||
if( index > episodes.size() )
|
if( index > episodes.size() )
|
||||||
episodes.resize( index );
|
episodes.resize( index );
|
||||||
index--;
|
index--;
|
||||||
episodes[index] = toString( x["episodeName"].get<string>() );
|
episodes[index] = toString( x["episodeName"].get< std::string >() );
|
||||||
// some eps have whitespace at the end
|
// some eps have whitespace at the end
|
||||||
while( isspace( episodes[index].back() ) )
|
while( isspace( episodes[index].back() ) )
|
||||||
episodes[index].pop_back();
|
episodes[index].pop_back();
|
||||||
@ -332,8 +332,8 @@ void allSeasons( const string &path, string &show, const string &language,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< std::pair< std::string, std::string > > getLangs() {
|
std::vector< std::pair< string, string > > getLangs() {
|
||||||
std::vector< std::pair< std::string, std::string > > langs;
|
std::vector< std::pair< string, string > > langs;
|
||||||
r.addHeader( TEXT( "Accept: application/json" ) );
|
r.addHeader( TEXT( "Accept: application/json" ) );
|
||||||
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
r.addHeader( TEXT( "Authorization: Bearer " ) + api_token );
|
||||||
auto j = json::parse( r.get( TEXT( "/languages" ) ) );
|
auto j = json::parse( r.get( TEXT( "/languages" ) ) );
|
||||||
@ -361,7 +361,7 @@ bool findLanguage( const char_t *language ) {
|
|||||||
|
|
||||||
bool authenticate( const std::string &api_key ) {
|
bool authenticate( const std::string &api_key ) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
r.setServer( "api.thetvdb.com" );
|
r.setServer( TEXT( "api.thetvdb.com" ) );
|
||||||
#else
|
#else
|
||||||
r.setServer( "https://api.thetvdb.com" );
|
r.setServer( "https://api.thetvdb.com" );
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,7 +29,7 @@ std::string sendRequest( HINTERNET hRequest, const std::wstring &headers,
|
|||||||
memcpy( opt.get(), optional.c_str(), optional.length() );
|
memcpy( opt.get(), optional.c_str(), optional.length() );
|
||||||
|
|
||||||
auto requestSent = HttpSendRequest(
|
auto requestSent = HttpSendRequest(
|
||||||
hRequest, headers.c_str(), headers.length(), opt, optional.length() );
|
hRequest, headers.c_str(), headers.length(), opt.get(), optional.length() );
|
||||||
|
|
||||||
if ( !requestSent )
|
if ( !requestSent )
|
||||||
std::wcerr << "ERROR HttpSendRequest: " << GetLastError() << std::endl;
|
std::wcerr << "ERROR HttpSendRequest: " << GetLastError() << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user