@@ -111,3 +111,63 @@ def start_job(self, obj, transcode_kwargs, message=''):
111
111
job .object_id = obj .pk
112
112
job .message = message
113
113
job .save ()
114
+
115
+
116
+ class AliyunTranscoder (Transcoder ):
117
+
118
+ def __init__ (
119
+ self ,
120
+ access_key_id = None ,
121
+ access_key_secret = None ,
122
+ pipeline_id = None ,
123
+ region = None ,
124
+ notify_url = None
125
+ ):
126
+ if not access_key_id :
127
+ access_key_id = get_setting_or_raise ('ALIYUN_TRANSCODE_ACCESS_KEY_ID' )
128
+ self .access_key_id = access_key_id
129
+
130
+ if not access_key_secret :
131
+ access_key_secret = get_setting_or_raise ('ALIYUN_TRANSCODE_ACCESS_KEY_SECRET' )
132
+ self .access_key_secret = access_key_secret
133
+
134
+ if not pipeline_id :
135
+ pipeline_id = get_setting_or_raise ('ALIYUN_TRANSCODE_PIPELINE_ID' )
136
+ self .pipeline_id = pipeline_id
137
+
138
+ if not region :
139
+ region = get_setting_or_raise ('ALIYUN_TRANSCODE_REGION' )
140
+ self .region = region
141
+
142
+ if not notify_url :
143
+ notify_url = get_setting_or_raise ('ALIYUN_TRANSCODE_NOTIFY_URL' )
144
+ self .notify_url = notify_url
145
+
146
+ from aliyunsdkcore import client
147
+
148
+ self .client = client .AcsClient (self .access_key_id , self .access_key_secret , self .region )
149
+
150
+ def start_job (self , obj , transcode_kwargs , message = '' ):
151
+ """
152
+ https://help.aliyun.com/document_detail/57347.html?spm=5176.doc56767.6.724.AJ8z3E
153
+ """
154
+
155
+ import json
156
+ from aliyunsdkmts .request .v20140618 import SubmitJobsRequest
157
+
158
+ request = SubmitJobsRequest .SubmitJobsRequest ()
159
+ request .set_accept_format ('json' )
160
+ request .set_Input (json .dumps (transcode_kwargs .get ('input_file' )))
161
+ request .set_OutputBucket (transcode_kwargs .get ('bucket' ))
162
+ request .set_OutputLocation (transcode_kwargs .get ('oss_location' ))
163
+ request .set_Outputs (json .dumps (transcode_kwargs .get ('outputs' )))
164
+ request .set_PipelineId (self .pipeline_id )
165
+ response = json .loads (self .client .do_action_with_exception (request ).decode ('utf-8' ))
166
+
167
+ content_type = ContentType .objects .get_for_model (obj )
168
+ job = EncodeJob ()
169
+ job .id = response ['JobResultList' ]['JobResult' ][0 ]['Job' ]['JobId' ]
170
+ job .content_type = content_type
171
+ job .object_id = obj .pk
172
+ job .message = message
173
+ job .save ()
0 commit comments