Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuban10703 committed Sep 21, 2021
1 parent 3a18595 commit fee0593
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 50 deletions.
113 changes: 66 additions & 47 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ def knowledge_sort(self, all_knowledge):
keys_sorted = natsorted(dict_all_knowledge.keys())
return [dict_all_knowledge[k] for k in keys_sorted]

def pass_video(self, video_duration, cpi, dtoken, otherInfo, clazzid, jobid, objectid):
sec = 58
for playingTime in range(video_duration + 120):
if sec >= 58:
sec = 0
res = self.chaoxing.pass_video(
cpi,
dtoken,
otherInfo,
playingTime,
clazzid,
video_duration,
jobid,
objectid
)
# print(res)
if res.get('isPassed'):
self.print_progress_bar(video_duration, video_duration)
break
elif res.get('error'):
raise Exception('请联系作者')
continue
self.print_progress_bar(playingTime, video_duration)
sec += 1
time.sleep(1)

def main(self):
if not self.chaoxing.login():
print('登录失败')
Expand All @@ -86,56 +112,49 @@ def main(self):
for knowledge_id_data in self.knowledge_sort(
course_data['data'][0]['course']['data'][0]['knowledge']['data']): # 遍历排序过的任务点
# print(knowledge_id_data)
knowledge_card_web_text = self.chaoxing.get_knowledge_card(
course_all_id_data[int(index_id)]['clazzid'],
course_all_id_data[int(index_id)]['courseid'],
knowledge_id_data['id'])
# print(knowledge_card_web_text)
# print(knowledge_id_data['id'])
attachments: dict = self.get_attachments(knowledge_card_web_text)
if not attachments:
continue
if not attachments.get('attachments'):
continue
print(f'当前章节:{knowledge_id_data["label"]}:{knowledge_id_data["name"]}')
for attachment in attachments['attachments']: # 遍历任务点
# print(attachment)
if attachment.get('type') != 'video': # 只刷视频
knowledge_json = self.chaoxing.get_knowledge_json(
knowledge_id_data['id'],
course_all_id_data[int(index_id)]['clazzid']
)
# print(knowledge_json)
tabs = len(knowledge_json['data'][0]['card']['data'])
# print(tabs)
for tab_index in range(tabs):
knowledge_card_web_text = self.chaoxing.get_knowledge_card(
course_all_id_data[int(index_id)]['clazzid'],
course_all_id_data[int(index_id)]['courseid'],
knowledge_id_data['id'],
tab_index
)
# print(knowledge_card_web_text)
# print(knowledge_id_data['id'])
attachments: dict = self.get_attachments(knowledge_card_web_text)
if not attachments:
continue
print(f"当前视频:{attachment['property']['name']}")
if attachment.get('isPassed'): # 跳过已完成的
self.print_progress_bar(1, 1)
if not attachments.get('attachments'):
continue
video_info = self.chaoxing.get_d_token(
attachment['objectId'],
attachments['defaults']['fid']
)
# print(video_info)
# playingTime = 0
sec = 58
for playingTime in range(video_info['duration'] + 1):
if sec >= 58 or playingTime == video_info['duration']:
sec = 0
res = self.chaoxing.pass_video(
attachments['defaults']['cpi'],
video_info['dtoken'],
attachments['attachments'][0]['otherInfo'],
playingTime,
course_all_id_data[int(index_id)]['clazzid'],
video_info['duration'],
attachments['attachments'][0]['jobid'],
video_info['objectid']
)
# print(res)
if res.get('isPassed'):
self.print_progress_bar(video_info['duration'], video_info['duration'])
break
elif res.get('error'):
raise Exception('请联系作者')
print(f'当前章节:{knowledge_id_data["label"]}:{knowledge_id_data["name"]}')
for attachment in attachments['attachments']: # 遍历任务点
# print(attachment)
if attachment.get('type') != 'video': # 只刷视频
continue
print(f"当前视频:{attachment['property']['name']}")
if attachment.get('isPassed'): # 跳过已完成的
self.print_progress_bar(1, 1)
continue
self.print_progress_bar(playingTime, video_info['duration'])
sec += 1
time.sleep(1)
video_info = self.chaoxing.get_d_token(
attachment['objectId'],
attachments['defaults']['fid']
)
self.pass_video(
video_info['duration'],
attachments['defaults']['cpi'],
video_info['dtoken'],
attachments['attachments'][0]['otherInfo'],
course_all_id_data[int(index_id)]['clazzid'],
attachments['attachments'][0]['jobid'],
video_info['objectid']
)
time.sleep(random.randint(1, 3))


Expand Down
28 changes: 25 additions & 3 deletions models/APIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,28 @@ def get_jobs_nodes(self, courseid, clazzid, nodes):
return self.client.post(url, data=data).json()

@retry(stop_max_attempt_number=3)
def get_knowledge_card(self, clazzid, courseid, knowledgeid):
def get_knowledge_json(self, id, courseid):
url = 'https://mooc1-api.chaoxing.com/gas/knowledge'
enc = self.get_infEnc_and_time()
params = {
'id': id,
'courseid': courseid,
'fields': 'id,parentnodeid,indexorder,label,layer,name,begintime,createtime,lastmodifytime,status,jobUnfinishedCount,clickcount,openlock,card.fields(id,knowledgeid,title,knowledgeTitile,description,cardorder).contentcard(all)',
'view': 'json',
'token': "4faa8662c59590c6f43ae9fe5b002b42",
'_time': enc[0],
'inf_enc': enc[1]
}
return self.client.get(url, params=params).json()

@retry(stop_max_attempt_number=3)
def get_knowledge_card(self, clazzid, courseid, knowledgeid, num):
url = 'https://mooc1-api.chaoxing.com/knowledge/cards'
params = {
'clazzid': clazzid,
'courseid': courseid,
'knowledgeid': knowledgeid,
'num': 0,
'num': num,
'isPhone': 1,
'control': True,
'cpi': self.personid
Expand All @@ -120,7 +135,7 @@ def get_d_token(self, objectid, fid):
}
return self.client.get(url, params=params).json()

@retry(stop_max_attempt_number=3)
@retry(stop_max_attempt_number=3, wait_random_min=1000, wait_random_max=2000)
def pass_video(self, personid, dtoken, otherInfo, playingTime, clazzId, duration, jobid, objectId):
url = 'https://mooc1-api.chaoxing.com/multimedia/log/a/{}/{}'.format(personid, dtoken)
# print(url)
Expand All @@ -142,6 +157,13 @@ def pass_video(self, personid, dtoken, otherInfo, playingTime, clazzId, duration
}
return self.client.get(url, params=params).json()

def get_infEnc_and_time(self):
m_time = str(int(time.time() * 1000))
m_token = '4faa8662c59590c6f43ae9fe5b002b42'
m_encrypt_str = 'token=' + m_token + '&_time=' + m_time + '&DESKey=Z(AfY@XS'
m_inf_enc = md5(m_encrypt_str.encode('utf-8')).hexdigest()
return m_time, m_inf_enc

def get_enc(self, clazzId, jobid, objectId, playingTime, duration):
# https://github.com/ZhyMC/chaoxing-xuexitong-autoflush/blob/445c8d8a8cc63472dd90cdf2a6ab28542c56d93b/logger.js
return md5(
Expand Down

0 comments on commit fee0593

Please sign in to comment.