Skip to content

Commit

Permalink
修复视频url多个分段获取问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Vespa314 committed Nov 6, 2015
1 parent a5bc0e2 commit 2bab607
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
32 changes: 11 additions & 21 deletions GetVideoUrl/biliDownLoad.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
#Modified by SuperFashi
#coding=utf-8

import sys
import gzip
import json
import hashlib
import re
import urllib.parse
import urllib.request
import urllib2
import xml.dom.minidom
import zlib

Expand All @@ -30,10 +28,10 @@ def GetBilibiliUrl(url):
media_args = {'otype': 'json', 'cid': cid, 'type': 'mp4', 'quality': 4, 'appkey': APPKEY}
resp_media = urlfetch(url_get_media+GetSign(media_args,APPKEY,APPSEC))
resp_media = dict(json.loads(resp_media.decode('utf-8', 'replace')))
media_urls = resp_media.get('durl')
media_urls = media_urls[0]
media_urls = media_urls.get('url')
return media_urls
res = []
for media_url in resp_media.get('durl'):
res.append(media_url.get('url'))
return res

def GetSign(params,appkey,AppSecret=None):
params['appkey']=appkey
Expand All @@ -51,22 +49,14 @@ def GetSign(params,appkey,AppSecret=None):
return data+'&sign='+m.hexdigest()

def urlfetch(url):
req_headers = {'Accept-Encoding': 'gzip, deflate', 'User-Agent': USER_AGENT}
req = urllib.request.Request(url=url, headers=req_headers)
response = urllib.request.urlopen(req, timeout=120)
content_encoding = response.info().get('Content-Encoding')
if content_encoding == 'gzip':
data = gzip.GzipFile(fileobj=response).read()
elif content_encoding == 'deflate':
decompressobj = zlib.decompressobj(-zlib.MAX_WBITS)
data = decompressobj.decompress(response.read())+decompressobj.flush()
else:
data = response.read()
return data
req_headers = {'User-Agent': USER_AGENT}
req = urllib2.Request(url=url, headers=req_headers)
return urllib2.urlopen(req).read()

if __name__ == '__main__':
if len(sys.argv) == 1:
print('输入视频播放地址')
else:
media_urls = GetBilibiliUrl(sys.argv[1])
print(media_urls)
for media_url in media_urls:
print media_url
8 changes: 6 additions & 2 deletions python API/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ def GetBilibiliUrl(url, appkey, AppSecret=None):
media_args = {'otype': 'json', 'cid': cid, 'type': 'mp4', 'quality': 4}
resp_media = getURLContent(url_get_media+GetSign(media_args,appkey,AppSecret))
resp_media = dict(json.loads(resp_media.decode('utf-8', 'replace')))
return resp_media.get('durl')[0].get('url')
res = []
for media_url in resp_media.get('durl'):
res.append(media_url.get('url'))
return res

def GetVideoOfUploader(mid,pagesize=20,page=1):
url = 'http://space.bilibili.com/ajax/member/getSubmitVideos?mid=%d&pagesize=%d&page=%d'%(getint(mid),getint(pagesize),getint(page))
Expand Down Expand Up @@ -544,7 +547,8 @@ def GetVideoOfUploader(mid,pagesize=20,page=1):
# print danmu.t_video,danmu.t_stamp,danmu.content
#获取视频下载地址列表
# media_urls = GetBilibiliUrl('http://www.bilibili.com/video/av1691618/',appkey = appkey,AppSecret=secretkey)
# print(media_urls)
# for media_url in media_urls:
# print(media_url)
#视频搜索
# for video in biliVideoSearch(appkey,secretkey,'rwby'):
# print video.title
Expand Down

0 comments on commit 2bab607

Please sign in to comment.