| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | import jsonimport randomimport timeimport requestsfrom common import Common, AliyunLoggerfrom common.sql_help import sqlCollectfrom data_channel.data_help import dataHelpclass SPH:    @classmethod    def find_target_user(cls, name, user_list):        """        在搜索到到账号列表中找目标列表        """        for obj in user_list:            if obj['contact']["nickname"] == name:                return obj            else:                continue        return False    @classmethod    def get_account_id(cls, account_name):        channel = 'shipinhao'        history_id = sqlCollect.get_history_id(channel, account_name)        if history_id:            return history_id        else:            url = "http://61.48.133.26:30001/Find_Video_Content"            payload = json.dumps({                "content": account_name,                "type": "19"            })            headers = {                'Content-Type': 'application/json'            }            response = requests.request("POST", url, headers=headers, data=payload)            info_list = response.json()['info_list']            if len(info_list) == 0:                return False            target_user = cls.find_target_user(name=account_name, user_list=info_list)            # 写入 MySql 数据库            if target_user:                target = target_user['contact']['username']                sqlCollect.insert_history_id(account_name, target, channel)                return target_user['contact']["username"]            else:                return False    @classmethod    def get_sph_url(cls, task_mark, url_id, number, mark, channel_id, name):        account_id = cls.get_account_id(url_id)        if account_id:            url = "http://61.48.133.26:30001/FinderGetUpMasterNextPage"            last_buffer = ""            list = []            for i in range(10):                headers = {                    'Content-Type': 'application/json'                }                payload = json.dumps({                    "username": account_id,                    "last_buffer": last_buffer                })                response = requests.request("POST", url, headers=headers, data=payload)                time.sleep(random.randint(1, 5))                res_json = response.json()                try:                    if len(res_json["DownloadAddress"]) == 0 or res_json["DownloadAddress"] == "" or res_json["DownloadAddress"] == None:                        return list                except:                    pass                if "objectId" not in response.text or response.status_code != 200:                    continue                if len(res_json["UpMasterHomePage"]) == 0:                    continue                if not res_json["UpMasterHomePage"]:                    continue                else:                    last_buffer = res_json.get('last_buffer')                    for obj in res_json["UpMasterHomePage"]:                        objectId = obj['objectId']                        status = sqlCollect.is_used(task_mark, objectId, mark, "视频号")                        objectNonceId = obj['objectNonceId']                        url1 = "http://61.48.133.26:30001/GetFinderDownloadAddress"                        payload = json.dumps({                            "objectId": objectId,                            "objectNonceId": objectNonceId                        })                        headers = {                            'Content-Type': 'text/plain'                        }                        response = requests.request("POST", url1, headers=headers, data=payload)                        time.sleep(random.randint(0, 1))                        video_obj = response.json()                        video_url = video_obj.get('DownloadAddress')                        share_cnt = int(obj['forward_count'])  # 分享                        like_cnt = int(obj['like_count'])  # 点赞                        old_title = video_obj.get('title').split("\n")[0].split("#")[0]                        duration = dataHelp.video_duration(video_url)                        log_data = f"user:{url_id},,video_id:{objectId},,video_url:{video_url},,original_title:{old_title},,share_count:{share_cnt},,like_count:{like_cnt},,duration:{duration}"                        AliyunLogger.logging(channel_id, name, url_id, objectId, "扫描到一条视频", "2001", log_data)                        Common.logger("sph").info(                            f"扫描:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")                        if status:                            AliyunLogger.logging(channel_id, name, url_id, objectId, "该视频已改造过", "2001", log_data)                            continue                        video_percent = '%.2f' % (share_cnt / like_cnt)                        special = float(0.25)                        if like_cnt >= 30000 or like_cnt >= 50000 or (share_cnt >= 300 and float(video_percent) >= special):                            if int(duration) < 30 or int(duration) > 720:                                Common.logger("sph").info(                                    f"任务:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt} ,时长:{duration} ")                                AliyunLogger.logging(channel_id, name, url, objectId, "不符合规则:时长不符合规则大于720秒/小于30秒",                                                     "2003", log_data)                                continue                            cover = video_obj.get('thumb_url')                            AliyunLogger.logging(channel_id, name, url_id, objectId, "符合规则等待改造", "2004", log_data)                            all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title}                            list.append(all_data)                            if len(list) == int(number):                                Common.logger(mark).info(f"获取视频号视频总数:{len(list)}\n")                                return list                        else:                            AliyunLogger.logging(channel_id, name, url_id, objectId, "不符合规则:点赞小于30000/50000 或 分享/点赞小于0.25和分享小于300", "2003", log_data)                            Common.logger("sph").info(                                     f"不符合规则:{task_mark},用户主页id:{url_id},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt}")                            continue                                            return list        return []if __name__ == '__main__':    SPH.get_sph_url('1',"霖霖觅影",'10','2',"视频号",'视频号品类账号')
 |