咪咕视频

master
1029559041@qq.com 5 years ago
parent 2f1006d2ff
commit 2dec6bc0a5
  1. 61
      PixivSearch/migu/GetVideoUrl.py
  2. 304
      PixivSearch/settings.py
  3. 55
      PixivSearch/urls.py
  4. 209
      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

@ -1,141 +1,163 @@
""" """
Django settings for PixivSearch project. Django settings for PixivSearch project.
Generated by 'django-admin startproject' using Django 1.11.7. Generated by 'django-admin startproject' using Django 1.11.7.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/ https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/ https://docs.djangoproject.com/en/1.11/ref/settings/
""" """
import logging.config import logging.config
import os import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'dh3^+=iugoo*+p_ea4u3dh&b!_zlgs8*m9kc+#*f2eozglsqjh' SECRET_KEY = 'dh3^+=iugoo*+p_ea4u3dh&b!_zlgs8*m9kc+#*f2eozglsqjh'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'PixivSearch.model' 'PixivSearch.model',
] 'corsheaders'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
] 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
ROOT_URLCONF = 'PixivSearch.urls' 'django.middleware.common.CommonMiddleware'
]
TEMPLATES = [ #跨域增加忽略
{ CORS_ALLOW_CREDENTIALS = True
'BACKEND': 'django.template.backends.django.DjangoTemplates', CORS_ORIGIN_ALLOW_ALL = True
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/')], CORS_ORIGIN_WHITELIST = ( '*')
'APP_DIRS': True, CORS_ALLOW_METHODS = ( 'DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'VIEW', )
'OPTIONS': { CORS_ALLOW_HEADERS = (
'context_processors': [ 'XMLHttpRequest',
'django.template.context_processors.debug', 'X_FILENAME',
'django.template.context_processors.request', 'accept-encoding',
'django.contrib.auth.context_processors.auth', 'authorization',
'django.contrib.messages.context_processors.messages', 'content-type',
], 'dnt',
}, 'origin',
}, 'user-agent',
] 'x-csrftoken',
'x-requested-with',
WSGI_APPLICATION = 'PixivSearch.wsgi.application' 'Pragma',
)
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases ROOT_URLCONF = 'PixivSearch.urls'
# DATABASES = { TEMPLATES = [
# 'default': { {
# 'ENGINE': 'django.db.backends.mysql', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
# 'NAME': 'bangumi', 'DIRS': [os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/')],
# 'USER': 'root', 'APP_DIRS': True,
# 'PASSWORD': '', 'OPTIONS': {
# 'HOST': '184.170.212.72', 'context_processors': [
# # 'HOST': 'sukura.top', 'django.template.context_processors.debug',
# 'PORT': '3306', 'django.template.context_processors.request',
# } 'django.contrib.auth.context_processors.auth',
# } 'django.contrib.messages.context_processors.messages',
],
DATABASES = { },
'default': { },
'ENGINE': 'django.db.backends.sqlite3', ]
'NAME': 'mydatabase',
} WSGI_APPLICATION = 'PixivSearch.wsgi.application'
}
# Database
# Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
# DATABASES = {
AUTH_PASSWORD_VALIDATORS = [ # 'default': {
{ # 'ENGINE': 'django.db.backends.mysql',
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # 'NAME': 'bangumi',
}, # 'USER': 'root',
{ # 'PASSWORD': '',
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # 'HOST': '184.170.212.72',
}, # # 'HOST': 'sukura.top',
{ # 'PORT': '3306',
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # }
}, # }
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', DATABASES = {
}, 'default': {
] 'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase',
}
# Internationalization }
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us' # Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
TIME_ZONE = 'Asia/Shanghai'
AUTH_PASSWORD_VALIDATORS = [
USE_I18N = True {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
USE_L10N = True },
{
USE_TZ = False 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
# Static files (CSS, JavaScript, Images) 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
# https://docs.djangoproject.com/en/1.11/howto/static-files/ },
{
STATIC_URL = '/static/' 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
STATICFILES_DIRS = [ },
os.path.join(os.path.dirname(__file__), 'static').replace('\\', '/'), ]
]
configPath = '%s/logging.conf' % os.path.dirname(__file__).replace('\\', '/') # Internationalization
logging.config.fileConfig(configPath) # https://docs.djangoproject.com/en/1.11/topics/i18n/
logger = logging.getLogger('file')
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(os.path.dirname(__file__), 'static').replace('\\', '/'),
]
configPath = '%s/logging.conf' % os.path.dirname(__file__).replace('\\', '/')
logging.config.fileConfig(configPath)
logger = logging.getLogger('file')

@ -1,27 +1,28 @@
"""PixivSearch URL Configuration """PixivSearch URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see: The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/ https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples: Examples:
Function views Function views
1. Add an import: from my_app import views 1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views Class-based views
1. Add an import: from other_app.views import Home 1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url 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 = [ urlpatterns = [
url(r'^$', index), url(r'^$', index),
url(r'^pixiv/search', search), url(r'^pixiv/search', search),
url(r'^pixiv/download', download), url(r'^pixiv/download', download),
url(r'^tsdm', saveConfig), url(r'^tsdm', saveConfig),
url(r'^bangumi/get', get), url(r'^bangumi/get', get),
url(r'^bangumi/start', start), url(r'^bangumi/start', start),
url(r'^bangumi/stop', stop) url(r'^bangumi/stop', stop),
] url(r'^migu',migu)
]

@ -1,101 +1,108 @@
# coding=utf-8 # coding=utf-8
import _thread import _thread
import os import json
import os
import django
from django.http import Http404, StreamingHttpResponse, HttpResponse import django
from django.shortcuts import render from django.http import Http404, StreamingHttpResponse, HttpResponse
from django.shortcuts import render
import root
from PixivSearch.dao.bangumi import get_, stop_, getIds import root
from PixivSearch.pixiv.pixiv import get_nodes from PixivSearch.dao.bangumi import get_, stop_, getIds
from PixivSearch.settings import logger from PixivSearch.pixiv.pixiv import get_nodes
from PixivSearch.settings import logger
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings") from PixivSearch.migu import GetVideoUrl
django.setup() # 添加的代码 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
django.setup() # 添加的代码
from PixivSearch.model import config
from PixivSearch.model import config
def search(request):
word = 'R-18' def search(request):
pageSize = 10 word = 'R-18'
order = 10 pageSize = 10
type = 'text' order = 10
type = 'text'
if request.POST.get('word') != '' and request.POST.get('word') is not None:
word = request.POST.get('word') if request.POST.get('word') != '' and request.POST.get('word') is not None:
if request.POST.get('pageSize') != '' and request.POST.get('pageSize') is not None: word = request.POST.get('word')
pageSize = int(request.POST.get('pageSize')) if request.POST.get('pageSize') != '' and request.POST.get('pageSize') is not None:
if request.POST.get('order') != '' and request.POST.get('order') is not None: pageSize = int(request.POST.get('pageSize'))
order = int(request.POST.get('order')) if request.POST.get('order') != '' and request.POST.get('order') is not None:
if request.POST.get('type') != '' and request.POST.get('type') is not None: order = int(request.POST.get('order'))
type = request.POST.get('type') if request.POST.get('type') != '' and request.POST.get('type') is not None:
type = request.POST.get('type')
try:
logger.info("word:%s,pageSize:%d,order:%d,type:%s", word, pageSize, order, type) try:
array = get_nodes([0, word, pageSize, order, type]) logger.info("word:%s,pageSize:%d,order:%d,type:%s", word, pageSize, order, type)
if len(array[0]) > 0: array = get_nodes([0, word, pageSize, order, type])
if request.POST.get('type') == 'img': if len(array[0]) > 0:
nodes = {'imageNodes': array[0], 'msg': array[1], 'download': word + '.zip', 'size': array[2], if request.POST.get('type') == 'img':
'word': word, 'pageSize': pageSize, 'order': order, 'type': type, nodes = {'imageNodes': array[0], 'msg': array[1], 'download': word + '.zip', 'size': array[2],
'imgPath': root.getConfigValue('imgPath'), 'word': word, 'pageSize': pageSize, 'order': order, 'type': type,
'baseZipPath': root.getConfigValue('baseZipPath')} 'imgPath': root.getConfigValue('imgPath'),
else: 'baseZipPath': root.getConfigValue('baseZipPath')}
nodes = {'imageNodes': array[0], 'msg': array[1], 'word': word, 'pageSize': pageSize, 'order': order, else:
'type': type} nodes = {'imageNodes': array[0], 'msg': array[1], 'word': word, 'pageSize': pageSize, 'order': order,
else: 'type': type}
nodes = {'tip': '没有返回结果'} else:
return render(request, 'index.html', nodes) nodes = {'tip': '没有返回结果'}
except ValueError: return render(request, 'index.html', nodes)
raise Http404() except ValueError:
raise Http404()
def index(request): def migu(request):
return render(request, 'index.html', {'tip': '输入参数进行搜索'}) if request.GET.get('playurl')!='' and request.GET.get('playurl') is not None:
result=GetVideoUrl.getUrl(request.GET.get('playurl'))
else:
def download(request): result={'参数不能为空'}
# do something... return HttpResponse(json.dumps(result,ensure_ascii=False), content_type='application/json', charset='utf-8')
def file_iterator(file_name, chunk_size=512):
with open(file_name) as f: def index(request):
while True: return render(request, 'index.html', {'tip': '输入参数进行搜索'})
c = f.read(chunk_size)
if c:
yield c def download(request):
else: # do something...
break def file_iterator(file_name, chunk_size=512):
with open(file_name) as f:
fileName = os.path.join(os.path.dirname(__file__), 'static/download/').replace('\\', '/') + request.GET.get( while True:
'fileName').encode('utf-8') c = f.read(chunk_size)
response = StreamingHttpResponse(file_iterator(fileName)) if c:
response['Content-Type'] = 'application/octet-stream' yield c
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(request.GET.get('fileName').encode('utf-8')) else:
return response break
fileName = os.path.join(os.path.dirname(__file__), 'static/download/').replace('\\', '/') + request.GET.get(
def saveConfig(request): 'fileName').encode('utf-8')
if 'GET' == request.method and request.GET.get('param_name'): response = StreamingHttpResponse(file_iterator(fileName))
p = config.param.objects.get(param_name=request.GET.get('param_name')) response['Content-Type'] = 'application/octet-stream'
return render(request, 'addConfig.html', p.__dict__) response['Content-Disposition'] = 'attachment;filename="{0}"'.format(request.GET.get('fileName').encode('utf-8'))
elif 'POST' == request.method and request.POST.get('param_name') and request.POST.get('param_value'): return response
p = config.param(param_name=request.POST.get('param_name'), param_value=request.POST.get('param_value'))
p.save()
return render(request, 'addConfig.html', p.__dict__) def saveConfig(request):
else: if 'GET' == request.method and request.GET.get('param_name'):
return render(request, 'addConfig.html') p = config.param.objects.get(param_name=request.GET.get('param_name'))
return render(request, 'addConfig.html', p.__dict__)
elif 'POST' == request.method and request.POST.get('param_name') and request.POST.get('param_value'):
def get(request): p = config.param(param_name=request.POST.get('param_name'), param_value=request.POST.get('param_value'))
return HttpResponse(str(get_().__str__())) p.save()
return render(request, 'addConfig.html', p.__dict__)
else:
# 测试方法 return render(request, 'addConfig.html')
def start(request):
_thread.start_new_thread(getIds, ())
return HttpResponse("start success") def get(request):
return HttpResponse(str(get_().__str__()))
def stop(request):
stop_() # 测试方法
return HttpResponse("stop success") def start(request):
_thread.start_new_thread(getIds, ())
return HttpResponse("start success")
def stop(request):
stop_()
return HttpResponse("stop success")

Loading…
Cancel
Save