Skip to content

Commit

Permalink
[优化方案]避免重复刷同一课程视频,支持多实例同时刷不同课程视频的优化方案 (#383)
Browse files Browse the repository at this point in the history
* 多实例观看视频
  • Loading branch information
cxfjh authored Nov 12, 2024
1 parent b7a3c4f commit 7742460
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
from api.exceptions import LoginError, FormatError, JSONDecodeError,MaxRollBackError
from api.answer import Tiku
from urllib3 import disable_warnings,exceptions
import os

# 定义全局变量,用于存储配置文件路径
textPath = './resource/BookID.txt'

# 获取文本 -> 用于查看学习过的课程ID
def getText():
try:
if not os.path.exists(textPath):
with open(textPath, 'x') as file: pass
return []
with open(textPath, 'r', encoding='utf-8') as file: content = file.read().split(',')
content = {int(item.strip()) for item in content if item.strip()}
return list(content)
except Exception as e: logger.error(f"获取文本失败: {e}"); return []

# 追加文本 -> 用于记录学习过的课程ID
def appendText(text):
if not os.path.exists(textPath): return
with open(textPath, 'a', encoding='utf-8') as file: file.write(f'{text}, ')


# 关闭警告
disable_warnings(exceptions.InsecureRequestWarning)

Expand Down Expand Up @@ -104,6 +126,8 @@ def add_times(self,id:str) -> None:
job_info = None
jobs, job_info = chaoxing.get_job_list(course["clazzId"], course["courseId"], course["cpi"], point["id"])

bookID = job_info["knowledgeid"] # 获取视频ID

# 发现未开放章节,尝试回滚上一个任务重新完成一次
try:
if job_info.get('notOpen',False):
Expand All @@ -129,6 +153,13 @@ def add_times(self,id:str) -> None:
for job in jobs:
# 视频任务
if job["type"] == "video":

TextBookID = getText() # 获取学习过的课程ID
if TextBookID.count(bookID) > 0:
logger.info(f"课程: {course['title']} 章节: {point['title']} 任务: {job['title']} 已学习过或在学习中,跳过") # 如果已经学习过该课程,则跳过
break # 如果已经学习过该课程,则跳过
appendText(bookID) # 记录正在学习的课程ID

logger.trace(f"识别到视频任务, 任务章节: {course['title']} 任务ID: {job['jobid']}")
# 超星的接口没有返回当前任务是否为Audio音频任务
isAudio = False
Expand Down

0 comments on commit 7742460

Please sign in to comment.