Имеется код который парсит актеров и информацию о них в базу.
Но возникла ситуация, когда необходимо обновить всю информацию каждого актера (который хранится в моей базе).
В ручную редактировать каждого - очень затратно. Подумал: а если при добавление актеров в фильм, те актеры, которые есть в моей базе, просто обратятся повторно по api и возьмут все необходимое?
пытался сам разобраться - потерпел неудачу.
хочу обратиться к людям, которые понимают в этом.
вот сам код, который парсит актеров:
if($_GET['actor'] == 'add') {
// Actors
$Credits = $Client->request(
'GET',
'https://api.themoviedb.org/3/'.$FilterType.'/' . $FilterId . '/credits?api_key=' . get($Settings,'data.tmdb_api','api') . '&language='.get($Settings,'data.tmdb_language','api')
);
$Credits = json_decode($Credits->getBody() , true);
foreach ($Credits['cast'] as $Credit) {
if($Credit['name'] AND $Credit['profile_path']) {
// Check Database
$CheckActor = $this->db->from('actors')
->where('self', Input::seo($Credit['name']))
->or_where('api_id', $Credit['id'])
->first();
if (!$CheckActor['id'] AND $Credit['name']) {
$ActorResponse = $Client->request(
'GET',
'https://api.themoviedb.org/3/person/' . $Credit['id'] . '?api_key=' . get($Settings,'data.tmdb_api','api') . '&language='.get($Settings,'data.tmdb_language','api')
);
$Actor = json_decode($ActorResponse->getBody() , true);
$SettingsData['data']['place_of_birth'] = $Actor['place_of_birth'];
$SettingsData['data']['birthday'] = $Actor['birthday'];
$SettingsData['data']['deathday'] = $Actor['deathday'];
$ActorSocial = $Client->request(
'GET',
'https://api.themoviedb.org/3/person/' . $Credit['id'] . '/external_ids?api_key=' . get($Settings,'data.tmdb_api','api') . '&language='.get($Settings,'data.tmdb_language','api')
);
$ActorSoc = json_decode($ActorSocial->getBody() , true);
$SettingsData['data']['social']['twitter'] = $ActorSoc['twitter_id'];
$SettingsData['data']['social']['facebook'] = $ActorSoc['facebook_id'];
$SettingsData['data']['social']['instagram'] = $ActorSoc['instagram_id'];
$Path = UPLOADPATH . '/tmp/' . Input::seo($Actor['name']) . '.jpg';
downloader('https://image.tmdb.org/t/p/original/'.$Actor['profile_path'], $Path);
$foo = new \Verot\Upload\Upload($Path);
if ($foo->uploaded) {
$foo->allowed = array('image/*');
$foo->file_auto_rename = true;
$foo->file_new_name_body = Input::seo($Actor['name']);
$foo->image_resize = true;
$foo->image_ratio_crop = true;
$foo->image_x = ACTOR_X;
$foo->image_y = ACTOR_Y;
$foo->image_convert = 'webp';
$foo->jpeg_quality = 100;
$foo->Process(UPLOADPATH . '/actor/');
if ($foo->processed) {
$Image = $foo->file_dst_name;
$thumb = new \Verot\Upload\Upload($Path);
$thumb->allowed = array('image/*');
$thumb->file_auto_rename = true;
$thumb->file_new_name_body = 'thumb-' . Input::seo($Actor['name']);
$thumb->image_resize = true;
$thumb->image_ratio_crop = true;
$thumb->image_x = THUMB_ACTOR_X;
$thumb->image_y = THUMB_ACTOR_Y;
$thumb->image_convert = 'webp';
$thumb->jpeg_quality = 100;
$thumb->Process(UPLOADPATH . '/actor/');
}
unlink($Path);
}
$Data = array(
'name' => Input::cleaner($Actor['name']),
'self' => Input::seo($Actor['name']),
'image' => $Image,
'biography' => Input::cleaner($Actor['biography']),
'gender' => Input::cleaner($Actor['gender']),
'data' => json_encode($SettingsData['data'], JSON_UNESCAPED_UNICODE),
'api_id' => Input::cleaner($Actor['id']),
'imdb_id' => Input::cleaner($Actor['imdb_id'])
);
$this->db->insert('actors')->set($Data);
$Actor_id = $this->db->lastId();
$Image = null;
$SettingsData = null;
$Path = null;
$_FILES['image'] = null;
} else {
$Actor_id = $CheckActor['id'];
}
$dataarray = array(
"actor_id" => $Actor_id,
"character_name" => Input::cleaner($Credit['character']),
"content_id" => $LastId,
"sortable" => Input::cleaner($Actor['sortable'])
);
$this->db->insert('posts_actor')->set($dataarray);
}
}
}