|
1 |
| -# Zencoder |
| 1 | + |
| 2 | +Zencoder |
| 3 | +-------- |
| 4 | + |
2 | 5 | [](https://travis-ci.org/zencoder/zencoder-py)
|
3 | 6 |
|
4 |
| -A Python module for the [Zencoder](http://zencoder.com) API. |
| 7 | +A Python module for interacting with the [Zencoder](http://zencoder.com) API. |
| 8 | + |
| 9 | +### Getting Started |
| 10 | + |
| 11 | +Install from PyPI |
| 12 | + |
| 13 | + $ pip install zencoder |
| 14 | + |
| 15 | +Import zencoder |
| 16 | + |
| 17 | +```python |
| 18 | +from zencoder import Zencoder |
| 19 | +``` |
| 20 | + |
| 21 | +Create an instance of the Zencoder client. This will accept an API key and version. If not API key is set, it will look for a `ZENCODER_API_KEY` environment variable. API version defaults to 'v2'. |
| 22 | + |
| 23 | + # If you want to specify an API key when creating a client |
| 24 | + client = Zencoder('API_KEY') |
| 25 | + |
| 26 | + # If you have the environment variable set |
| 27 | + client = Zencoder() |
| 28 | + |
| 29 | +## [Jobs](https://app.zencoder.com/docs/api/jobs) |
| 30 | + |
| 31 | +Create a [new job](https://app.zencoder.com/docs/api/jobs/create). |
| 32 | + |
| 33 | +```python |
| 34 | +client.job.create('s3://bucket/key.mp4') |
| 35 | +client.job.create('s3://bucket/key.mp4', |
| 36 | + outputs=[{'label': 'vp8 for the web', |
| 37 | + 'url': 's3://bucket/key_output.webm'}]) |
| 38 | +``` |
| 39 | + |
| 40 | +This returns a `zencoder.Response` object. The body includes a Job ID, and one or more Output IDs (one for every output file created). |
| 41 | + |
| 42 | +```python |
| 43 | +response = client.job.create('s3://bucket/key.mp4') |
| 44 | +response.code # 201 |
| 45 | +response.body['id'] # 12345 |
| 46 | +``` |
| 47 | + |
| 48 | +[List jobs](https://app.zencoder.com/docs/api/jobs/list). |
5 | 49 |
|
6 |
| -## Installation |
7 |
| -Install from PyPI using `easy_install` or `pip`. |
| 50 | +By default the jobs listing is paginated with 50 jobs per page and sorted by ID in descending order. You can pass two parameters to control the paging: `page` and `per_page`. |
8 | 51 |
|
9 |
| - pip install zencoder |
| 52 | +```python |
| 53 | +client.job.list(per_page=10) |
| 54 | +client.job.list(per_page=10, page=2) |
| 55 | +``` |
| 56 | + |
| 57 | +Get [details](https://app.zencoder.com/docs/api/jobs/show) about a job. |
| 58 | + |
| 59 | +The number passed to `details` is the ID of a Zencoder job. |
| 60 | + |
| 61 | +```python |
| 62 | +client.job.details(1) |
| 63 | +``` |
| 64 | + |
| 65 | +Get [progress](https://app.zencoder.com/docs/api/jobs/progress) on a job. |
| 66 | + |
| 67 | +The number passed to `progress` is the ID of a Zencoder job. |
| 68 | + |
| 69 | +```python |
| 70 | +client.job.progress(1) |
| 71 | +``` |
10 | 72 |
|
11 |
| -## Dependencies |
12 |
| -`zencoder-py` depends on [requests](http://python-requests.org), and uses the `json` or `simplejson` module. |
| 73 | +[Resubmit](https://app.zencoder.com/docs/api/jobs/resubmit) a job |
13 | 74 |
|
14 |
| -## Usage |
| 75 | +The number passed to `resubmit` is the ID of a Zencoder job. |
15 | 76 |
|
16 |
| - from zencoder import Zencoder |
17 |
| - zen = Zencoder('abc123') # enter your api key |
| 77 | +```python |
| 78 | +client.job.resubmit(1) |
| 79 | +``` |
18 | 80 |
|
19 |
| - # creates an encoding job with the defaults |
20 |
| - job = zen.job.create('http://input-file/movie.avi') |
21 |
| - print job.code |
22 |
| - print job.body |
23 |
| - print job.body['id'] |
| 81 | +[Cancel](https://app.zencoder.com/docs/api/jobs/cancel) a job |
24 | 82 |
|
25 |
| - # get the transcode progress of the first output |
26 |
| - progress = zen.output.progress(job.body['outputs'][0]['id']) |
27 |
| - print progress.body |
| 83 | +The number passed to `cancel` is the ID of a Zencoder job. |
28 | 84 |
|
| 85 | +```python |
| 86 | +client.job.cancel(1) |
| 87 | +``` |
29 | 88 |
|
30 |
| - # configure your outputs with dictionaries |
31 |
| - iphone = { |
32 |
| - 'label': 'iPhone', |
33 |
| - 'url': 's3://output-bucket/output-file-1.mp4', |
34 |
| - 'width': 480, |
35 |
| - 'height': 320 |
36 |
| - } |
37 |
| - web = { |
38 |
| - 'label': 'web', |
39 |
| - 'url': 's3://output-bucket/output-file.vp8', |
40 |
| - 'video_codec':, 'vp8' |
41 |
| - } |
42 |
| - # the outputs kwarg requires an iterable |
43 |
| - outputs = (iphone, web) |
44 |
| - another_job = zen.job.create(input_url, outputs=outputs) |
| 89 | +## [Inputs](https://app.zencoder.com/docs/api/inputs) |
45 | 90 |
|
46 |
| -**Note:** If you set the `ZENCODER_API_KEY` environment variable to your api key, you don't have to provide it when initializing Zencoder. |
| 91 | +Get [details](https://app.zencoder.com/docs/api/inputs/show) about an input. |
47 | 92 |
|
48 |
| -## Specifying the API Version |
49 |
| -Set the version of the Zencoder API you want to use as the `api_version` keyword to the `Zencoder` object (defaults to `v2`): |
| 93 | +The number passed to `details` is the ID of a Zencoder job. |
50 | 94 |
|
51 | 95 | ```python
|
52 |
| -# set to version 1: https://app.zencoder.com/api/v1/ |
53 |
| -zen = Zencoder(api_version='v1') |
| 96 | +client.input.details(1) |
| 97 | +``` |
54 | 98 |
|
55 |
| -# set to the edge version: https://app.zencoder.com/api/ |
56 |
| -zen = Zencoder(api_version='edge') |
| 99 | +Get [progress](https://app.zencoder.com/docs/api/inputs/progress) for an input. |
| 100 | + |
| 101 | +The number passed to `progress` is the ID of a Zencoder job. |
| 102 | + |
| 103 | +```python |
| 104 | +client.input.progress(1) |
57 | 105 | ```
|
58 |
| -## Documentation |
59 |
| -Docs are in progress, and hosted at Read the Docs: http://zencoder.rtfd.org |
60 | 106 |
|
61 |
| -## Contributors |
62 |
| - * [Senko Rasic](http://github.com/senko) |
63 |
| - * [Josh Kennedy](http://github.com/kennedyj) |
64 |
| - * [Issac Kelly](http://github.com/issackelly) |
| 107 | +## [Outputs](https://app.zencoder.com/docs/api/outputs) |
| 108 | + |
| 109 | +Get [details](https://app.zencoder.com/docs/api/outputs/show) about an output. |
| 110 | + |
| 111 | +The number passed to `details` is the ID of a Zencoder job. |
| 112 | + |
| 113 | +```python |
| 114 | +client.output.details(1) |
| 115 | +``` |
| 116 | + |
| 117 | +Get [progress](https://app.zencoder.com/docs/api/outputs/progress) for an output. |
| 118 | + |
| 119 | +The number passed to `progress` is the ID of a Zencoder job. |
| 120 | + |
| 121 | +```python |
| 122 | +client.output.progress(1) |
| 123 | +``` |
| 124 | + |
| 125 | +## [Reports](https://app.zencoder.com/docs/api/reports) |
| 126 | + |
| 127 | +Reports are great for getting usage data for your account. All default to 30 days from yesterday with no [grouping](https://app.zencoder.com/docs/api/encoding/job/grouping), but this can be altered. These will return `422 Unprocessable Entity` if the date format is incorrect or the range is greater than 2 months. |
| 128 | + |
| 129 | +Get [all usage](https://app.zencoder.com/docs/api/reports/all) (Live + VOD). |
| 130 | + |
| 131 | +```python |
| 132 | +import datetime |
| 133 | +client.report.all() |
| 134 | +client.report.all(grouping="foo") |
| 135 | +client.report.all(start_date=datetime.date(2011, 10, 30), |
| 136 | + end_date=datetime.date(2011, 11, 24)) |
| 137 | +client.report.all(start_date=datetime.date(2011, 10, 30), |
| 138 | + end_date=datetime.date(2011, 11, 24), |
| 139 | + grouping="foo") |
| 140 | +``` |
| 141 | + |
| 142 | +Get [VOD usage](https://app.zencoder.com/docs/api/reports/vod). |
| 143 | + |
| 144 | +```python |
| 145 | +import datetime |
| 146 | +client.report.vod() |
| 147 | +client.report.vod(grouping="foo") |
| 148 | +client.report.vod(start_date=datetime.date(2011, 10, 30), |
| 149 | + end_date=datetime.date(2011, 11, 24)) |
| 150 | +client.report.vod(start_date=datetime.date(2011, 10, 30), |
| 151 | + end_date=datetime.date(2011, 11, 24), |
| 152 | + grouping="foo") |
| 153 | +``` |
| 154 | + |
| 155 | +Get [Live usage](https://app.zencoder.com/docs/api/reports/live). |
| 156 | + |
| 157 | +```python |
| 158 | +import datetime |
| 159 | +client.report.live() |
| 160 | +client.report.live(grouping="foo") |
| 161 | +client.report.live(start_date=datetime.date(2011, 10, 30), |
| 162 | + end_date=datetime.date(2011, 11, 24)) |
| 163 | +client.report.live(start_date=datetime.date(2011, 10, 30), |
| 164 | + end_date=datetime.date(2011, 11, 24), |
| 165 | + grouping="foo") |
| 166 | +``` |
| 167 | + |
| 168 | +## [Accounts](https://app.zencoder.com/docs/api/accounts) |
| 169 | + |
| 170 | +Create a [new account](https://app.zencoder.com/docs/api/accounts/create). A unique email address and terms of service are required, but you can also specify a password (and confirmation) along with whether or not you want to subscribe to the Zencoder newsletter. New accounts will be created under the Test (Free) plan. |
| 171 | + |
| 172 | +No API Key is required. |
| 173 | + |
| 174 | +```python |
| 175 | +client.account.create('foo@example.com', tos=1) |
| 176 | +client.account.create('foo@example.com', tos=1, |
| 177 | + options={'password': 'abcd1234', |
| 178 | + 'affiliate_code': 'foo'}) |
| 179 | +``` |
| 180 | + |
| 181 | +Get [details](https://app.zencoder.com/docs/api/accounts/show) about the current account. |
| 182 | + |
| 183 | +```python |
| 184 | +client.account.details() |
| 185 | +``` |
| 186 | + |
| 187 | +Turn [integration mode](https://app.zencoder.com/docs/api/accounts/integration) on (all jobs are test jobs). |
| 188 | + |
| 189 | +```python |
| 190 | +client.account.integration() |
| 191 | +``` |
| 192 | + |
| 193 | +Turn off integration mode, which means your account is live (and you'll be billed for jobs). |
| 194 | + |
| 195 | +```python |
| 196 | +client.account.live() |
| 197 | +``` |
| 198 | +## Tests |
| 199 | + |
| 200 | +The tests use the `mock` library to stub in response data from the API. Run tests individually: |
| 201 | + |
| 202 | + $ python test/test_jobs.py |
| 203 | + |
| 204 | +Or use `nose`: |
65 | 205 |
|
| 206 | + $ nosetests |
66 | 207 |
|
0 commit comments