Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 05762f9

Browse files
committed
restore old transcription workflow
1 parent ee75aff commit 05762f9

File tree

3 files changed

+249
-1
lines changed

3 files changed

+249
-1
lines changed

control/old_veda_deliver_cielo.py

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import requests
2+
import ast
3+
import urllib
4+
5+
"""
6+
Cielo24 API Job Start and Download
7+
Options (reflected in Course.models):
8+
transcription_fidelity =
9+
Mechanical (75%),
10+
Premium (95%)(3-72h),
11+
Professional (99+%)(3-72h)
12+
priority =
13+
standard (24h),
14+
priority (48h)
15+
turnaround_hours = number, overrides 'priority' call, will change a standard to a priority silently
16+
"""
17+
from control_env import *
18+
from veda_utils import ErrorObject
19+
20+
requests.packages.urllib3.disable_warnings()
21+
22+
23+
class Cielo24TranscriptOld(object):
24+
25+
def __init__(self, veda_id):
26+
self.veda_id = veda_id
27+
'''Defaults'''
28+
self.c24_site = 'https://api.cielo24.com/api'
29+
self.c24_login = '/account/login'
30+
self.c24_joblist = '/job/list'
31+
self.c24_newjob = '/job/new'
32+
self.add_media = '/job/add_media'
33+
self.transcribe = '/job/perform_transcription'
34+
35+
'''Retreive C24 Course-based defaults'''
36+
self.c24_defaults = self.retrieve_defaults()
37+
38+
def perform_transcription(self):
39+
if self.c24_defaults['c24_user'] is None:
40+
return None
41+
'''
42+
GET /api/job/perform_transcription?v=1 HTTP/1.1
43+
&api_token=xxxx
44+
&job_id=xxxx
45+
&transcription_fidelity=PREMIUM&priority=STANDARD
46+
Host: api.cielo24.com
47+
'''
48+
api_token = self.tokengenerator()
49+
if api_token is None:
50+
return None
51+
52+
job_id = self.generate_jobs(api_token)
53+
task_id = self.embed_url(api_token, job_id)
54+
55+
r5 = requests.get(
56+
''.join((
57+
self.c24_site,
58+
self.transcribe,
59+
'?v=1&api_token=',
60+
api_token,
61+
'&job_id=',
62+
job_id,
63+
'&transcription_fidelity=',
64+
self.c24_defaults['c24_fidelity'],
65+
'&priority=',
66+
self.c24_defaults['c24_speed']
67+
))
68+
)
69+
return ast.literal_eval(r5.text)['TaskId']
70+
71+
def retrieve_defaults(self):
72+
video_query = Video.objects.filter(
73+
edx_id=self.veda_id
74+
).latest()
75+
76+
url_query = URL.objects.filter(
77+
videoID=video_query,
78+
encode_url__icontains='_DTH.mp4',
79+
).latest()
80+
81+
if video_query.inst_class.c24_username is None:
82+
ErrorObject.print_error(
83+
message='Cielo24 Record Incomplete',
84+
)
85+
return None
86+
87+
c24_defaults = {
88+
'c24_user': video_query.inst_class.c24_username,
89+
'c24_pass': video_query.inst_class.c24_password,
90+
'c24_speed': video_query.inst_class.c24_speed,
91+
'c24_fidelity': video_query.inst_class.c24_fidelity,
92+
'edx_id': self.veda_id,
93+
'url': url_query.encode_url
94+
}
95+
return c24_defaults
96+
97+
def tokengenerator(self):
98+
token_url = self.c24_site + self.c24_login + \
99+
'?v=1&username=' + self.c24_defaults['c24_user'] + \
100+
'&password=' + self.c24_defaults['c24_pass']
101+
102+
# Generate Token
103+
r1 = requests.get(token_url)
104+
if r1.status_code > 299:
105+
ErrorObject.print_error(
106+
message='Cielo24 API Access Error',
107+
)
108+
return None
109+
api_token = ast.literal_eval(r1.text)["ApiToken"]
110+
return api_token
111+
112+
def listjobs(self):
113+
"""List Jobs"""
114+
api_token = self.tokengenerator()
115+
r2 = requests.get(
116+
''.join((
117+
self.c24_site,
118+
self.c24_joblist,
119+
'?v=1&api_token=',
120+
api_token
121+
))
122+
)
123+
job_list = r2.text
124+
return job_list
125+
126+
def generate_jobs(self, api_token):
127+
"""
128+
'https://api.cielo24.com/job/new?v=1&\
129+
api_token=xxx&job_name=xxx&language=en'
130+
"""
131+
r3 = requests.get(
132+
''.join((
133+
self.c24_site,
134+
self.c24_newjob,
135+
'?v=1&api_token=',
136+
api_token,
137+
'&job_name=',
138+
self.c24_defaults['edx_id'],
139+
'&language=en'
140+
))
141+
)
142+
job_id = ast.literal_eval(r3.text)['JobId']
143+
return job_id
144+
145+
def embed_url(self, api_token, job_id):
146+
"""
147+
GET /api/job/add_media?v=1&api_token=xxxx
148+
&job_id=xxxxx
149+
&media_url=http%3A%2F%2Fwww.domain.com%2Fvideo.mp4 HTTP/1.1
150+
Host: api.cielo24.com
151+
"""
152+
r4 = requests.get(
153+
''.join((
154+
self.c24_site,
155+
self.add_media,
156+
'?v=1&api_token=',
157+
api_token,
158+
'&job_id=',
159+
job_id,
160+
'&media_url=',
161+
urllib.quote_plus(self.c24_defaults['url'])
162+
))
163+
)
164+
print str(r4.status_code) + ' : Cielo24 Status Code'
165+
return ast.literal_eval(r4.text)['TaskId']
166+
167+
168+
def main():
169+
pass
170+
171+
172+
if __name__ == "__main__":
173+
sys.exit(main())

control/veda_deliver.py

+73-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
"""
77
import datetime
8+
import ftplib
89
import logging
910
import shutil
1011
from os.path import expanduser
11-
import sys
1212

1313
import boto
1414
import boto.s3
@@ -19,6 +19,7 @@
1919
from boto.s3.key import Key
2020
from django.core.urlresolvers import reverse
2121

22+
from control.old_veda_deliver_cielo import Cielo24TranscriptOld
2223
from control_env import *
2324
from veda_deliver_cielo import Cielo24Transcript
2425
from veda_deliver_youtube import DeliverYoutube
@@ -128,6 +129,11 @@ def run(self):
128129
u1.encode_size = self.video_proto.filesize
129130
u1.save()
130131

132+
# TODO: Warning! this shall be removed once 3rd party credentials
133+
# for existing courses are migrated according to new flow.
134+
self._THREEPLAY_UPLOAD()
135+
self._CIELO24_UPLOAD()
136+
131137
self.status = self._DETERMINE_STATUS()
132138
self._UPDATE_DATA()
133139
self._CLEANUP()
@@ -629,6 +635,72 @@ def start_3play_transcription_process(self, encoded_file):
629635
self.video_query.studio_id,
630636
)
631637

638+
def _CIELO24_UPLOAD(self):
639+
"""
640+
Note: This is part of the old flow which was deprecated when transcript phase 1 was reased.
641+
"""
642+
# TODO: this must be removed once existing 3rd party credentials are migrated according
643+
# to the new workflow.
644+
if self.video_query.inst_class.c24_proc is False:
645+
return None
646+
647+
if self.encode_profile != 'desktop_mp4':
648+
return None
649+
650+
C24 = Cielo24TranscriptOld(
651+
veda_id=self.video_query.edx_id
652+
)
653+
output = C24.perform_transcription()
654+
print '[ %s ] : %s' % (
655+
'Cielo24 JOB', self.video_query.edx_id
656+
)
657+
658+
def _THREEPLAY_UPLOAD(self):
659+
"""
660+
Note: This is part of the old flow which was deprecated when transcript phase 1 was reased.
661+
"""
662+
# TODO: this must be removed once existing 3rd party credentials are migrated according
663+
# to the new workflow.
664+
if self.video_query.inst_class.tp_proc is False:
665+
return None
666+
667+
if self.encode_profile != 'desktop_mp4':
668+
return None
669+
670+
ftp1 = ftplib.FTP(
671+
self.auth_dict['threeplay_ftphost']
672+
)
673+
user = self.video_query.inst_class.tp_username.strip()
674+
passwd = self.video_query.inst_class.tp_password.strip()
675+
try:
676+
ftp1.login(user, passwd)
677+
except:
678+
ErrorObject.print_error(
679+
message='3Play Authentication Failure'
680+
)
681+
try:
682+
ftp1.cwd(
683+
self.video_query.inst_class.tp_speed
684+
)
685+
except:
686+
ftp1.mkd(
687+
self.video_query.inst_class.tp_speed
688+
)
689+
ftp1.cwd(
690+
self.video_query.inst_class.tp_speed
691+
)
692+
os.chdir(self.node_work_directory)
693+
694+
ftp1.storbinary(
695+
'STOR ' + self.encoded_file,
696+
open(os.path.join(
697+
self.node_work_directory,
698+
self.encoded_file
699+
), 'rb')
700+
)
701+
702+
os.chdir(homedir)
703+
632704
def YOUTUBE_SFTP(self, review=False):
633705
if self.video_query.inst_class.yt_proc is False:
634706
if self.video_query.inst_class.review_proc is False:

static_config.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
# This configuration should only have static settings.
33

4+
# 3PlayMedia FTP host for old workflow
5+
threeplay_ftphost: ftp.3playmedia.com
6+
47
# s3 bucket static prefixes
58
edx_s3_processed_prefix: prod-edx/processed/
69
edx_s3_rejected_prefix: prod-edx/rejected/

0 commit comments

Comments
 (0)