def embed_player(self): if self.player is not None: return self.player.template(self) return self.context.translate(_(u"No configured player."))
def __init__(self): self.id = "jwplayer" self.name = _(u"JWPlayer") self.resourceid = RESOURCE_ID self.template = ViewPageTemplateFile('jwplayer.pt') self.captions_info = CAPTION_REGISTRY["SRT"]
class VideoExtraDataEditForm(AutoExtensibleForm, form.EditForm): schema = IVideoExtraData def getContent(self): extra = component.queryAdapter(self.context, IVideoExtraData) if extra: extra.update() #FIXME: captions format is not saved if extra.captions_format: captions_format = extra.captions_format['id'] else: captions_format = "TTML" return {'captions': extra.captions, 'captions_format': captions_format, 'transcription': extra.transcription, 'download_url': extra.download_url} def getExtra(self): extra = component.queryAdapter(self.context, IVideoExtraData) if extra: extra.update() return extra #really strange: when adding an action, the apply one is removed. # lets add it back @button.buttonAndHandler(_z('Apply'), name='apply') def handleApply(self, action): #those weird decorator change the signature ... lets copy/paste code data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return changes = self.applyChanges(data) if changes: self.status = self.successMessage else: self.status = self.noChangesMessage def applyChanges(self, data): extra = self.getExtra() if extra: extra.transcription = data.get('transcription', '') extra.download_url = data.get('download_url', '') extra.captions_format = data.get('captions_format', '') data_captions = data.get('captions', '') if not data_captions and extra.captions: extra.captions = '' elif data_captions: extra.captions = data_captions self.request.response.redirect(self.context.absolute_url()) return True @button.buttonAndHandler(_('Update from youtube'), name='update') def handleUpdate(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return changes = self.applyUpdate(data) if changes: self.status = self.successMessage else: self.status = self.noChangesMessage def applyUpdate(self, data): extra = self.getExtra() if extra: url = self.context.getRemoteUrl() language = self.context.Language() reader = youtube.get_reader(url, language) if reader: reader.read() extra.captions = reader.rawcontent extra.captions_format = 'transcript' # force format self.request.response.redirect(self.context.absolute_url()) return True return False @button.buttonAndHandler(_('Delete'), name='delete') def handleDelete(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return changes = self.applyDelete() if changes: self.status = self.successMessage else: self.status = self.noChangesMessage def applyDelete(self): extra = self.getExtra() if extra: extra.captions = u'' extra.transcription = u'' extra.download_url = '' extra.captions_format = '' self.request.response.redirect(self.context.absolute_url()) return True return False