Skip to content

Commit 8c9ebb9

Browse files
committed
v2.5 Half不好用版本。解决了切出时视频暂停的问题,但引入了新问题:视频播放完毕后暂停会被重新播放(从前面开始播放),之前判断视频是否播放完毕的方法失效
1 parent 10beb80 commit 8c9ebb9

File tree

1 file changed

+28
-86
lines changed

1 file changed

+28
-86
lines changed

main.py

Lines changed: 28 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,7 @@
22
Author: LetMeFly
33
Date: 2021-11-01 15:52:32
44
LastEditors: LetMeFly
5-
LastEditTime: 2023-06-26 13:21:17
6-
'''
7-
8-
'''
9-
PS F:\OtherApps\Program\VsCode\Code> & F:/OtherApps/Program/Python/Python/python.exe f:/OtherApps/Program/VsCode/Code/YuKeTang.py
10-
11-
DevTools listening on ws://127.0.0.1:59227/devtools/browser/1345bf1f-6b58-47d7-98cb-20e955bbe99a
12-
请扫码登陆
13-
[8224:6516:1102/113245.817:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
14-
[8224:21044:1102/113245.819:ERROR:device_event_log_impl.cc(214)] [11:32:45.820] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
15-
[8224:6516:1102/113245.820:ERROR:chrome_browser_main_extra_parts_metrics.cc(233)] crbug.com/1216328: Checking Bluetooth availability ended.
16-
[8224:6516:1102/113245.861:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.
17-
[8224:6516:1102/113245.893:ERROR:chrome_browser_main_extra_parts_metrics.cc(240)] crbug.com/1216328: Checking default browser status ended.
18-
登录成功
19-
此课程已完成
20-
此课程已完成
21-
此课程已完成
22-
不是课程
23-
此课程已完成
24-
不是课程
25-
此课程已完成
26-
不是课程
27-
此课程已完成
28-
此课程已完成
29-
此课程已完成
30-
不是课程
31-
不是课程
32-
此课程已完成
33-
此课程已完成
34-
此课程已完成
35-
[12280:19080:1102/113441.896:ERROR:gpu_init.cc(453)] Passthrough is not supported, GL is disabled, ANGLE is
36-
不是课程
37-
不是课程
38-
此课程已完成
39-
此课程已完成
40-
此课程已完成
41-
不是课程
42-
不是课程
43-
此课程已完成
44-
此课程已完成
45-
此课程已完成
46-
不是课程
47-
此课程已完成
48-
此课程已完成
49-
此课程已完成
50-
不是课程
51-
此课程已完成
52-
此课程已完成
53-
此课程已完成
54-
不是课程
55-
是课程
56-
暂停状态
57-
正在播放
58-
此课程播放完毕!
59-
此课程已完成
60-
是课程
61-
暂停状态
62-
正在播放
63-
此课程播放完毕!
64-
不是课程
65-
是课程
66-
暂停状态
67-
正在播放
68-
此课程播放完毕!
69-
是课程
70-
暂停状态
71-
正在播放
72-
此课程播放完毕!
73-
是课程
74-
暂停状态
75-
正在播放
76-
此课程播放完毕!
77-
不是课程
78-
不是课程
79-
全部完成!
5+
LastEditTime: 2023-09-12 19:27:08
806
'''
817

828
from selenium import webdriver
@@ -99,7 +25,7 @@
9925
# 完成一门课程的函数
10026
def finishThisCourse(courseId):
10127
# 访问此视频
102-
driver.get("https://grsbupt.yuketang.cn/pro/lms/84eubUaed9T/16809342/video/" + courseId)
28+
driver.get("https://grsbupt.yuketang.cn/pro/lms/84eubUXLHEy/17556639/video/" + courseId)
10329
# 判断是否已经完成
10430
sleep(3)
10531
if len(driver.find_elements_by_class_name("icon--gou")):
@@ -145,23 +71,39 @@ def ifCouldPlayAVideo():
14571
# # print("执行失败")
14672
# sleep(3)
14773
# sleep(1)
148-
driver.execute_script("setInterval(function() {if (document.querySelector('video').paused) {document.querySelector('video').play();}}, 200);")
74+
75+
driver.execute_script("video = document.querySelector('video');")
76+
element_video = driver.find_element_by_tag_name('video')
77+
webdriver.ActionChains(driver).move_to_element(element_video).perform()
78+
webdriver.ActionChains(driver).click().perform()
79+
driver.execute_script("startVideo = setInterval(() => {video.play(); console.log('尝试播放视频');}, 1000); setTimeout(() => {clearInterval(startVideo); console.log('停止尝试播放视频')}, 5200);")
14980
print("正在播放")
150-
while not driver.execute_script("function ifFinished() {percent = document.querySelector('.xt_video_player_progress_currentTime');style = percent.getAttribute('style');return style=='width: 100%;'} return ifFinished();"):
81+
driver.execute_script("video.addEventListener('pause', function() {video.play();});")
82+
sleep(5)
83+
element_speeds = driver.find_element_by_class_name('xt_video_player_common_value')
84+
webdriver.ActionChains(driver).move_to_element(element_speeds).perform()
85+
sleep(0.2)
86+
element_speed2 = driver.find_element_by_xpath('//*[@id="video-box"]/div/xt-wrap/xt-controls/xt-inner/xt-speedbutton/xt-speedlist/ul/li[1]')
87+
webdriver.ActionChains(driver).move_to_element_with_offset(element_speed2, 3, 5).perform()
88+
sleep(0.3)
89+
element_speed2.click()
90+
# webdriver.ActionChains(driver).context_click(element_speed2).perform()
91+
92+
while not len(driver.find_elements_by_class_name("icon--gou")):
15193
sleep(1)
15294
print("此课程播放完毕!")
15395
return True
15496

15597

15698
# 访问每一门课
157-
while True:
158-
try:
159-
for courseId in range(35657455, 35657509 + 1):
160-
finishThisCourse(str(courseId))
161-
print("全部完成!")
162-
break
163-
except:
164-
pass
99+
for courseId in range(37551787, 37551907 + 1):
100+
# try:
101+
if True:
102+
finishThisCourse(str(courseId))
103+
# except:
104+
# pass
105+
print("全部完成!")
106+
165107

166108

167109
# 雨课堂字幕:https://buct.yuketang.cn/mooc-api/v1/lms/service/subtitle_parse/?c_d=0D0C4F3DE7D58B649C33DC5901307461&lg=0&_=1665473764724

0 commit comments

Comments
 (0)