Skip to content

Commit

Permalink
Merge pull request #1084 from mitodl/populate-video-duration-to-edx-call
Browse files Browse the repository at this point in the history
Populate video duration to edx call
  • Loading branch information
rachellougee authored Mar 26, 2024
2 parents 7d731ce + 676a31e commit 2154f41
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ui/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
API methods
"""
from ast import literal_eval
from uuid import uuid4

import requests
Expand Down Expand Up @@ -94,6 +95,18 @@ def post_video_to_edx(video_files):
for edx_endpoint in edx_endpoints:
try:
edx_endpoint.refresh_access_token()
submitted_encode_job = (
video_files[0].video.encode_jobs.filter(state=0).first()
)
duration = 0.0
if submitted_encode_job:
duration = (
literal_eval(submitted_encode_job.message)
.get("Output", {})
.get("Duration", 0.0)
or 0.0
)

resp = requests.post(
edx_endpoint.full_api_url,
json={
Expand All @@ -102,7 +115,7 @@ def post_video_to_edx(video_files):
"encoded_videos": encoded_videos,
"courses": [{video_files[0].video.collection.edx_course_id: None}],
"status": "file_complete",
"duration": 0.0,
"duration": duration,
},
headers={
"Authorization": "JWT {}".format(edx_endpoint.access_token),
Expand Down

0 comments on commit 2154f41

Please sign in to comment.