|
|
|
@ -0,0 +1,96 @@
|
|
|
|
|
import time
|
|
|
|
|
import yaml
|
|
|
|
|
import redis
|
|
|
|
|
import requests
|
|
|
|
|
from requests import utils
|
|
|
|
|
from selenium import webdriver
|
|
|
|
|
from selenium.webdriver.chrome.options import Options
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_redis_yaml():
|
|
|
|
|
f = open(r'./redis.yml')
|
|
|
|
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redis_data = read_redis_yaml()
|
|
|
|
|
redis_host = redis_data['host']
|
|
|
|
|
redis_port = redis_data['port']
|
|
|
|
|
redis_password = redis_data['password']
|
|
|
|
|
redis_db = redis_data['db']
|
|
|
|
|
redis_pool = redis.ConnectionPool(host=redis_host, port=redis_port, password=redis_password, db=redis_db)
|
|
|
|
|
r = redis.Redis(connection_pool=redis_pool)
|
|
|
|
|
|
|
|
|
|
# 创建Chrome浏览器的一个Options实例对象
|
|
|
|
|
chrome_options = Options()
|
|
|
|
|
|
|
|
|
|
# 设置chrome禁用图片的相关设置
|
|
|
|
|
prefs = {
|
|
|
|
|
'profile.default_content_setting_values': {
|
|
|
|
|
'images': 2, # 屏蔽图片
|
|
|
|
|
'notifications': 2, # 屏蔽消息推送
|
|
|
|
|
'stylesheet': 2, # 屏蔽css
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
chrome_options.add_experimental_option("prefs", prefs)
|
|
|
|
|
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) # 设置为开发者模式,避免被识别
|
|
|
|
|
chrome_options.add_argument('--headless') # 设置无界面模式
|
|
|
|
|
driver = webdriver.Chrome(options=chrome_options)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# cookie转字典格式
|
|
|
|
|
def cookie_to_dic(cookie):
|
|
|
|
|
cookie_dic = {}
|
|
|
|
|
cookie = cookie.split(';')
|
|
|
|
|
for i in cookie:
|
|
|
|
|
if i == '':
|
|
|
|
|
continue
|
|
|
|
|
split_list = i.split('=', 1)
|
|
|
|
|
cookie_dic[split_list[0]] = split_list[1]
|
|
|
|
|
return cookie_dic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# cookie处理 获取 vusession
|
|
|
|
|
def sign_in():
|
|
|
|
|
login_headers = {
|
|
|
|
|
'Referer': 'https://v.qq.com',
|
|
|
|
|
'Cookie': str(r.get('v_cookie')) # 这里把cookie替换成自己的cookie,别把引号删了!!
|
|
|
|
|
}
|
|
|
|
|
login = requests.get(r.get('v_auth_refres'),
|
|
|
|
|
headers=login_headers) # 这里把auth_refres换成自己的,别把引号删了!!
|
|
|
|
|
cookie = requests.utils.dict_from_cookiejar(login.cookies)
|
|
|
|
|
str1 = login_headers['Cookie']
|
|
|
|
|
str2 = 'vqq_vusession='
|
|
|
|
|
sign_headers = str1[:str1.index(str2)]
|
|
|
|
|
temp = 'vqq_vusession=' + cookie['vqq_vusession']
|
|
|
|
|
sign_headers = sign_headers + temp
|
|
|
|
|
x_cookie = cookie_to_dic(sign_headers)
|
|
|
|
|
return x_cookie
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_js(url):
|
|
|
|
|
js0 = 'document.getElementsByClassName("txp_menuitem")[1].click()' # 切换清晰度
|
|
|
|
|
js1 = 'return PLAYER._DownloadMonitor.context.dataset.title,' \
|
|
|
|
|
'PLAYER._DownloadMonitor.context.dataset.ckc?PLAYER._DownloadMonitor.context.dataset.currentVideoUrl:PLAYER' \
|
|
|
|
|
'._DownloadMonitor.context.dataset.currentVideoUrl.replace(/:.*qq.com/g,' \
|
|
|
|
|
'"://defaultts.tc.qq.com/defaultts.tc.qq.com") ' # 获取m3u8地址
|
|
|
|
|
js2 = ''
|
|
|
|
|
from_url = url
|
|
|
|
|
driver.get(from_url)
|
|
|
|
|
cookie = sign_in()
|
|
|
|
|
# set up cookie 将cookie导入网页
|
|
|
|
|
for i in cookie:
|
|
|
|
|
name = i.strip(" ").strip("\n")
|
|
|
|
|
values = cookie[i].strip(" ").strip("\n")
|
|
|
|
|
print(name, ":", values)
|
|
|
|
|
driver.add_cookie({"name": name, "value": values})
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
driver.refresh()
|
|
|
|
|
driver.execute_script(js0)
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
driver.execute_script(js1)
|
|
|
|
|
return driver.execute_script(js1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
run_js('https://v.qq.com/x/cover/mzc00200v3lnbmd.html')
|