Add (ai gen)
This commit is contained in:
@@ -19,7 +19,9 @@ public static function handle($shopee_task)
|
||||
|
||||
$main_image_url = null;
|
||||
|
||||
$proxy_server = get_smartproxy_server();
|
||||
$unblocker_proxy_server = get_smartproxy_unblocker_server();
|
||||
$rotating_proxy_server = get_smartproxy_rotating_server();
|
||||
|
||||
$user_agent = config('platform.proxy.user_agent');
|
||||
|
||||
///////// PART 1
|
||||
@@ -36,7 +38,7 @@ public static function handle($shopee_task)
|
||||
$intervention_images = $shopee_task->product_task->intervention->intervention_images;
|
||||
} else {
|
||||
$images = self::getImages($shopee_task->product_task->response->raw_html);
|
||||
$images = self::filterImages($images, $proxy_server, $user_agent, $costs, $intervention_images);
|
||||
$images = self::filterImages($images, $rotating_proxy_server, $user_agent, $costs, $intervention_images);
|
||||
}
|
||||
|
||||
///////// PART 2
|
||||
@@ -54,7 +56,7 @@ public static function handle($shopee_task)
|
||||
$scraped_image = ShopeeSellerScrapedImage::where('original_name', pathinfo($main_image_url, PATHINFO_BASENAME))->where('shopee_seller_scrape_id', $shopee_task->shopee_seller_scrape->id)->first();
|
||||
|
||||
if (is_null($scraped_image)) {
|
||||
$main_image = self::getProductImage($shopee_task->product_task->response->jsonld, $proxy_server, $user_agent, $costs, $main_intervention_image);
|
||||
$main_image = self::getProductImage($shopee_task->product_task->response->jsonld, $rotating_proxy_server, $user_agent, $costs, $main_intervention_image);
|
||||
|
||||
$scraped_image = self::uploadAndSaveScrapedImage($shopee_task->shopee_seller_scrape, $main_intervention_image, true);
|
||||
}
|
||||
@@ -137,16 +139,18 @@ private static function getImages(string $raw_html)
|
||||
$crawler->filter('img')->each(function ($node) use (&$images) {
|
||||
$src = $node->attr('src');
|
||||
$alt = $node->attr('alt') ?? null; // Setting a default value if alt is not present
|
||||
$images[] = [
|
||||
'src' => $src,
|
||||
'alt' => $alt,
|
||||
];
|
||||
});
|
||||
|
||||
// if (count($images) > 4)
|
||||
// {
|
||||
// return $images;
|
||||
// }
|
||||
$blacklist_domain = [];
|
||||
|
||||
foreach ($blacklist_domain as $blacklist) {
|
||||
if (! str_contains($src, $blacklist)) {
|
||||
$images[] = [
|
||||
'src' => $src,
|
||||
'alt' => $alt,
|
||||
];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $images;
|
||||
}
|
||||
@@ -164,7 +168,7 @@ private static function filterImages(array $images, string $proxy, string $user_
|
||||
$src = $image['src'];
|
||||
|
||||
try {
|
||||
$response = Http::withOptions(['proxy' => $proxy])->withHeaders(['User-Agent' => $user_agent])->get($src);
|
||||
$response = Http::withOptions(['proxy' => $proxy, 'verify' => false])->withHeaders(['User-Agent' => $user_agent])->get($src);
|
||||
|
||||
// Check if the request was successful
|
||||
if (! $response->successful()) {
|
||||
@@ -274,7 +278,7 @@ private static function getProductImage(array $jsonLdData, string $proxy, string
|
||||
if (isset($data->{'@type'}) && $data->{'@type'} === 'Product') {
|
||||
if (isset($data->url) && isset($data->image)) {
|
||||
try {
|
||||
$response = Http::withOptions(['proxy' => $proxy])->withHeaders(['User-Agent' => $user_agent])->get($data->image);
|
||||
$response = Http::withOptions(['proxy' => $proxy, 'verify' => false])->withHeaders(['User-Agent' => $user_agent])->get($data->image);
|
||||
|
||||
// Check if the request was successful
|
||||
if ($response->successful()) {
|
||||
|
||||
Reference in New Issue
Block a user