class
get_video_content(get_video_time,get_user_id):
def
__init__(
self
,class_id,course_id):
self
.course_id
=
course_id
self
.class_id
=
class_id
get_user_id.__init__(
self
)
self
.ts
=
get_timestamp()
self
.url_get_video_content
=
"".
format
(course_id)
self
.params_get_video_content
=
json.dumps({
"class_id"
:class_id})
self
.headers_get_video_content
=
{""
}
self
.cookies
=
get_cookies()
self
.video_list
=
[]
self
.parse_get_video_list()
self
.video_list_queue
=
Queue()
for
video_id
in
self
.video_list:
self
.video_list_queue.put(video_id)
self
.list_thread
=
[]
for
i
in
range
(
5
):
t
=
threading.Thread(target
=
self
.run_video_queue)
self
.list_thread.append(t)
for
t
in
self
.list_thread:
t.setDaemon(
True
)
t.start()
self
.video_list_queue.join()
def
run_video_queue(
self
):
while
True
:
video_id
=
self
.video_list_queue.get()
get_video_time.__init__(
self
,
self
.course_id,
self
.class_id,video_id,
self
.user_id)
self
.video_list_queue.task_done()
def
parse_get_video_list(
self
):
r
=
requests.post(
self
.url_get_video_content,headers
=
self
.headers_get_video_content,cookies
=
self
.cookies,data
=
self
.params_get_video_content)
r
=
json.loads(r.content.decode())
for
x
in
r[
"coursewareArray"
]:
try
:
video_id
=
x[
"children"
][
"items"
][
"item_id"
]
video_complete
=
x[
"done"
]
if
not
video_complete:
self
.video_list.append(video_id)
except
:
pass