8000 improve Transcoder · mauler/django-elastic-transcoder@8c10654 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c10654

Browse files
committed
improve Transcoder
1 parent 46dcda6 commit 8c10654

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

dj_elastictranscoder/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
__version__ = '0.1'
2+
3+
from .transcoder import Transcoder

dj_elastictranscoder/tests.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def test_oncomplete(self):
114114
self.assertEqual(job.state, 4)
115115

116116

117-
118117
class SignalTest(TestCase):
119118

120119
def test_transcode_init(self):
@@ -233,3 +232,24 @@ def test_transcode_oncomplete(self):
233232
self.assertEqual('1396802241671-jkmme8', job.id)
234233
self.assertEqual('Success', job.message)
235234
self.assertEqual(4, job.state)
235+
236+
237+
"""
238+
class TranscoderTest(TestCase):
239+
def test_transcoder(self):
240+
from .transcoder import Transcoder
241+
242+
input = {
243+
'Key': 'music/00/09/00094930/6c55503185ac4a42b68d01d8277cd84e.mp3',
244+
}
245+
246+
outputs = [{
247+
'Key': 'hello.mp3',
248+
'PresetId': '1351620000001-300040' # for example: 128k mp3 audio preset
249+
}]
250+
251+
pipeline_id = '<pipeline_id>'
252+
253+
transcoder = Transcoder(pipeline_id, 'ap-southeast-1')
254+
transcoder.encode(input, outputs)
255+
"""

dj_elastictranscoder/transcoder.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from boto import elastictranscoder
2+
3+
from django.conf import settings
4+
5+
from .signals import transcode_init
6+
7+
8+
class Transcoder(object):
9+
def __init__(self, pipeline_id, region=None):
10+
self.pipeline_id = pipeline_id
11+
12+
if not region:
13+
region = getattr(settings, 'AWS_REGION', None)
14+
15+
self.aws_region = region
16+
17+
self.aws_access_key_id = getattr(settings, 'AWS_ACCESS_KEY_ID', '')
18+
self.aws_secret_access_key = getattr(settings, 'AWS_SECRET_ACCESS_KEY', '')
19+
20+
if not self.aws_access_key_id:
21+
assert False, 'Please provide AWS_ACCESS_KEY_ID'
22+
23+
if not self.aws_secret_access_key:
24+
assert False, 'Please provide AWS_SECRET_ACCESS_KEY'
25+
26+
if not self.aws_region:
27+
assert False, 'Please provide AWS_REGION'
28+
29+
30+
def encode(self, input_name, outputs):
31+
encoder = elastictranscoder.connect_to_region(
32+
self.aws_region,
33+
aws_access_key_id=self.aws_access_key_id,
34+
aws_secret_access_key=self.aws_secret_access_key)
35+
36+
message = encoder.create_job(self.pipeline_id, input_name, outputs=outputs)
37+
38+
# send signal
39+
transcode_init.send(sender=None, message=message)

dj_elastictranscoder/utils.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0