Skip to content

Commit 4f1cceb

Browse files
authored
Merge pull request Samueli924#187 from yhm97/main
修复任务为音频时报错403
2 parents 6aa2b79 + 721f7dc commit 4f1cceb

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

api/chaoxing.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def add_log(self, personid, courseid, classid, encode):
192192
self.logger.debug(resp.text)
193193
self.logger.debug("---resp.text info end---")
194194

195-
def main_pass_video(self, personid, dtoken, otherInfo, playingTime, clazzId, duration, jobid, objectId, userid, _tsp):
195+
def main_pass_video(self, personid, dtoken, otherInfo, playingTime, clazzId, duration, jobid, objectId, userid, dtype, _tsp):
196196
url = 'https://mooc1-api.chaoxing.com/multimedia/log/a/{}/{}'.format(personid, dtoken)
197197
# print(url)
198198
params = {
@@ -208,7 +208,8 @@ def main_pass_video(self, personid, dtoken, otherInfo, playingTime, clazzId, dur
208208
'isdrag': '0',
209209
'enc': self.get_enc(clazzId, jobid, objectId, playingTime, duration, userid),
210210
'rt': '0.9', # 'rt': '1.0', ??
211-
'dtype': 'Video',
211+
# 'dtype': 'Video', 音频文件为Audio
212+
'dtype': dtype,
212213
'view': 'pc',
213214
'_t': str(int(round( time.time()*1000)))
214215
}
@@ -218,9 +219,16 @@ def main_pass_video(self, personid, dtoken, otherInfo, playingTime, clazzId, dur
218219
mylist.append(my)
219220
params = "&".join(mylist)
220221
# print:(url+params)
221-
return self.session.get(url, params=params).json()
222+
tmp_response = self.session.get(url, params=params)
223+
try:
224+
result = tmp_response.json()
225+
except Exception:
226+
self.logger.debug("任务失败")
227+
result = {'error': {'status_code': tmp_response.status_code, 'text': tmp_response.text}}
228+
return result
229+
# return self.session.get(url, params=params).json()
222230

223-
def pass_video(self, video_duration, cpi, dtoken, otherInfo, clazzid, jobid, objectid, userid, name, speed, _tsp):
231+
def pass_video(self, video_duration, cpi, dtoken, otherInfo, clazzid, jobid, objectid, userid, name, speed, dtype, _tsp):
224232
sec = 58
225233
playingTime = 0
226234
print("当前播放速率:"+str(speed)+"倍速")
@@ -237,6 +245,7 @@ def pass_video(self, video_duration, cpi, dtoken, otherInfo, clazzid, jobid, obj
237245
jobid,
238246
objectid,
239247
userid,
248+
dtype,
240249
_tsp
241250
)
242251
# print(res)
@@ -245,7 +254,7 @@ def pass_video(self, video_duration, cpi, dtoken, otherInfo, clazzid, jobid, obj
245254
break
246255
elif res.get('error'):
247256
self.logger.debug("---result info begin---")
248-
self.logger.debug(res.get)
257+
self.logger.debug(res)
249258
self.logger.debug("---result info end---")
250259
raise Exception('出现错误')
251260
continue

main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def do_work(chaoxingAPI):
7171
jobid = None
7272
if "jobid" in attachments:
7373
jobid = attachments["jobid"]
74-
else:
74+
else:
7575
if "jobid" in attachment:
7676
jobid = attachment["jobid"]
7777
elif attachment.get('property', False):
@@ -92,6 +92,10 @@ def do_work(chaoxingAPI):
9292
# else:
9393
# print("当前视频不支持倍速播放,跳过")
9494
# chaoxing.speed = set_speed
95+
dtype = 'Video'
96+
if 'audio' in attachment['property']['module']:
97+
dtype = 'Audio'
98+
9599
chaoxingAPI.pass_video(
96100
video_info['duration'],
97101
attachments['defaults']['cpi'],
@@ -103,6 +107,7 @@ def do_work(chaoxingAPI):
103107
chaoxingAPI.uid,
104108
attachment['property']['name'],
105109
chaoxingAPI.speed,
110+
dtype,
106111
chaoxingAPI.get_current_ms
107112
)
108113
ft.pause(10, 13)

0 commit comments

Comments
 (0)