Skip to content

Commit

Permalink
upload texttracks added
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Cabrera committed Sep 25, 2014
1 parent bafd046 commit d7a0af2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion vimeo/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,34 @@ def upload_picture(self, obj, filename, activate=False):

return picture

class UploadTexttrackMixin(object):
"""Functionality for uploading a texttrack to Vimeo for a video.
"""
TEXTRACK_ENDPOINT = '{video_uri}/texttracks'

def upload_texttrack(self, video_uri, track_type, language, filename):
"""Upload a texttrack for the object.
"""
uri = self.TEXTRACK_ENDPOINT.format(video_uri=video_uri)
name = filename.split('/')[-1]

texttrack = self.post(uri,
data={'type': track_type,
'language': language,
'name': name})

assert texttrack.status_code == 201, \
"Failed to create a new texttrack with Vimeo."

texttrack = texttrack.json()

with open(filename) as f:
upload_resp = self.put(texttrack['link'], data=f)
assert upload_resp.status_code == 200, "Failed uploading"

return texttrack


class UploadMixin(UploadVideoMixin, UploadPictureMixin):
class UploadMixin(UploadVideoMixin, UploadPictureMixin, UploadTexttrackMixin):
"""Handle uploading to the Vimeo API."""
pass

0 comments on commit d7a0af2

Please sign in to comment.