コード例 #1
0
def Danmuku(cid, path):
    path = path.replace('\\', '/')
    #############在这里改路径####################

    #####PC端路径示例############################
    path = 'C:/Users/xml/AppData/Roaming/Kodi/userdata/addon_data/plugin.video.bilibili/ass'
    #####coreelec端路径示例############################
    # path = '/storage/videos/ass'
    #############################################

    if os.path.exists(path):
        # shutil.rmtree(path)
        # os.makedirs(path)
        deleteFile(path)
    else:
        os.makedirs(path)
    headers = {
        'user-agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
    }
    danmuku = requests.get('https://comment.bilibili.com/' + str(cid) + '.xml',
                           headers=headers)
    danmuku.encoding = 'utf-8'
    # print(type(danmuku.text))
    with io.open(path + '/' + str(cid) + '.xml', 'w',
                 encoding='utf-8') as file:
        file.write(danmuku.text)
    file.close()
    xml2ass.Danmaku2ASS(path + '/' + str(cid) + '.xml',
                        path + '/' + str(cid) + '.ass', 1920, 540)
    os.remove(path + '/' + str(cid) + '.xml')
コード例 #2
0
ファイル: spider.py プロジェクト: SStarLib/biliSpByAv
 def get_danmu(self, oid, filename):
     danmu_url=danmu_url = 'https://api.bilibili.com/x/v1/dm/list.so?oid={}'.format(oid)
     danmu_name = os.path.join(self.dir, filename + '.xml')
     danmu_ass = os.path.join(self.dir, filename + '.ass')
     self.download_xml(danmu_url, danmu_name)
     time.sleep(0.5)
     xml2ass.Danmaku2ASS(danmu_name, danmu_ass, 1280, 720)
コード例 #3
0
ファイル: bilibili.py プロジェクト: springY1/python-spider
	def get_danmu(self, oid, filename):
		"""
		下载弹幕
		Parameters:
			oid: 弹幕oid
			filename: 弹幕保存前缀名
		Returns:
			无
		"""
		danmu_url = 'https://api.bilibili.com/x/v1/dm/list.so?oid={}'.format(oid)
		danmu_name = os.path.join(self.dir, filename + '.xml')
		danmu_ass = os.path.join(self.dir, filename + '.ass')
		self.download_xml(danmu_url, danmu_name)
		time.sleep(0.5)
		xml2ass.Danmaku2ASS(danmu_name, danmu_ass, 1280, 720)
コード例 #4
0
def Danmuku(cid):
    path = 'D:/ass'
    if os.path.exists(path):
        shutil.rmtree(path)
        os.makedirs(path)
    else:
        os.makedirs(path)
    # 链接格式:https://www.bilibili.com/video/BV******* (后面不能有/)
    # url = input('输入视频链接:')
    # bv = url[len('https://www.bilibili.com/video/'):]
    headers = {
        'user-agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
    }
    # a = requests.get('http://api.bilibili.com/x/web-interface/archive/stat?bvid='+ bv, headers = headers)
    # dict_aid = eval(a.text)
    # aid = dict_aid['data']['aid']
    # # print(aid)
    # r = requests.get("https://www.bilibili.com/widget/getPageList?aid=" + str(aid),headers = headers)
    # # print(eval(r.text))
    # cid = []
    # for i in eval(r.text):
    #     dict = i
    #     every_cid = dict['cid']
    #     cid.append(every_cid)
    # print(len(cid))

    # *******多P视频分P下载弹幕************
    # for j in range(len(cid)):
    #     p_cid = cid[j]
    #     # print(p_cid)
    danmuku = requests.get('https://comment.bilibili.com/' + str(cid) + '.xml',
                           headers=headers)
    danmuku.encoding = 'utf-8'
    # print(type(danmuku.text))
    with io.open('D:/ass/' + str(cid) + '.xml', 'w', encoding='utf-8') as file:
        file.write(danmuku.text)
    file.close()
    xml2ass.Danmaku2ASS('D:/ass/' + str(cid) + '.xml',
                        'D:/ass/' + str(cid) + '.ass', 1920, 540)
    os.remove('D:/ass/' + str(cid) + '.xml')
コード例 #5
0
def Download(url):
    if not xbmcvfs.exists(__temp__.replace('\\', '/')):
        xbmcvfs.mkdirs(__temp__)
    dirs, files = xbmcvfs.listdir(__temp__)

    for file in files:
        xbmcvfs.delete(os.path.join(__temp__, file.decode("utf-8")))

    subtitle_list = []
    try:
        #data = GetHttpData(url)
        if re.match('https://', url) == None:
            if re.match('http://', url) != None:
                url = 'https://' + url[7:]
            else:
                dialog = xbmcgui.Dialog()
                ok = dialog.ok('错误提示', '非法url')

        ifbangumiurl = re.match('https://www.bilibili.com/bangumi/play/ss',
                                url)
        ifvideourl = re.match('https://www.bilibili.com/video/', url)
        if ifbangumiurl or ifvideourl != None:
            if ifbangumiurl != None:
                ssid = re.search(r'ss[0-9]+', url)
                ssid = ssid.group()
                ssid = ssid[2:]
                r = GetHttpData(
                    'http://api.bilibili.com/pgc/web/season/section?season_id='
                    + ssid)
                j = json.loads(r)

                titles = []
                cids = []
                for p in range(len(j['result']['main_section']['episodes'])):
                    titles.append(
                        u'正片 - ' +
                        j['result']['main_section']['episodes'][p]['title'])
                    cids.append(
                        j['result']['main_section']['episodes'][p]['cid'])
                for index in range(len(j['result']['section'])):
                    duopname = j['result']['section'][index]['title']
                    for i in range(
                            len(j['result']['section'][index]['episodes'])):
                        titles.append(duopname + u' - ' +
                                      j['result']['section'][index]['episodes']
                                      [i]['title'])
                        cids.append(j['result']['section'][index]['episodes']
                                    [i]['cid'])

            if ifvideourl != None:
                bvid = ''
                aid = ''
                if re.search(r'[Bb]{1}[Vv]{1}[a-zA-Z0-9]+', url):
                    bvid = re.search(r'[Bb]{1}[Vv]{1}[a-zA-Z0-9]+', url)
                    bvid = bvid.group()
                    vurl = 'https://api.bilibili.com/x/web-interface/view?bvid=' + bvid
                if re.search('[aA]{1}[vV]{1}[0-9]+', url):
                    aid = re.search(r'[aA]{1}[vV]{1}[0-9]+', url)
                    aid = aid.group()
                    aid = aid[2:]
                    vurl = 'https://api.bilibili.com/x/web-interface/view?aid=' + aid
                r = GetHttpData(vurl)
                j = json.loads(r)
                #bvid = j['data']['pages'][0]['bvid']
                titles = []
                cids = []
                for p in range(len(j['data']['pages'])):
                    titles.append(j['data']['pages'][p]['part'])
                    cids.append(j['data']['pages'][p]['cid'])
            if len(titles) > 1:
                sel = xbmcgui.Dialog().select('请选择分集的弹幕', titles)
                if sel == -1:
                    sel = 0
            else:
                sel = 0
        r = requests.get('https://api.bilibili.com/x/v1/dm/list.so?oid=' +
                         str(cids[sel]))
        r.encoding = 'utf-8'
        data = r.text
        pDialog = xbmcgui.DialogProgress()
        pDialog.create('获取弹幕', '初始化...')
        pDialog.update(50, '获取弹幕成功...')
        # dialog = xbmcgui.Dialog()
        # dialog.textviewer('错误提示', str(data.encode('utf-8')))
    except:
        return []
    if len(data) < 1024:
        return []
    tmpfile = os.path.join(
        __temp__,
        "cid%s%s.ass" % (str(cids[sel]), os.path.splitext(url)[1])).replace(
            '\\', '/')
    # dialog = xbmcgui.Dialog()
    # dialog.textviewer('错误提示', str(tmpfile))
    with open(tmpfile, "wb") as subFile:
        subFile.write(data.encode('utf-8'))
    pDialog.update(75, '写入xml成功...')
    xbmc.sleep(500)
    xml2ass.Danmaku2ASS(tmpfile, tmpfile, 960, 540, duration_marquee=10.0)
    pDialog.update(100, '转换ass成功...')
    pDialog.close()
    subtitle_list.append(tmpfile)
    return subtitle_list
コード例 #6
0
ファイル: download.py プロジェクト: FrazierLei/python-spider
    for c in u'´☆<img draggable="false" data-mce-resize="false" data-mce-placeholder="1" data-wp-emoji="1" class="emoji" alt="❤" src="https://s.w.org/images/core/emoji/11.2.0/svg/2764.svg">◦\/:*?"<>| ':
        filename = filename.replace(c, '')
    save_video_name = filename + '.mp4'
    all_video[xunlei_video_name] = save_video_name

    addTasktoXunlei(download_url)
    # 弹幕下载
    danmu_name = filename + '.xml'
    danmu_ass = filename + '.ass'
    oid = download_url.split('/')[6]
    danmu_url = 'https://api.bilibili.com/x/v1/dm/list.so?oid={}'.format(oid)
    danmu_header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36',
                    'Accept': '*/*',
                    'Accept-Encoding': 'gzip, deflate, br',
                    'Accept-Language': 'zh-CN,zh;q=0.9'}
    with closing(sess.get(danmu_url, headers=danmu_header, stream=True, verify=False)) as response:
        if response.status_code == 200:
            with open(danmu_name, 'wb') as file:
                for data in response.iter_content():
                    file.write(data)
                    file.flush()
        else:
            print('链接异常')
    time.sleep(0.5)
    xml2ass.Danmaku2ASS(danmu_name, danmu_ass, 1280, 720)
# 视频重命名
for key, item in all_video.items():
    while key not in os.listdir('./'):
        time.sleep(1)
    os.rename(key, item)
コード例 #7
0
def Download(url):

    if not xbmcvfs.exists(__temp__.replace('\\', '/')):
        xbmcvfs.mkdirs(__temp__)
    dirs, files = xbmcvfs.listdir(__temp__)

    for file in files:
        xbmcvfs.delete(os.path.join(__temp__, file.decode("utf-8")))

    subtitle_list = []
    b = 1
    if b == 1:
        #data = GetHttpData(url)
        if re.match('https://', url) == None:
            if re.match('http://', url) != None:
                url = 'https://' + url[7:]
            else:
                dialog = xbmcgui.Dialog()
                ok = dialog.ok('错误提示', '非法url')

        ifbangumiurl = re.match('https://www.acfun.cn/bangumi/aa', url)
        ifvideourl = re.match('https://www.acfun.cn/v/ac', url)
        if ifbangumiurl or ifvideourl != None:
            if ifbangumiurl != None:
                r = GetHttpData(url)
                str1 = r.find('window.bangumiList = ')
                str2 = r.find('window.abtestConfig =')
                cutjson = r[str1 + 21:str2]
                cutjson = cutjson.split(';')[0]
                # dialog = xbmcgui.Dialog()
                # dialog.textviewer('错误提示', str(cutjson))
                j = json.loads(cutjson)

                titles = []
                cids = []
                for p in range(len(j['items'])):
                    titles.append(u'正片 - ' + j['items'][p]['episodeName'])
                    cids.append(j['items'][p]['videoId'])

            if ifvideourl != None:
                r = GetHttpData(url)
                str1 = r.find('window.pageInfo = window.videoInfo = ')
                str2 = r.find('window.videoResource =')
                cutjson = r[str1 + 37:str2]
                cutjson = cutjson.split(';')[0]
                # dialog = xbmcgui.Dialog()
                # dialog.textviewer('错误提示', str(cutjson))
                j = json.loads(cutjson)
                #bvid = j['data']['pages'][0]['bvid']
                titles = []
                cids = []
                for p in range(len(j['videoList'])):
                    titles.append(j['videoList'][p]['title'])
                    cids.append(j['videoList'][p]['id'])
            if len(titles) > 1:
                sel = xbmcgui.Dialog().select('请选择分集的弹幕', titles)
                if sel == -1:
                    sel = 0
            else:
                sel = 0
        apiheaders = {
            'user-agent':
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36',
            'cookie':
            '_did=web_471136585E37DE05; uuid=00ac251daba2fd89f2cef9937df1662b; analytics=GA1.2.979500629.1590051501; ac__avi=101092823893b8e326abdc90e6850ae2886d0cde88b81067851cf6c2c6febafe3a364146315ef65213; Hm_lvt_2af69bc2b378fb58ae04ed2a04257ed1=1589465669,1590051312,1590243605,1590284267; sign_remind=1; csrfToken=oUoc3WbPlM29zqGXhVNsi7Vb; session_id=4045767301B5686B; webp_supported=%7B%22lossy%22%3Atrue%2C%22lossless%22%3Atrue%2C%22alpha%22%3Atrue%2C%22animation%22%3Atrue%7D; lsv_js_player_v1_main=f2c6e6; lsv_js_player_v2_main=9fa1b0; clientlanguage=zh_CN; safety_id=AAJHfMhNHgUr-jBjMz48azvJ; cur_req_id=5488657659848AC3_self_93a47343167a440b05e5119c339296db; cur_group_id=5488657659848AC3_self_93a47343167a440b05e5119c339296db_0'
        }
        apidata = {'videoId': cids[sel], 'lastFetchTime': 0}
        r = requests.post(
            'https://www.acfun.cn/rest/pc-direct/new-danmaku/poll',
            apidata,
            headers=apiheaders)
        r.encoding = 'utf-8'
        r = r.text
        j = json.loads(r)
        pDialog = xbmcgui.DialogProgress()
        pDialog.create('获取弹幕', '初始化...')
        pDialog.update(25, '获取弹幕成功...')
        data = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><i><chatserver>chat.bilibili.com</chatserver><chatid>72540443</chatid><mission>0</mission><maxlimit>%d</maxlimit><state>0</state><real_name>0</real_name><source>e-r</source>' % (
            len(j['added']))
        # str1 = r.find('\"added\":[')
        # str2 = r.find('],\"host-name\"')
        # data = '{' + r[str1+8:str2] + ']}'
        for i in range(len(j['added'])):
            data += '<d p=\"' + str(
                float(j['added'][i]['position']) / float(1000))  #弹幕开始显示时间
            if re.search('.\d+,', data):
                if len(re.search('.\d+,', data).group()[1:-1]) < 5:
                    data += '0' * (5 -
                                   len(re.search('.\d+,', data).group()[1:-1]))

            data += ','
            data += str(j['added'][i]['mode']) + ','  #模式
            data += str(j['added'][i]['size']) + ','  #字体
            data += str(j['added'][i]['color']) + ','  #颜色
            data += str(int(float(j['added'][i]['createTime']) /
                            1000)) + ','  #时间戳 acfun 13位-> b站 10位
            data += '0' + ','  #弹幕池 b站特有
            data += hex(j['added'][i]['userId'])[2:] + ','  #发送者id b站特有
            data += str(j['added'][i]['danmakuId'])  #弹幕在数据库的rowid,b站特有
            data += '\">' + j['added'][i]['body'] + '</d>'
        data += '</i>'
        pDialog.update(50, 'json转xml成功...')
        # dialog = xbmcgui.Dialog()
        # dialog.textviewer('错误提示', str(data.encode('utf-8')))
        #data = r
        # if data['info'] != 'OK':
        #     return []
        # url = data['data']['info']['file']
        # data = GetHttpData(url)
    #except:
    #return []
    if len(data) < 1024:
        return []
    # t = time.time()

    # ts = time.strftime("%Y%m%d%H%M%S",time.localtime(t)) + str(int((t - int(t)) * 1000))
    tmpfile = os.path.join(
        __temp__,
        "cid%s%s.ass" % (str(cids[sel]), os.path.splitext(url)[1])).replace(
            '\\', '/')

    # dialog = xbmcgui.Dialog()
    # dialog.textviewer('错误提示', str(tmpfile))
    with open(tmpfile, "wb") as subFile:
        subFile.write(data.encode('utf-8'))
    pDialog.update(75, '写入xml成功...')
    xbmc.sleep(500)
    xml2ass.Danmaku2ASS(tmpfile, tmpfile, 960, 540, duration_marquee=10.0)
    pDialog.update(100, '转换ass成功...')
    pDialog.close()
    subtitle_list.append(tmpfile)
    return subtitle_list
コード例 #8
0
def Download(url):
    
    if not xbmcvfs.exists(__temp__.replace('\\','/')):
        xbmcvfs.mkdirs(__temp__)
    dirs, files = xbmcvfs.listdir(__temp__)
    
    for file in files:
        xbmcvfs.delete(os.path.join(__temp__, file.decode("utf-8")))
    
    subtitle_list = []
    b = 1
    if b == 1:
        #data = GetHttpData(url)
        if re.match('https://',url) == None:
            if re.match('http://',url) != None:
                url = 'https://'+url[7:]
            else:
                dialog = xbmcgui.Dialog()
                ok = dialog.ok('错误提示', '非法url')

        ifbangumiurl = re.match('https://www.bilibili.com/bangumi/play/ss',url)
        ifvideourl = re.match('https://www.bilibili.com/video/',url)
        if ifbangumiurl or ifvideourl != None:
            if ifbangumiurl != None:
                ssid = re.search(r'ss[0-9]+', url)
                ssid = ssid.group()
                ssid = ssid[2:]
                r = GetHttpData('http://api.bilibili.com/pgc/web/season/section?season_id=' + ssid)
                j = json.loads(r)
        
                titles = []
                cids = []
                for p in range(len(j['result']['main_section']['episodes'])):
                    titles.append(u'正片 - ' + j['result']['main_section']['episodes'][p]['title'])
                    cids.append(j['result']['main_section']['episodes'][p]['cid'])
                for index in range(len(j['result']['section'])):
                    duopname = j['result']['section'][index]['title']
                    for i in range(len(j['result']['section'][index]['episodes'])):
                        titles.append(duopname + u' - ' + j['result']['section'][index]['episodes'][i]['title'])
                        cids.append(j['result']['section'][index]['episodes'][i]['cid'])

            if ifvideourl != None:
                bvid = ''
                aid = ''
                if re.search(r'[Bb]{1}[Vv]{1}[a-zA-Z0-9]+', url):
                    bvid = re.search(r'[Bb]{1}[Vv]{1}[a-zA-Z0-9]+', url)
                    bvid = bvid.group()
                    vurl = 'https://api.bilibili.com/x/web-interface/view?bvid='+bvid
                if re.search('[aA]{1}[vV]{1}[0-9]+', url):
                    aid = re.search(r'[aA]{1}[vV]{1}[0-9]+', url)
                    aid = aid.group()
                    aid = aid[2:]
                    vurl = 'https://api.bilibili.com/x/web-interface/view?aid='+aid
                r = GetHttpData(vurl)
                j = json.loads(r)
                #bvid = j['data']['pages'][0]['bvid']
                titles = []
                cids = []
                for p in range(len(j['data']['pages'])):
                    titles.append(j['data']['pages'][p]['part'])
                    cids.append(j['data']['pages'][p]['cid'])
            if len(titles) > 1:
                sel = xbmcgui.Dialog().select('请选择分集的字幕', titles)
                if sel == -1:
                    sel = 0
            else:
                sel = 0
        r = requests.get('https://api.bilibili.com/x/v1/dm/list.so?oid=' + str(cids[sel]))
        r.encoding = 'utf-8'
        data = r.text
        dialog = xbmcgui.Dialog()
        dialog.textviewer('错误提示', str(data.encode('utf-8')))
        # if data['info'] != 'OK':
        #     return []
        # url = data['data']['info']['file']
        # data = GetHttpData(url)
    #except:
        #return []
    if len(data) < 1024:
        return []
    # t = time.time()
    
    # ts = time.strftime("%Y%m%d%H%M%S",time.localtime(t)) + str(int((t - int(t)) * 1000))
    tmpfile = os.path.join(__temp__, "cid%s%s.ass" % (str(cids[sel]), os.path.splitext(url)[1])).replace('\\','/')
    dialog = xbmcgui.Dialog()
    dialog.textviewer('错误提示', str(tmpfile))
    with open(tmpfile, "wb") as subFile:
        subFile.write(data.encode('utf-8'))

    xbmc.sleep(500)
    xml2ass.Danmaku2ASS(tmpfile,tmpfile,960,540,duration_marquee=10.0)

    # archive = urllib.quote_plus(tmpfile)
    # if data[:4] == 'Rar!':
    #     path = 'rar://%s' % (archive)
    # else:
    #     path = 'zip://%s' % (archive)
    # dirs, files = xbmcvfs.listdir(path)
    # if ('__MACOSX') in dirs:
    #     dirs.remove('__MACOSX')
    # if len(dirs) > 0:
    #     path = path + '/' + dirs[0].decode('utf-8')
    #     dirs, files = xbmcvfs.listdir(path)
    # list = []
    # for subfile in files:
    #     if (os.path.splitext( subfile )[1] in exts):
    #         list.append(subfile.decode('utf-8'))
    # if len(list) == 1:
    #     subtitle_list.append(path + '/' + list[0])
    # elif len(list) > 1:
    #     sel = xbmcgui.Dialog().select('请选择压缩包中的字幕', list)
    #     if sel == -1:
    #         sel = 0
    #     subtitle_list.append(path + '/' + list[sel])
    subtitle_list.append(tmpfile)
    return subtitle_list
コード例 #9
0
                 bv,
                 headers=headers)
dict_aid = eval(a.text)
aid = dict_aid['data']['aid']
# print(aid)
r = requests.get("https://www.bilibili.com/widget/getPageList?aid=" + str(aid),
                 headers=headers)
# print(eval(r.text))
cid = []
for i in eval(r.text):
    dict = i
    every_cid = dict['cid']
    cid.append(every_cid)
# print(len(cid))

# *******多P视频分P下载弹幕************
for j in range(len(cid)):
    p_cid = cid[j]
    # print(p_cid)
    danmuku = requests.get('https://comment.bilibili.com/' + str(p_cid) +
                           '.xml',
                           headers=headers)
    danmuku.encoding = 'utf-8'
    # print(type(danmuku.text))
    with open('./' + str(j) + '.xml', 'w', encoding='utf-8') as file:
        file.write(danmuku.text)
    file.close()
    xml2ass.Danmaku2ASS('./' + str(j) + '.xml', './' + str(j) + '.ass', 1920,
                        540)
    os.remove('./' + str(j) + '.xml')