TheMovieDB: formatting
This commit is contained in:
parent
b88d4c0e65
commit
1565aabf70
@ -1,5 +1,6 @@
|
||||
// API - 2ebc8e784a4072da457fae5c0d291e48
|
||||
// API READ ONLY - eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIyZWJjOGU3ODRhNDA3MmRhNDU3ZmFlNWMwZDI5MWU0OCIsInN1YiI6IjYwZTJlNGI5MjJlNDgwMDA2MDJmZDMzMyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.c0y7bTCI5KSsfQRw7igPx1FR40mbMF6hGTJTHn0HXH8
|
||||
// API READ ONLY -
|
||||
// eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIyZWJjOGU3ODRhNDA3MmRhNDU3ZmFlNWMwZDI5MWU0OCIsInN1YiI6IjYwZTJlNGI5MjJlNDgwMDA2MDJmZDMzMyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.c0y7bTCI5KSsfQRw7igPx1FR40mbMF6hGTJTHn0HXH8
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
@ -64,11 +65,16 @@ bool init(const string &config_path) {
|
||||
#else
|
||||
request.setServer( "https://api.themoviedb.org/3" );
|
||||
#endif
|
||||
_moviedb_api_token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIyZWJjOGU3ODRhNDA3MmRhNDU3ZmFlNWMwZDI5MWU0OCIsInN1YiI6IjYwZTJlNGI5MjJlNDgwMDA2MDJmZDMzMyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.c0y7bTCI5KSsfQRw7igPx1FR40mbMF6hGTJTHn0HXH8";
|
||||
_moviedb_api_token =
|
||||
"eyJhbGciOiJIUzI1NiJ9."
|
||||
"eyJhdWQiOiIyZWJjOGU3ODRhNDA3MmRhNDU3ZmFlNWMwZDI5MWU0OCIsInN1YiI6IjYwZT"
|
||||
"JlNGI5MjJlNDgwMDA2MDJmZDMzMyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9u"
|
||||
"IjoxfQ.c0y7bTCI5KSsfQRw7igPx1FR40mbMF6hGTJTHn0HXH8";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hasKey(const rapidjson::GenericValue<rapidjson::UTF8<>> &object, const std::string &key) {
|
||||
bool hasKey( const rapidjson::GenericValue< rapidjson::UTF8<> > &object,
|
||||
const std::string &key ) {
|
||||
return object.FindMember( key.c_str() ) != object.MemberEnd();
|
||||
}
|
||||
|
||||
@ -87,12 +93,13 @@ searchMovie( const string &movie, const string &language, const string &year ) {
|
||||
do {
|
||||
cur_page++;
|
||||
rapidjson::Document json;
|
||||
auto request_uri = TEXT( "/search/movie?query=" ) + encoded_show + TEXT("&language=" ) + language + TEXT("&page=") + toString(std::to_string(cur_page));
|
||||
auto request_uri = TEXT( "/search/movie?query=" ) + encoded_show +
|
||||
TEXT( "&language=" ) + language + TEXT( "&page=" ) +
|
||||
toString( std::to_string( cur_page ) );
|
||||
if ( !year.empty() ) {
|
||||
request_uri += TEXT( "&year=" ) + year;
|
||||
}
|
||||
json.Parse(
|
||||
request.get( request_uri ).c_str() );
|
||||
json.Parse( request.get( request_uri ).c_str() );
|
||||
if ( json.HasParseError() )
|
||||
return {};
|
||||
|
||||
@ -105,14 +112,17 @@ searchMovie( const string &movie, const string &language, const string &year ) {
|
||||
|
||||
// find all possible movies
|
||||
for ( size_t i = 0; i < results.Size(); i++ ) {
|
||||
if(!hasKey(results[i], "title") || !hasKey(results[i], "id") ||
|
||||
!hasKey(results[i], "release_date") || !hasKey(results[i], "original_title")) {
|
||||
if ( !hasKey( results[i], "title" ) ||
|
||||
!hasKey( results[i], "id" ) ||
|
||||
!hasKey( results[i], "release_date" ) ||
|
||||
!hasKey( results[i], "original_title" ) ) {
|
||||
continue;
|
||||
}
|
||||
auto movie = toString( results[i]["title"].GetString() );
|
||||
auto id = toString( std::to_string( results[i]["id"].GetInt() ) );
|
||||
string year = toString( results[i]["release_date"].GetString() );
|
||||
string original = toString( results[i]["original_title"].GetString() );
|
||||
string original =
|
||||
toString( results[i]["original_title"].GetString() );
|
||||
if ( year.empty() ) {
|
||||
year = "0000";
|
||||
} else {
|
||||
@ -173,8 +183,8 @@ std::string removeIllegalCharacters(const std::string &input) {
|
||||
// replace characters illegal in windows
|
||||
ret.erase( std::remove_if( ret.begin(), ret.end(),
|
||||
[]( char_t x ) {
|
||||
return x == '?' || x == '"' ||
|
||||
x == '\\' || x == '*';
|
||||
return x == '?' || x == '"' || x == '\\' ||
|
||||
x == '*';
|
||||
} ),
|
||||
ret.end() );
|
||||
for ( size_t i = 0; i < ret.size(); i++ ) {
|
||||
@ -211,11 +221,14 @@ MovieNames movieFromId( const string &id, const string &language ) {
|
||||
if ( json.HasParseError() ) {
|
||||
return { "", "" };
|
||||
}
|
||||
return {removeIllegalCharacters( json["title"].GetString() ), removeIllegalCharacters( json["original_title"].GetString() )};
|
||||
return { removeIllegalCharacters( json["title"].GetString() ),
|
||||
removeIllegalCharacters( json["original_title"].GetString() ) };
|
||||
}
|
||||
|
||||
bool renameMovie( const string &path, const string &name, const string &year ) {
|
||||
return FSLib::rename(path, FSLib::canonical( FSLib::getContainingDirectory(path) ) + "/" + name + " (" + year + ")." + FSLib::getFileExtension(path) );
|
||||
return FSLib::rename(
|
||||
path, FSLib::canonical( FSLib::getContainingDirectory( path ) ) + "/" +
|
||||
name + " (" + year + ")." + FSLib::getFileExtension( path ) );
|
||||
}
|
||||
|
||||
bool renamePath( const string &path, const RenameObject &renamer ) {
|
||||
@ -248,17 +261,20 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
|
||||
if ( results.empty() )
|
||||
return false;
|
||||
id = results[0].id;
|
||||
movie = { removeIllegalCharacters( results[0].name ), removeIllegalCharacters( results[0].original_name ) };
|
||||
movie = { removeIllegalCharacters( results[0].name ),
|
||||
removeIllegalCharacters( results[0].original_name ) };
|
||||
year = results[0].year;
|
||||
} else {
|
||||
id = renamer.getCustomFields().at( "id" );
|
||||
movie = movieFromId( id, lang );
|
||||
}
|
||||
|
||||
if((!use_original && movie.name == "") || (use_original && movie.original_name == ""))
|
||||
if ( ( !use_original && movie.name == "" ) ||
|
||||
( use_original && movie.original_name == "" ) )
|
||||
return false;
|
||||
|
||||
return renameMovie( path, use_original ? movie.original_name : movie.name, year );
|
||||
return renameMovie( path, use_original ? movie.original_name : movie.name,
|
||||
year );
|
||||
}
|
||||
|
||||
std::vector< string > getCustomKeys() {
|
||||
|
Loading…
Reference in New Issue
Block a user