

import json
import requests
import re
import random
from datetime import datetime
import threading
import time
import os
os.environ['NO_PROXY'] = 'stackoverflow.com'
import logging
logging.captureWarnings(True)
from all_connect import ConnectSpider
Con = ConnectSpider()
from lxml import etree
import requests
from image_id_pairs_9038595 import image_id_id_pairs
# from curl_cffi import requests
import os
os.environ['NO_PROXY'] = 'stackoverflow.com'
from cookies import cookie_list_9038595
cookie_list = cookie_list_9038595
import curl_cffi


class Stock_Detail():
    def __init__(self):
        self.headers = {
            'accept': 'application/json',
            'accept-language': 'zh-CN,zh;q=0.9',
            # 'cookie': 'stck_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; sstk_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; _gcl_au=1.1.874517867.1723276566; __ssid=c064478ee3926370e6737c3582c60d0; _ga=GA1.1.675721154.1723276566; did=02a1c297-357e-400b-87f5-41457a394697; accts_customer=903859535; accts_customer_sso1=331378495-undefined; next.sid=s%3Agy3BgikznI1m6vIui-5gGcFYcjWzDFIK.OXZW%2FtHJ8HVG%2Fx9eXhfAilGM0zicWdtakg1aacGy8OM; _4c_=%7B%22_4c_mc_%22%3A%222a68f713-f2b5-49b7-8e45-07549f8a66d8%22%7D; FPID=FPID2.2.eJMnQEWeDZwuxnkWmESNukKGwRAIKHd9t3eewKvzeQQ%3D.1723276566; visitor_id=73458769441; htjs_user_id=331378495; htjs_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; __rtbh.uid=%7B%22eventType%22%3A%22uid%22%2C%22id%22%3A%227c4b5046-d8eb-4ee5-8bac-893a170fa766%22%7D; slireg=https://scout.us1.salesloft.com; extole_access_token=BV1L1U32MH7O4IOEUHOH6F88AJ; sliguid=2259d959-8b66-4544-8a26-ee6f9e0d872c; slirequested=true; n_v=2d4faa42e64; locale=zh; NEXT_LOCALE=zh; hl=zh; sstk_session_start=2024-08-12T00%3A50%3A01.185Z; stck_session_id=eb218863-1d7b-453e-b68f-826b54a4f567; sstk_session_id=eb218863-1d7b-453e-b68f-826b54a4f567; downlink=slow; visit_id=81252382944; gtm_monit_roll=99; OptanonConsent=consentId=5cff2293-6adc-4e35-960b-a301a65fc215&datestamp=Mon+Aug+12+2024+08%3A50%3A04+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=202403.2.0&interactionCount=0&isAnonUser=1&isGpcEnabled=0&browserGpcFlag=0&isIABGlobal=false&hosts=&landingPath=NotLandingPage&groups=C0001%3A1%2CC0003%3A1%2CC0002%3A1%2CC0005%3A1%2CC0004%3A1%2CC0007%3A1&AwaitingReconsent=false; OptanonCachedGroups=,C0001,C0003,C0002,C0005,C0004,C0007,; FPLC=xYngCOYQalQCTnXJSrL5MkPtTggGURkuZLMfzokC8ITFBHfwhBl4NrpZuNrp44Zw2eHfL22tL9Q1ejmZot6AEMzltj2Hvtapbeu8iPj20h1y4yHKQZLIWATPUg4j1A%3D%3D; datadome=1Q5Il~6ANKiyum9UFnRoJyruo7C1U0TXOsxV_tOU4rYdEk5a6dO3mjUEFLs5FgsAbSj2xGvoSUp3jYNLxrjs~XHUOwCU9L~8nimhKtYEznVW_AeNZ23e2zxJLf2GHikU; Authorization=1%2FeyJjbGllbnRfaWQiOiJhMGI3Ni1hN2Y1ZS1mZWRlYy1iYmViZS1mYTY1Yi04NTcxOSIsInJlYWxtIjoiY3VzdG9tZXIiLCJzY29wZSI6InVzZXIudmlldyB1c2VyLmVtYWlsIHVzZXIuYWRkcmVzcyB1c2VyLmVkaXQgb3JnYW5pemF0aW9uLnZpZXcgb3JnYW5pemF0aW9uLmFkZHJlc3MgY29sbGVjdGlvbnMudmlldyBjb2xsZWN0aW9ucy5lZGl0IGxpY2Vuc2VzLnZpZXcgbGljZW5zZXMuY3JlYXRlIG1lZGlhLnVwbG9hZCBtZWRpYS5zdWJtaXQgbWVkaWEuZWRpdCBwdXJjaGFzZXMudmlldyBwdXJjaGFzZXMuY3JlYXRlIiwidXR2IjoicUhpNCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ1c2VybmFtZSI6IjkwMzg1OTUzNSIsInVzZXJfaWQiOjMzMTM3ODQ5NSwib3JnYW5pemF0aW9uX2lkIjpudWxsLCJwYXJlbnRfb3JnYW5pemF0aW9uX2lkcyI6W10sImN1c3RvbWVyX2lkIjozMzEzNzg0OTUsImV4cCI6MTcyMzQyNzMyMX0.QcAGSAHi_1fLXJQReHBAtupw2qzn6DXiX1nsLVOoxg6OEe277kv3zt85EsJHen0_DmoHdMS35s4Fh418lXWR-w; _uetsid=d11e0420584411efb988e71c7217a51d|17zp06m|2|fo9|0|1685; _uetvid=58dc29704a6511ef8f5e5754465f397d|1dj9d84|1723425007889|3|1|bat.bing.com/p/insights/c/i; _ga_H22ZZQTXLV=GS1.1.1723423806.2.1.1723425008.0.0.0; _ga_SSGTMSSTK=GS1.1.1723423806.2.1.1723425008.0.0.1890544395; _ga_5JRYE4Y8J9=GS1.1.1723423806.2.1.1723425008.59.0.0',
            'if-modified-since': 'Sat, 10 Aug 2024 08:09:24 GMT',
            'if-none-match': 'W/"17t8cdyfo1s1un"',
            'newrelic': 'eyJ2IjpbMCwxXSwiZCI6eyJ0eSI6IkJyb3dzZXIiLCJhYyI6Ijk2NzIzMiIsImFwIjoiMTU4ODYzMjc5MiIsImlkIjoiMTU5ZDAyYjQ0YTdjN2VlZiIsInRyIjoiNTEzYjdiODMwNGFkODE4N2Y5YzMwMzg0OTc4YWYwOWUiLCJ0aSI6MTcyMzQyNTAxNzYyOH19',
            'priority': 'u=1, i',
            'referer': 'https://www.shutterstock.com/zh/catalog/licenses',
            'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'traceparent': '00-513b7b8304ad8187f9c30384978af09e-159d02b44a7c7eef-01',
            'tracestate': '967232@nr=0-1-967232-1588632792-159d02b44a7c7eef----1723425017628',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
            'x-end-app-name': 'next-web',
            'x-end-app-version': '2d4faa42e64',
            'x-newrelic-id': 'XQAAU1VRGwIEVVhaBgYGUlI=',
            'x-request-id': 'db700cde-0361-46f8-8ff3-d7234616ab34',
        }

    def random_ua(self):
        first_num = random.randint(55, 62)
        third_num = random.randint(0, 3200)
        fourth_num = random.randint(0, 140)
        os_type = [
            '(Windows NT 6.1; WOW64)',
            '(Windows NT 10.0; WOW64)',
            '(X11; Linux x86_64)',
            '(Macintosh; Intel Mac OS X 10_12_6)'
        ]
        chrome_version = 'Chrome/{}.0.{}.{}'.format(first_num, third_num, fourth_num)
        ua = ' '.join(['Mozilla/5.0', random.choice(os_type), 'AppleWebKit/537.36',
                       '(KHTML, like Gecko)', chrome_version, 'Safari/537.36']
                      )
        self.headers['user-agent'] = ua
    def get_pic(self,account_id,image_id, item_id,cookie,retry=0):
        start_time = datetime.now().strftime("%m-%d %H:%M:%S")
        try:
            self.random_ua()
            item = {}
            headers = {
                'accept': 'application/json',
                'accept-language': 'zh-CN,zh;q=0.9',
                # 'cookie': 'stck_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; sstk_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; _gcl_au=1.1.874517867.1723276566; __ssid=c064478ee3926370e6737c3582c60d0; _ga=GA1.1.675721154.1723276566; did=02a1c297-357e-400b-87f5-41457a394697; accts_customer=903859535; accts_customer_sso1=331378495-undefined; next.sid=s%3Agy3BgikznI1m6vIui-5gGcFYcjWzDFIK.OXZW%2FtHJ8HVG%2Fx9eXhfAilGM0zicWdtakg1aacGy8OM; _4c_=%7B%22_4c_mc_%22%3A%222a68f713-f2b5-49b7-8e45-07549f8a66d8%22%7D; FPID=FPID2.2.eJMnQEWeDZwuxnkWmESNukKGwRAIKHd9t3eewKvzeQQ%3D.1723276566; visitor_id=73458769441; htjs_user_id=331378495; htjs_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; __rtbh.uid=%7B%22eventType%22%3A%22uid%22%2C%22id%22%3A%227c4b5046-d8eb-4ee5-8bac-893a170fa766%22%7D; slireg=https://scout.us1.salesloft.com; extole_access_token=BV1L1U32MH7O4IOEUHOH6F88AJ; sliguid=2259d959-8b66-4544-8a26-ee6f9e0d872c; slirequested=true; n_v=2d4faa42e64; locale=zh; NEXT_LOCALE=zh; hl=zh; sstk_session_start=2024-08-12T00%3A50%3A01.185Z; stck_session_id=eb218863-1d7b-453e-b68f-826b54a4f567; sstk_session_id=eb218863-1d7b-453e-b68f-826b54a4f567; downlink=slow; visit_id=81252382944; gtm_monit_roll=99; OptanonConsent=consentId=5cff2293-6adc-4e35-960b-a301a65fc215&datestamp=Mon+Aug+12+2024+08%3A50%3A04+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=202403.2.0&interactionCount=0&isAnonUser=1&isGpcEnabled=0&browserGpcFlag=0&isIABGlobal=false&hosts=&landingPath=NotLandingPage&groups=C0001%3A1%2CC0003%3A1%2CC0002%3A1%2CC0005%3A1%2CC0004%3A1%2CC0007%3A1&AwaitingReconsent=false; OptanonCachedGroups=,C0001,C0003,C0002,C0005,C0004,C0007,; FPLC=xYngCOYQalQCTnXJSrL5MkPtTggGURkuZLMfzokC8ITFBHfwhBl4NrpZuNrp44Zw2eHfL22tL9Q1ejmZot6AEMzltj2Hvtapbeu8iPj20h1y4yHKQZLIWATPUg4j1A%3D%3D; datadome=1Q5Il~6ANKiyum9UFnRoJyruo7C1U0TXOsxV_tOU4rYdEk5a6dO3mjUEFLs5FgsAbSj2xGvoSUp3jYNLxrjs~XHUOwCU9L~8nimhKtYEznVW_AeNZ23e2zxJLf2GHikU; Authorization=1%2FeyJjbGllbnRfaWQiOiJhMGI3Ni1hN2Y1ZS1mZWRlYy1iYmViZS1mYTY1Yi04NTcxOSIsInJlYWxtIjoiY3VzdG9tZXIiLCJzY29wZSI6InVzZXIudmlldyB1c2VyLmVtYWlsIHVzZXIuYWRkcmVzcyB1c2VyLmVkaXQgb3JnYW5pemF0aW9uLnZpZXcgb3JnYW5pemF0aW9uLmFkZHJlc3MgY29sbGVjdGlvbnMudmlldyBjb2xsZWN0aW9ucy5lZGl0IGxpY2Vuc2VzLnZpZXcgbGljZW5zZXMuY3JlYXRlIG1lZGlhLnVwbG9hZCBtZWRpYS5zdWJtaXQgbWVkaWEuZWRpdCBwdXJjaGFzZXMudmlldyBwdXJjaGFzZXMuY3JlYXRlIiwidXR2IjoicUhpNCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ1c2VybmFtZSI6IjkwMzg1OTUzNSIsInVzZXJfaWQiOjMzMTM3ODQ5NSwib3JnYW5pemF0aW9uX2lkIjpudWxsLCJwYXJlbnRfb3JnYW5pemF0aW9uX2lkcyI6W10sImN1c3RvbWVyX2lkIjozMzEzNzg0OTUsImV4cCI6MTcyMzQyNzMyMX0.QcAGSAHi_1fLXJQReHBAtupw2qzn6DXiX1nsLVOoxg6OEe277kv3zt85EsJHen0_DmoHdMS35s4Fh418lXWR-w; _uetsid=d11e0420584411efb988e71c7217a51d|17zp06m|2|fo9|0|1685; _uetvid=58dc29704a6511ef8f5e5754465f397d|1dj9d84|1723425007889|3|1|bat.bing.com/p/insights/c/i; _ga_H22ZZQTXLV=GS1.1.1723423806.2.1.1723425008.0.0.0; _ga_SSGTMSSTK=GS1.1.1723423806.2.1.1723425008.0.0.1890544395; _ga_5JRYE4Y8J9=GS1.1.1723423806.2.1.1723425008.59.0.0',
                'if-modified-since': 'Sat, 10 Aug 2024 08:09:24 GMT',
                'if-none-match': 'W/"17t8cdyfo1s1un"',
                'newrelic': 'eyJ2IjpbMCwxXSwiZCI6eyJ0eSI6IkJyb3dzZXIiLCJhYyI6Ijk2NzIzMiIsImFwIjoiMTU4ODYzMjc5MiIsImlkIjoiMTU5ZDAyYjQ0YTdjN2VlZiIsInRyIjoiNTEzYjdiODMwNGFkODE4N2Y5YzMwMzg0OTc4YWYwOWUiLCJ0aSI6MTcyMzQyNTAxNzYyOH19',
                'priority': 'u=1, i',
                'referer': 'https://www.shutterstock.com/zh/catalog/licenses',
                'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
                'sec-ch-ua-mobile': '?0',
                'sec-ch-ua-platform': '"Windows"',
                'sec-fetch-dest': 'empty',
                'sec-fetch-mode': 'cors',
                'sec-fetch-site': 'same-origin',
                'traceparent': '00-513b7b8304ad8187f9c30384978af09e-159d02b44a7c7eef-01',
                'tracestate': '967232@nr=0-1-967232-1588632792-159d02b44a7c7eef----1723425017628',
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
                'x-end-app-name': 'next-web',
                'x-end-app-version': '2d4faa42e64',
                'x-newrelic-id': 'XQAAU1VRGwIEVVhaBgYGUlI=',
                'x-request-id': 'db700cde-0361-46f8-8ff3-d7234616ab34',
            }
            params = {
                'fields[images]': 'alt,aspect,channels,content_tier,contributor_id,description,displays,height,image_type,is_editorial,creativeInsights,link,model_release_info,sizes,src,title,width,has_model_release,has_property_release,status',
                'fields[licenses]': 'content_id,content_size,content_type,global_accounts_user_id,insert_time,license_name,media-item,metadata',
                'include': 'media-item.categories',
                'filter[media_type]': 'photo',
                'filter[licensee_type]': 'all',
                'page[number]': '1',
                'page[size]': '50',
                'filter[media_id]': f'{image_id}',
                'sort': 'newest',
                'v': '2d4faa42e64',
            }
            response = requests.get('https://www.shutterstock.com/napi/user/licenses', params=params, cookies=cookie, headers=headers,timeout=600)
            if response.status_code == 200:
                try:
                    data = json.loads(response.text)
                    image_title = data['included'][0]['attributes']['alt']
                    image_size_info = {}
                    try:
                        hugeJpg = data['included'][0]['attributes']['sizes']['hugeJpg']
                        image_size_info['hugeJpg'] = hugeJpg
                    except:
                        hugeJpg = None

                    try:
                        mediumJpg = data['included'][0]['attributes']['sizes']['mediumJpg']
                        image_size_info['mediumJpg'] = mediumJpg
                    except:
                        mediumJpg = None

                    try:
                        smallJpg = data['included'][0]['attributes']['sizes']['smallJpg']
                        image_size_info['smallJpg'] = smallJpg
                    except:
                        smallJpg = None

                    image_size_info = json.dumps(image_size_info)
                except:
                    image_size_info = None
                    image_title = None
                if image_title:
                    # 获取图片url
                    try:
                        save_folder= 'D:\公司备用文件\\all_images\\9038595@qq'
                        pic_name = f'{str(image_id)}+{image_title}'.replace(':', '_').replace('\t', '').replace('\r', '').replace('|','').replace( '/', '').replace('"', "'").replace(' ', '_').replace(',', '_').replace('.', '_').replace('\n', '_')
                        pic_name = re.sub(r'[\\/*?:"<>|]', '_', pic_name)[:160] + '.jpg'
                        json_data = {
                            'required_cookies': '',
                            'content': [
                                {
                                    'content_id': f'{image_id}',
                                    'content_type': 'photo',
                                    'content_size': 'huge',
                                    'content_format': 'jpg',
                                    'license_name': 'standard',
                                    'show_modal': True,
                                },
                            ],
                        }
                        response = requests.post('https://www.shutterstock.com/napi/licensees/current/redownload',cookies=cookie, headers=self.headers,json=json_data,timeout =600)
                        image_url = json.loads(response.text)['meta']['licensedContent'][0]['downloadUrl']
                        image_type = 'jpg'
                        res = requests.get(image_url,timeout=600)

                        # 构建完整的文件路径
                        file_path = os.path.join(save_folder, pic_name)
                        with open(file_path, "wb") as f:
                            f.write(res.content)
                        item['account_id'] = account_id
                        item['image_id'] = image_id
                        item['image_size_info'] = image_size_info
                        item['image_title'] = image_title
                        item['image_type'] = image_type
                        item['image_url'] = image_url
                        item['created_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                        # print(item)
                        Con.save_stock_detail(item)
                        Con.update_image_id_to_3(item_id)
                        now_time = datetime.now().strftime("%m-%d %H:%M:%S")
                        print(f'pic_name:{pic_name[:38]},time:{start_time}——{now_time}下载成功')
                    except Exception as e:
                        print('不是jpg',e)
                        try:
                            # 如果 jpg 格式失败，则尝试 png 格式
                            pic_name = f'{str(image_id)}+{image_title}'.replace(':', '_').replace('\t', '').replace('\r', '').replace('|', '').replace('/', '').replace('"', "'").replace(' ', '_').replace(',', '_').replace('.', '_').replace('\n', '_')
                            pic_name = re.sub(r'[\\/*?:"<>|]', '_', pic_name)[:160] + '.png'
                            json_data = {
                                'required_cookies': '',
                                'content': [
                                    {
                                        'content_id': f'{image_id}',
                                        'content_type': 'photo',
                                        'content_size': 'large',
                                        'content_format': 'png',
                                        'include_shadows': True,
                                        'angle': 'G03',
                                        'license_name': 'standard',
                                        'show_modal': True,
                                    },
                                ],
                            }
                            response = requests.post('https://www.shutterstock.com/napi/licensees/current/redownload',cookies=cookie,headers=self.headers,json=json_data,timeout=600)
                            image_url = json.loads(response.text)['meta']['licensedContent'][0]['downloadUrl']
                            image_type = 'png'
                            res = requests.get(image_url,timeout=600)

                            # 构建完整的文件路径
                            file_path = os.path.join(save_folder, pic_name)
                            with open(file_path, "wb") as f:
                                f.write(res.content)
                            item['account_id'] = account_id
                            item['image_id'] = image_id
                            item['image_size_info'] = image_size_info
                            item['image_title'] = image_title
                            item['image_type'] = image_type
                            item['image_url'] = image_url
                            item['created_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                            Con.save_stock_detail(item)
                            Con.update_image_id_to_3(item_id)
                            now_time = datetime.now().strftime("%m-%d %H:%M:%S")
                            print(f'pic_name:{pic_name},time:{start_time}——{now_time}下载成功')
                        except Exception as e:
                            print('不是png', e)
                else:
                    Con.update_image_id_to_4(item_id)

            elif response.status_code == 403 and retry < 3:
                # 根据重试次数设置不同的休眠时间
                if retry == 0:
                    sleep_time = random.randint(3, 6)
                elif retry == 1:
                    sleep_time = random.randint(63, 66)
                elif retry == 2:
                    sleep_time = random.randint(360, 366)
                time.sleep(sleep_time)
                cookie = cookie_list[random.randint(0, len(cookie_list) - 1)]
                return self.get_pic(account_id, image_id, item_id, cookie, retry + 1)
            else:
                print(image_id, '状态码=', response.status_code)
        except curl_cffi.requests.errors.RequestsError as e:
            if retry < 3:
                print(f"网络错误 {e}, 尝试重新连接...")
                # 根据重试次数设置不同的休眠时间
                if retry == 0:
                    sleep_time = random.randint(3, 6)
                elif retry == 1:
                    sleep_time = random.randint(63, 66)
                elif retry == 2:
                    sleep_time = random.randint(360, 366)

                time.sleep(sleep_time)
                cookie = cookie_list[random.randint(0, len(cookie_list) - 1)]
                return self.get_pic(account_id, image_id, item_id, cookie, retry + 1)
            else:
                print('重试次数用完')
                raise


    def run(self):
        account_id = '9038595@qq.com'
        counts_start = 4061
        counts_last = 5956
        cookie = cookie_list_9038595[random.randint(0, len(cookie_list_9038595) - 1)]
        cookie = {
            'stck_anonymous_id': '7c4b5046-d8eb-4ee5-8bac-893a170fa766',
            'sstk_anonymous_id': '7c4b5046-d8eb-4ee5-8bac-893a170fa766',
            'stck_session_id': 'e581e2e7-1933-4913-b239-1761b434c44d',
            'sstk_session_id': 'e581e2e7-1933-4913-b239-1761b434c44d',
            'gtm_monit_roll': '28',
            '_gcl_au': '1.1.771816893.1723647478',
            '__ssid': '28f72d1846262242ca0b17aa9194143',
            '_ga': 'GA1.1.2131351330.1723647478',
            'did': 'a0286b86-d979-4399-b62c-533c763645c1',
            'accts_customer': '903859535',
            'accts_customer_sso1': '331378495-undefined',
            'n_v': 'aed496c2095',
            'next.sid': 's%3AVTU7VfLR6gI-BMo7OEwnGlwAVztcHQ-3.%2BW35URwHTuB345Gl7VSTYbPWj3rb2gqF4gMZ%2BDTxx9M',
            'Authorization': '1%2FeyJjbGllbnRfaWQiOiJhMGI3Ni1hN2Y1ZS1mZWRlYy1iYmViZS1mYTY1Yi04NTcxOSIsInJlYWxtIjoiY3VzdG9tZXIiLCJzY29wZSI6InVzZXIudmlldyB1c2VyLmVtYWlsIHVzZXIuYWRkcmVzcyB1c2VyLmVkaXQgb3JnYW5pemF0aW9uLnZpZXcgb3JnYW5pemF0aW9uLmFkZHJlc3MgY29sbGVjdGlvbnMudmlldyBjb2xsZWN0aW9ucy5lZGl0IGxpY2Vuc2VzLnZpZXcgbGljZW5zZXMuY3JlYXRlIG1lZGlhLnVwbG9hZCBtZWRpYS5zdWJtaXQgbWVkaWEuZWRpdCBwdXJjaGFzZXMudmlldyBwdXJjaGFzZXMuY3JlYXRlIiwidXR2IjoicUhpNCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ1c2VybmFtZSI6IjkwMzg1OTUzNSIsInVzZXJfaWQiOjMzMTM3ODQ5NSwib3JnYW5pemF0aW9uX2lkIjpudWxsLCJwYXJlbnRfb3JnYW5pemF0aW9uX2lkcyI6W10sImN1c3RvbWVyX2lkIjozMzEzNzg0OTUsImV4cCI6MTcyMzY1MTAwM30.D8ssA57f7afzvpKkmArZLxjaGzPS-5LcNKbc6DfInBxNS_q4lIjRdT-cucxoJAbnNX4-XmGZyu4nZ_XlCyuxNg',
            'locale': 'zh',
            'NEXT_LOCALE': 'zh',
            'hl': 'zh',
            'downlink': 'low',
            '_4c_': '%7B%22_4c_mc_%22%3A%22b6a47d96-66fe-482e-b706-8f755b50caa9%22%7D',
            'FPID': 'FPID2.2.khIsa35ATNFYOdJwHRZS%2FQaz8pwpup%2BtFNxS00ynRAY%3D.1723647478',
            'FPLC': 'dZnYmOYJ%2BSHKtun3yMjrhnLPM4vCY1SUAyypJkfVjo7651SS97oXiQYDgpH%2BWb1TBK6DO7WPKW7UxiW10o5kyLNP44atbgljRI6MDZ08b7GAdyibKwAjERwMLhBc3w%3D%3D',
            'visit_id': '81268690780',
            'visitor_id': '73477854695',
            'htjs_user_id': '331378495',
            'htjs_anonymous_id': '7c4b5046-d8eb-4ee5-8bac-893a170fa766',
            'OptanonCachedGroups': ',C0001,C0003,C0002,C0005,C0004,C0007,',
            '__rtbh.uid': '%7B%22eventType%22%3A%22uid%22%2C%22id%22%3A%227c4b5046-d8eb-4ee5-8bac-893a170fa766%22%7D',
            'slireg': 'https://scout.us1.salesloft.com',
            'extole_access_token': 'GBMAGUNJKCVHN6MQD2I3O10R7M',
            'sliguid': 'f3718707-e12a-406c-bb72-4c6e11818ed5',
            'slirequested': 'true',
            'datadome': 'Qg34pBp0XktPTUP6O3VyAkUqSLrvf2a_ujVv06D9jHkrnwyKLAKZhmuJGINfosdXN5IReXFJ3vcOaPlr2M3PjStlds9k~IEQWAmgypcs4YRs7yeIgB7nQtymGIxzC1O_',
            'OptanonConsent': 'consentId=bd069a57-0565-4fa3-bbab-314279d2a296&datestamp=Wed+Aug+14+2024+22%3A58%3A27+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=202403.2.0&interactionCount=1&isAnonUser=1&isGpcEnabled=0&browserGpcFlag=0&isIABGlobal=false&hosts=&landingPath=https%3A%2F%2Fwww.shutterstock.com%2Fzh%2Fcatalog%2Flicenses&groups=C0001%3A1%2CC0003%3A1%2CC0002%3A1%2CC0005%3A1%2CC0004%3A1%2CC0007%3A1',
            '_ga_SSGTMSSTK': 'GS1.1.1723647477.1.1.1723647508.0.0.939777019',
            '_ga_H22ZZQTXLV': 'GS1.1.1723644993.3.1.1723647508.0.0.0',
            '_ga_5JRYE4Y8J9': 'GS1.1.1723647478.1.1.1723647508.30.0.0',
            '_uetsid': 'd11e0420584411efb988e71c7217a51d|17zp06m|2|fob|0|1685',
            '_uetvid': '58dc29704a6511ef8f5e5754465f397d|th0n3t|1723647509267|16|1|bat.bing.com/p/insights/c/x',
        }

        for count in range(counts_start, counts_last):
            image_id = image_id_id_pairs[count].split('||-||')[0]
            item_id = image_id_id_pairs[count].split('||-||')[1]
            print('执行', image_id, item_id, count)
            self.get_pic(account_id, image_id, item_id, cookie)
            count += 1
            if count == 5956:
                print('全部下载完成')
                break

if __name__ == '__main__':
    stock_detail = Stock_Detail()
    stock_detail.run()



# account = '9038595@qq.com'
# cookie_list = Con.get_stock_cookie(account)
# print(len(cookie_list))
# print(cookie_list)
# image_id_id_pairs = Con.get_stock_image_id()
# print(len(image_id_id_pairs))
# with open('image_id_pairs_9038595.py','w',encoding='utf-8') as f:
#     f.write(str(image_id_id_pairs))
