-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
316 additions
and
299 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# encoding=utf-8 | ||
from playwright.async_api import Page, TimeoutError | ||
|
||
|
||
async def move_mouse(page: Page): | ||
try: | ||
await page.wait_for_selector(".videoArea", state="attached", timeout=5000) | ||
elem = page.locator(".videoArea") | ||
await elem.hover(timeout=4000) | ||
pos = await elem.bounding_box() | ||
if not pos: | ||
return | ||
# Calculate the target position to move the mouse | ||
target_x = pos['x'] + 30 | ||
target_y = pos['y'] + 30 | ||
await page.mouse.move(target_x, target_y) | ||
except TimeoutError: | ||
return | ||
|
||
|
||
async def get_progress(page: Page): | ||
def parse_time(h, m, s): | ||
return int(h) * 3600 + int(m) * 60 + int(s) | ||
|
||
curtime = "0%" | ||
await move_mouse(page) | ||
cur_play = await page.query_selector(".current_play") | ||
progress = await cur_play.query_selector(".progress-num") | ||
total_time_selector = await cur_play.query_selector(".time.fl") | ||
total_time_str = await total_time_selector.text_content() | ||
total_time = parse_time(*total_time_str.split(":")) | ||
if not progress: | ||
finish = await cur_play.query_selector(".time_icofinish") | ||
if finish: | ||
curtime = "100%" | ||
else: | ||
curtime = await progress.text_content() | ||
|
||
return curtime, total_time | ||
|
||
|
||
def show_progress(desc, cur_str=None, enableRepeat=False): | ||
percent = int(cur_str.split("%")[0]) + 1 # Handles a 1% rendering error | ||
if percent >= 80 and not enableRepeat: # In learning mode, 80% progress is considered complete | ||
percent = 100 | ||
length = int(percent * 30 // 100) | ||
progress = ("█" * length).ljust(30, " ") | ||
percent_str = str(percent) + "%" | ||
print(f"\r{desc} |{progress}| {percent_str}\t", end="", flush=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from typing import List | ||
from playwright.async_api import Page, Locator | ||
from res.configs import Config | ||
from res.progress import move_mouse | ||
import time | ||
|
||
|
||
async def optimize_page(page: Page, config: Config) -> None: | ||
try: | ||
await page.evaluate(config.pop_js) | ||
hour = time.localtime().tm_hour | ||
if hour >= 18 or hour < 7: | ||
await page.wait_for_selector(".Patternbtn-div") | ||
await page.evaluate(config.night_js) | ||
await page.wait_for_selector(".ai-show-icon.ai-icon-appear") | ||
await page.evaluate(config.remove_assist) | ||
await page.evaluate(config.no_hint) | ||
await page.evaluate(config.gzh_pop) | ||
await page.wait_for_selector(".warn-box", timeout=1500) | ||
await page.evaluate(config.close_gjh) | ||
except TimeoutError: | ||
return | ||
|
||
|
||
async def get_lesson_name(page: Page) -> str: | ||
title_ele = await page.wait_for_selector("#lessonOrder") | ||
await page.wait_for_timeout(500) | ||
title_ = await title_ele.get_attribute("title") | ||
return title_ | ||
|
||
|
||
async def video_optimize(page: Page, config: Config) -> None: | ||
try: | ||
await move_mouse(page) | ||
volumeBox = await page.wait_for_selector(".volumeBox") | ||
await volumeBox.click() | ||
await page.wait_for_timeout(200) | ||
definiBox = await page.wait_for_selector(".definiBox") | ||
await definiBox.hover() | ||
low_quality = await page.wait_for_selector(".line1bq") | ||
await low_quality.hover() | ||
await low_quality.click() | ||
await page.wait_for_timeout(200) | ||
speedBox = await page.wait_for_selector(".speedBox") | ||
await speedBox.hover() | ||
await page.evaluate(config.revise_speed_name) | ||
max_speed = await page.wait_for_selector(".speedTab15") | ||
await max_speed.hover() | ||
revise_speed = page.locator("div[rate=\"1.5\"]") | ||
await revise_speed.evaluate( | ||
f'revise => revise.setAttribute("rate","{config.limitSpeed}");' | ||
) | ||
await max_speed.click() | ||
except Exception as e: | ||
print(f"\n[Warn]{repr(e)}") | ||
|
||
|
||
async def get_filtered_class(page: Page, enableRepeat=False) -> List[Locator]: | ||
try: | ||
await page.wait_for_selector(".time_icofinish", timeout=1000) | ||
except TimeoutError: | ||
pass | ||
all_class = await page.locator(".clearfix.video").all() | ||
if enableRepeat: | ||
return all_class | ||
else: | ||
new_class = [] | ||
for each in all_class: | ||
isDone = await each.locator(".time_icofinish").count() | ||
if not isDone: | ||
new_class.append(each) | ||
return new_class |