Beispiel #1
0
    def getAjaxInfo(self):
        """获取视频ajax信息"""
        url = get_urls('url_stat')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        params = {'aid': str(self.aid), '_': '{}'.format(timestamp_ms)}
        headers = {'User-Agent': random.choice(UAS)}

        try:
            res = requests.get(url, params=params, headers=headers)
            res.raise_for_status()
        except Exception as e:
            # print(e)
            msg = 'aid({}) get error'.format(self.aid)
            bilivideolog.error(msg)
            return None
        text = json.loads(res.text)
        # print(text)
        try:
            if text['code'] == 0:
                data = text['data']
                ajax_info = (data['view'], data['danmaku'], data['reply'],
                             data['favorite'], data['coin'], data['share'],
                             data['now_rank'], data['his_rank'], data['like'],
                             data['no_reprint'], data['copyright'])
                return ajax_info

            else:
                msg = 'aid({}) ajax request code return error'.format(self.aid)
                bilivideolog.info(msg)
                return None
        except TypeError:
            msg = 'aid({}) text return None'.format(self.aid)
            bilivideolog.info(msg)
            return None
Beispiel #2
0
    def getBasicInfo(self):
        url = get_urls('url_view')
        timestamp_ms = get_timestamp()
        appkey = get_key()
        UAS = get_user_agents()
        params = {'type': 'json', 'appkey': appkey, 'id': str(
            self.aid), '_': '{}'.format(timestamp_ms)}
        # print(params)
        headers = {'User-Agent': random.choice(UAS)}
        # print(headers)

        try:
            res = requests.get(url, params=params, headers=headers)
            res.raise_for_status()
        except Exception as e:
            # print(e)
            msg = 'aid({}) get error'.format(self.aid)
            bilivideolog.error(msg)
            return None
        data = json.loads(res.text)
        # print(data)
        if 'mid' in data:
            # ('added','mid','aid','tid','cid','typename','arctype','title','pic','pages','created')
            related_info = (get_timestamp_s(), data['mid'], self.aid, data['tid'],
                            data['cid'], data['typename'], data['arctype'],
                            data['title'], data['pic'],
                            data['pages'], data['created'])
            return related_info

        else:
            msg = 'aid({}) basic info request  return error'.format(self.aid)
            bilivideolog.info(msg)
            return None
    def getVideoList(uid):
        url = get_urls('url_submit')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        headers = {'User-Agent': random.choice(UAS)}
        params = {'mid': str(uid), '_': '{}'.format(timestamp_ms)}
        video_num = 0
        video_pages = 0
        try:
            response = requests.get(url, headers=headers, params=params)
            text = json.loads(response.text)
            video_num = text['data']['count']
            video_pages = text['data']['pages']
        except Exception as e:
            msg = 'user({}) vnum text got error and {}'.format(uid, e)
            bilivideolog.error(msg)
            return None
        # 没投过稿
        if video_num < 1:
            return None

        def get_videoinfo(url, mid, pages):
            """返回所有aid的序列"""
            vlist = None
            for page in range(1, pages + 1):
                params = {
                    "mid": '{}'.format(mid),
                    "page": '{}'.format(page),
                    '_': '{}'.format(timestamp_ms)
                }
                try:
                    response = requests.get(url,
                                            headers=headers,
                                            params=params)
                    text = json.loads(response.text)
                    vlist = text['data']['vlist']
                    for item in vlist:
                        # vinfo:("mid", "aid",
                        # "tid","title","created","length","play","comment",
                        # "danmaku","favorite","hide_click")
                        vinfo = (item["mid"], item["aid"], item["typeid"],
                                 item["title"], item["created"],
                                 item["length"], item["play"], item["comment"],
                                 item["video_review"], item["favorites"],
                                 item["hide_click"])
                        # yield(item['aid'])
                        yield vinfo
                except Exception as e:
                    msg = 'uid({}) vlist get error and\n {}'.format(mid, e)
                    bilivideolog.error(msg)
                    return None

                time.sleep(1)  # 每页休息一下

        return get_videoinfo(url, uid, video_pages)
Beispiel #4
0
    def getVideoList(uid):
        url = get_urls('url_submit')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        headers = {'User-Agent': random.choice(UAS)}
        params = {'mid': str(uid), '_': '{}'.format(timestamp_ms)}
        video_num = 0
        video_pages = 0
        try:
            response = requests.get(url, headers=headers, params=params)
            text = json.loads(response.text)
            video_num = text['data']['count']
            video_pages = text['data']['pages']
        except Exception:
            msg = 'user({}) vnum text got error'.format(uid)
            bilivideolog.error(msg)
            return None
        # 没投过稿
        if video_num < 1:
            return None

        def get_aids(url, mid, pages):
            """返回所有aid的序列"""
            vlist = None
            for page in range(1, pages + 1):
                params = {"mid": '{}'.format(mid), "page": '{}'.format(page),
                          '_': '{}'.format(timestamp_ms)}
                try:
                    response = requests.get(
                        url, headers=headers, params=params)
                    text = json.loads(response.text)
                    vlist = text['data']['vlist']
                    for item in vlist:
                        yield(item['aid'])
                except Exception as e:
                    msg = 'uid({}) vlist get error and\n {}'.format(mid, e)
                    bilivideolog.error(msg)
                    return None

                time.sleep(1)  # 休息一下

        return get_aids(url, uid, video_pages)
Beispiel #5
0
    def getUserInfo(cls, uid):
        url = get_urls('url_user')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        headers = {'User-Agent': random.choice(UAS)}
        params = {'mid': str(uid), '_': '{}'.format(timestamp_ms)}

        try:
            res = requests.get(url, headers=headers, params=params)
            res.raise_for_status()
            text = json.loads(res.text)
        except Exception as e:
            msg = 'uid({}) get error'.format(uid)
            biliuserlog.error(msg)
            return None

        try:
            if text['code'] == 0:
                data = text['data']['card']

                info = (data['mid'], data['name'],
                        data['approve'], data['sex'],
                        data['DisplayRank'], data['regtime'],
                        data['spacesta'], data['birthday'],
                        data['place'],
                        data['article'], data['fans'],
                        data['attention'],
                        data['level_info']['current_level'],
                        data['official_verify']['type'],
                        data['vip']['vipStatus'])
                return info
            else:
                msg = 'uid({}) request code return error'.format(uid)
                biliuserlog.info(msg)
                return None
        except TypeError:
            msg = 'uid({}) text return None'.format(uid)
            biliuserlog.info(msg)
            return None