咪咕视频

master
1029559041@qq.com 6 years ago
parent 2f1006d2ff
commit 2dec6bc0a5
  1. 61
      PixivSearch/migu/GetVideoUrl.py
  2. 24
      PixivSearch/settings.py
  3. 5
      PixivSearch/urls.py
  4. 9
      PixivSearch/view.py

@ -0,0 +1,61 @@
import json
import re
import requests
from bs4 import BeautifulSoup
def getUrl(playurl):
# 请求头
headers = {
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/56.0.2924.87 Safari/537.36'
}
# headers['referer']='http://www.miguvideo.com/wap/resource/pc/detail/miguplay.jsp?cid=650644142'
baseurl = 'www.miguvideo.com/wap/resource/pc/detail/miguplay.jsp'
try:
if re.match("^(http|https):\/\/www\.miguvideo\.com\/wap\/resource\/pc\/detail\/miguplay\.jsp\?cid=\d+$",playurl):
req = requests.get(playurl, headers=headers)
sessionID = 0
playId = 0
# 提取接口参数
cid = re.findall('\d+', playurl)[0]
# 获取sessionID
result={'msg':'网络异常'}
if req.status_code == 200:
document = BeautifulSoup(req.text, 'lxml')
print('sessionID=%s' % sessionID)
sessionID = document.select('#sessionID')[0].get('value')
print('sessionID=%s' % sessionID)
# 获取playId
if req.status_code == 200:
req = requests.get('http://www.miguvideo.com/wap/resource/pc/data/miguData.jsp?cid=%s' % cid,
headers=headers)
miguData = json.loads(req.text)
print('playId=%s' % playId)
playId = miguData[0]['playId']
print('playId=%s' % playId)
# 使用播放地址接口获取视频信息
req = requests.get(
'http://www.miguvideo.com/playurl/v1/play/playurlh5?contId=%s&rateType=1,2,3&clientId=%s' % (
playId, sessionID))
if req.status_code == 200:
videoInfo = json.loads(req.text)
# 解析出json结构视频信息,获取视频真实地址
result = {'name': miguData[0]['Detail'],'video':[]};
print("视频信息=%s" % miguData[0]['Detail'])
if videoInfo['code'] == '200' and 'body' in videoInfo and 'urlInfos' in videoInfo['body']:
for info in videoInfo['body']['urlInfos']:
result['video'].append({'rateDesc':info['rateDesc'],'url':info['url'],'mediaSize':info['mediaSize']})
print('清晰度=%s' % info['rateDesc'])
print('真实地址=%s' % info['url'])
print('视频大小=%s字节' % info['mediaSize'])
else:
result = {'msg': '不是合法播放地址'}
except BaseException as e:
result={'msg':'程序异常'}
return result

@ -37,7 +37,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'PixivSearch.model'
'PixivSearch.model',
'corsheaders'
]
MIDDLEWARE = [
@ -48,7 +49,28 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware'
]
#跨域增加忽略
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = ( '*')
CORS_ALLOW_METHODS = ( 'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'VIEW', )
CORS_ALLOW_HEADERS = (
'XMLHttpRequest',
'X_FILENAME',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'Pragma',
)
ROOT_URLCONF = 'PixivSearch.urls'

@ -14,7 +14,7 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from PixivSearch.view import search, index, download, saveConfig, get, start, stop
from PixivSearch.view import search, index, download, saveConfig, get, start, stop, migu
urlpatterns = [
url(r'^$', index),
@ -23,5 +23,6 @@ urlpatterns = [
url(r'^tsdm', saveConfig),
url(r'^bangumi/get', get),
url(r'^bangumi/start', start),
url(r'^bangumi/stop', stop)
url(r'^bangumi/stop', stop),
url(r'^migu',migu)
]

@ -1,5 +1,6 @@
# coding=utf-8
import _thread
import json
import os
import django
@ -10,7 +11,7 @@ import root
from PixivSearch.dao.bangumi import get_, stop_, getIds
from PixivSearch.pixiv.pixiv import get_nodes
from PixivSearch.settings import logger
from PixivSearch.migu import GetVideoUrl
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
django.setup() # 添加的代码
@ -50,6 +51,12 @@ def search(request):
except ValueError:
raise Http404()
def migu(request):
if request.GET.get('playurl')!='' and request.GET.get('playurl') is not None:
result=GetVideoUrl.getUrl(request.GET.get('playurl'))
else:
result={'参数不能为空'}
return HttpResponse(json.dumps(result,ensure_ascii=False), content_type='application/json', charset='utf-8')
def index(request):
return render(request, 'index.html', {'tip': '输入参数进行搜索'})

Loading…
Cancel
Save