Esempio n. 1
0
 def getSubmitNumber(self):
     url = "%s?mid=%s&page=1&pagesize=1" % (bilibili.submitUrl, str(
         self.mid))
     # print(url)
     try:
         return bilibili.getDict(bilibili.getHTMLText(url))['data']['count']
     except bException.bError as e:
         raise e
Esempio n. 2
0
    def getSubRepliesNum(self):
        try:
            url = "%s?pn=1&type=%d&oid=%d&sort=1&ps=1&root=%d" % (
                bilibili.subreplyUrl, 1, self.aid, self.rid)

            res = bilibili.getDict(bilibili.getHTMLText(url))
            return res['data']['page']['count']

        except bException.bError as e:
            raise e
Esempio n. 3
0
    def getHistoryDanmaku(self, date):
        url = "%s?type=1&date=%s&oid=%d" % (bilibili.historyDanmakuUrl,
                                            date.strftime("%Y-%m-%d"),
                                            self.getOid())
        print(url)

        try:
            return self.__getDanmakuHelper(
                bilibili.getHTMLText(url, bilibili.login_headers))
        except bException.bError as e:
            raise e
Esempio n. 4
0
    def getReply(self, page=1, sort=1):
        try:
            url = "%s?pn=%d&type=%d&oid=%d&sort=%d" % (bilibili.replyUrl, page,
                                                       1, self.aid, sort)
            # print(url)
            res = bilibili.getDict(bilibili.getHTMLText(url))

            return self.__getReplyHelper(res['data']['replies'])

        except bException.bError as e:
            raise e
Esempio n. 5
0
    def getReplyInfo(self):
        try:
            url = "%s?pn=%d&type=%d&oid=%d&sort=%d" % (bilibili.replyUrl, 1, 1,
                                                       self.getOid(), 1)
            res = bilibili.getDict(bilibili.getHTMLText(url))

            resDict = {}
            resDict['acount'] = res['data']['page']['acount']
            resDict['count'] = res['data']['page']['count']
        except bException.bError as e:
            raise e
Esempio n. 6
0
    def getSubmitEx(self):
        url = "%s?mid=%s&page=1&pagesize=%s" % (
            bilibili.submitUrl, str(self.mid), str(self.getSubmitNumber()))
        # print(url)
        submitDict = ""
        resList = []
        try:

            submitDict = bilibili.getDict(bilibili.getHTMLText(url))
            # print(submitDict)
            vlist = submitDict['data']['vlist']

            # 遍历每一个投稿
            for item in vlist:
                aid = item['aid']
                submitDetailDict = {}
                detail = {}
                try:
                    # 取得每一个投稿的详细信息
                    url = "%s?aid=%s" % (bilibili.submitDetailUrl, str(aid))
                    submitDetailDict = bilibili.getDict(
                        bilibili.getHTMLText(url))
                    detail = submitDetailDict['data']
                except:
                    return []

                resList.append(
                    submit.submitEx(item['typeid'], item['play'],
                                    item['title'], item['created'],
                                    item['video_review'], item['favorites'],
                                    aid, self.mid, detail['reply'],
                                    detail['coin'], detail['like'],
                                    detail['his_rank']))

        except:
            return resList
        return resList
Esempio n. 7
0
def getUpper(mid, cfg, proxy={}):
    url = "%s?vmid=%s" % (bilibili.upInfoUrl, str(mid))
    response = bilibili.getHTMLText(url)
    if response == None:
        return None
    status_code = response[0]

    if status_code != 200:
        return status_code

    # 获取基本信息
    updict = bilibili.getDict(response[1])

    #----------------------------------------------------------

    url = bilibili.upInfoDetailUrl

    postData = {
        'csrf': cfg.getAttr('csrf'),  #'099defc050cb8ad2827ca8493d06ab91'
        'mid': mid
    }
    # 获取用户详细信息
    r = requests.post(bilibili.upInfoDetailUrl,
                      data=postData,
                      headers=bilibili.detail_headers,
                      proxies=proxy)
    status_code = r.status_code

    # 获取失败
    if status_code != 200:
        return status_code

    res = bilibili.getDict(r.text)
    # 这里对regtime进行特殊处理是因为实践中发现regtime似乎并不是每个用户都有
    # 有些特别的用户获取不到regtime. 另外有些字段获取的到不过为空或者其他什么奇怪的东西就是啦..
    regtime = 0
    if 'regtime' in res['data']:
        regtime = res['data']['regtime']

    try:
        return upper(updict['data']['mid'], updict['data']['follower'],
                     res['data']['name'], res['data']['face'], regtime,
                     res['data']['sex'],
                     res['data']['level_info']['current_level'],
                     res['data']['vip']['vipType'],
                     res['data']['vip']['vipStatus'])
    except:
        return None
Esempio n. 8
0
    def getAllDanmakus(self, path):
        # 获取当前时间
        today = datetime.datetime.now()
        # 获取视频发布时间
        createdDate = datetime.datetime.fromtimestamp(self.createdTime)
        # 获取两日间隔
        daysGap = today - createdDate

        fileobj = open(path, 'w', encoding="UTF-8")
        # 写入文件头
        fileobj.write('''
        <?xml version="1.0" encoding="UTF-8"?><i>
        <chatserver>chat.bilibili.com</chatserver>
        <mission>0</mission>
        <maxlimit>%d</maxlimit>
        <state>0</state>
        <real_name>0</real_name>
        <source>k-v</source>
        ''' % (self.danmaku))
        #循环每一天
        for i in range(0, daysGap.days):
            date = createdDate + datetime.timedelta(days=i)
            # 请求地址
            url = "%s?type=1&date=%s&oid=%d" % (bilibili.historyDanmakuUrl,
                                                date.strftime("%Y-%m-%d"),
                                                self.getOid())
            text = ""
            print("getting %s\n" % (url))
            try:
                text = bilibili.getHTMLText(url, bilibili.login_headers)
            except:
                continue

            soup = BeautifulSoup(text, 'lxml')
            ds = soup.find_all('d')
            s = set()
            for i in ds:
                s.add(str(i))
            for i in s:
                fileobj.write(i)

        fileobj.write("</i>")
        fileobj.close()
Esempio n. 9
0
    def getSubReplies(self, sort=1):
        try:
            url = "%s?pn=1&type=%d&oid=%d&sort=%d&ps=%d&root=%d" % (
                bilibili.subreplyUrl, 1, self.aid, sort,
                self.getSubRepliesNum(), self.rid)
            res = bilibili.getDict(bilibili.getHTMLText(url))

            repliesList = []
            subRepliesDict = res['data']['replies']
            for r in subRepliesDict:
                nr = reply(r['content']['message'], r['member']['mid'],
                           r['member']['uname'], r['floor'], r['ctime'],
                           r['like'], r['content']['plat'], r['oid'],
                           r['rpid'], r['root'], self.upmid)
                repliesList.append(nr)

            return repliesList

        except bException.bError as e:
            raise e
Esempio n. 10
0
 def getOid(self):
     url = "%s%s" % (bilibili.archieveUrl, str(self.aid))
     text = ""
     try:
         text = bilibili.getHTMLText(url)
     except bException.bError as e:
         raise e
     oidInfo = re.findall(r'"cid":[\d]*', text)
     '''
       突然发现有一些视频不知道为什么提取不了cid. 这些视频的普遍特征就是在B站看的时候预览
       显示不出播放量。 应该是早期作♂品
     '''
     try:
         return eval(oidInfo[0].split(':')[1])
     except:
         oidInfo = re.findall(r'"cid": [\d]*', text)
         try:
             return eval(oidInfo[0].split(':')[1])
         except:
             return -1
Esempio n. 11
0
    def getSubmit(self):
        url = "%s?mid=%s&page=1&pagesize=%s" % (
            bilibili.submitUrl, str(self.mid), str(self.getSubmitNumber()))
        # print(url)
        submitDict = ""
        resList = []
        try:
            submitDict = bilibili.getDict(bilibili.getHTMLText(url))
            # print(submitDict)
            vlist = submitDict['data']['vlist']

            # 遍历每一个投稿
            for item in vlist:
                resList.append(
                    submit.submit(item['typeid'], item['play'], item['title'],
                                  item['created'], item['video_review'],
                                  item['favorites'], item['aid'], self.mid))

        except bException.bError as e:
            raise e
        return resList
Esempio n. 12
0
    def getDanmaku(self):
        url = "%s?oid=%s" % (bilibili.danmakuUrl, str(self.getOid()))
        text = ""
        # resList = []
        try:
            text = bilibili.getHTMLText(url)
            # soup = BeautifulSoup(text, 'lxml')
            # ds = soup.find_all('d')

            # # 遍历所有弹幕标签
            # for item in ds:
            #     dproperty = item.get('p')
            #     dps = dproperty.split(',')
            #     resList.append(
            #         danmaku.danmaku(
            #             time.strftime("%Y-%m-%d %H:%M:%S",
            #                           time.localtime(eval(dps[4]))),
            #             item.get_text(), eval(dps[1]), self.aid))
            return self.__getDanmakuHelper(text)

        except bException.bError as e:
            raise e
        return resList