Skip to content

Commit 23a8d01

Browse files
committed
Merge pull request #39 from greedo/upload_texttracks
Upload texttracks
2 parents 2522f4f + c146669 commit 23a8d01

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ video_uri = v.upload('your-filename.mp4')
9393

9494
Once you have an authenticated instance of the `VimeoClient` class, you can also replace the source file of an existing video.
9595

96-
```
96+
```python
9797
video_uri = v.replace(
9898
video_uri='video_uri',
9999
filename='your-filename.mp4',
@@ -114,6 +114,18 @@ v.upload_picture('/videos/12345', 'your-image.jpg', activate=True)
114114

115115
Note: This will make it the active picture for all users this way. The `activate` keyword argument defaults to `False`, so without it you will need to activate the picture yourself.
116116

117+
### Uploading a text track
118+
119+
Once you have an authenticated instance of the `VimeoClient` class, uploading a text track requires the video uri of the video the text track will be added to, text track type, text track language, and text track filename.
120+
121+
```python
122+
v = vimeo.VimeoClient(
123+
key=YOUR_API_TOKEN,
124+
secret=YOUR_TOKEN_SECRET)
125+
126+
v.upload_texttrack('/videos/12345', 'captions', 'en-US', 'your-texttrack.vtt')
127+
```
128+
117129
# Legacy Python Library
118130

119131
An earlier version of this library used a more complicated ORM syntax. This library is still available from this github repo via the [orm-tornado](https://github.com/vimeo/vimeo.py/releases/tag/orm-tornado) tag.

vimeo/upload.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,33 @@ def upload_picture(self, obj, filename, activate=False):
123123

124124
return picture
125125

126+
class UploadTexttrackMixin(object):
127+
"""Functionality for uploading a texttrack to Vimeo for a video.
128+
"""
129+
TEXTTRACK_ENDPOINT = '{video_uri}/texttracks'
130+
131+
def upload_texttrack(self, video_uri, track_type, language, filename):
132+
"""Upload the texttrack at the given uri with the named source file."""
133+
uri = self.TEXTTRACK_ENDPOINT.format(video_uri=video_uri)
134+
name = filename.split('/')[-1]
135+
136+
texttrack = self.post(uri,
137+
data={'type': track_type,
138+
'language': language,
139+
'name': name})
140+
141+
assert texttrack.status_code == 201, \
142+
"Failed to create a new texttrack with Vimeo."
143+
144+
texttrack = texttrack.json()
145+
146+
with open(filename) as f:
147+
upload_resp = self.put(texttrack['link'], data=f)
148+
assert upload_resp.status_code == 200, "Failed uploading"
149+
150+
return texttrack
151+
126152

127-
class UploadMixin(UploadVideoMixin, UploadPictureMixin):
153+
class UploadMixin(UploadVideoMixin, UploadPictureMixin, UploadTexttrackMixin):
128154
"""Handle uploading to the Vimeo API."""
129155
pass

0 commit comments

Comments
 (0)