Пример #1
0
class IAudio(model.Schema):

    # main file will always be converted to mp4
    form.widget(audio_file=StreamNamedFileFieldWidget)
    model.primary('audio_file')
    audio_file = namedfile.NamedBlobFile(
        title=_(u"Audio File"),
        description=u"",
        required=True,
        constraint=valid_audio
    )

    form.omitted('metadata')
    metadata = schema.Text(
        required=False
    )

    transcript = RichText(
        title=_(u"Transcript"),
        default_mime_type='text/html',
        output_mime_type='text/html',
        allowed_mime_types=('text/html', 'text/plain'),
        default=u"",
        required=False
    )
Пример #2
0
def retrieveThumbImage(video):
    """
    Try to call YouTube service to retrieve video thumbnail
    and save it in the video
    """
    video_behavior = IVideo(video)
    if not video_behavior:
        return
    video_id = video_behavior.get_youtube_id_from_url()
    if not video_id:
        return
    url = "https://i.ytimg.com/vi/%s/hqdefault.jpg" % video_id
    error_msg = _(
        'yt_image_download_error_label',
        'Unable to download thumbnail image automatically from youtube. Try later.'
    )
    try:
        res = requests.get(url, stream=True, timeout=10)
    except Timeout:
        logger.error(
            'Unable to retrieve thumbnail image for "%s": timeout.' % video_id)
        api.portal.show_message(
            message=error_msg,
            request=video.REQUEST,
            type="warning")
        return
    except Exception as e:
        logger.error('Unable to retrieve thumbnail from "%s".' % url)
        logger.exception(e)
        api.portal.show_message(
            message=error_msg,
            request=video.REQUEST,
            type="warning")
        return
    if not res.ok:
        if res.status_code == 404:
            logger.error(
                'Unable to retrieve thumbnail from "%s". Not found.' % url)
            error_msg = _(
                'yt_image_download_notfound_error_label',
                "Unable to download thumbnail image automatically from youtube. Probably it isn't available yet. Please retry in a few minutes."
            )
            api.portal.show_message(
                message=error_msg,
                request=video.REQUEST,
                type="warning")
        else:
            logger.error('Unable to retrieve thumbnail from "%s". Error: %s' % (url, res.status_code))
            api.portal.show_message(
                message=error_msg,
                request=video.REQUEST,
                type="warning")
        return
    video.image = NamedBlobImage(res.raw.data, filename=u'%s.jpg' % video_id)
    api.portal.show_message(
        message=_(
            'yt_image_download_success_label',
            'Thumbnail image correctly saved from youtube.'),
        request=video.REQUEST)
Пример #3
0
def retrieveThumbImage(video):
    """
    Try to call YouTube service to retrieve video thumbnail
    and save it in the video
    """
    video_behavior = IVideo(video)
    if not video_behavior:
        return
    video_id = video_behavior.get_youtube_id_from_url()
    if not video_id:
        return
    url = "https://i.ytimg.com/vi/%s/hqdefault.jpg" % video_id
    error_msg = _(
        'yt_image_download_error_label',
        'Unable to download thumbnail image automatically from youtube. Try later.'
    )
    try:
        res = requests.get(url, stream=True, timeout=10)
    except Timeout:
        logger.error('Unable to retrieve thumbnail image for "%s": timeout.' %
                     video_id)
        api.portal.show_message(message=error_msg,
                                request=video.REQUEST,
                                type="warning")
        return
    except Exception as e:
        logger.error('Unable to retrieve thumbnail from "%s".' % url)
        logger.exception(e)
        api.portal.show_message(message=error_msg,
                                request=video.REQUEST,
                                type="warning")
        return
    if not res.ok:
        if res.status_code == 404:
            logger.error('Unable to retrieve thumbnail from "%s". Not found.' %
                         url)
            error_msg = _(
                'yt_image_download_notfound_error_label',
                "Unable to download thumbnail image automatically from youtube. Probably it isn't available yet. Please retry in a few minutes."
            )
            api.portal.show_message(message=error_msg,
                                    request=video.REQUEST,
                                    type="warning")
        else:
            logger.error('Unable to retrieve thumbnail from "%s". Error: %s' %
                         (url, res.status_code))
            api.portal.show_message(message=error_msg,
                                    request=video.REQUEST,
                                    type="warning")
        return
    video.image = NamedBlobImage(res.raw.data, filename=u'%s.jpg' % video_id)
    api.portal.show_message(message=_(
        'yt_image_download_success_label',
        'Thumbnail image correctly saved from youtube.'),
                            request=video.REQUEST)
Пример #4
0
class IVideo(model.Schema):

    form.omitted('image')
    image = namedfile.NamedBlobImage(
        title=_(u"Cover Image"),
        description=u"",
        required=False,
    )

    # main file will always be converted to mp4
    form.widget(video_file=StreamNamedFileFieldWidget)
    model.primary('video_file')
    video_file = namedfile.NamedBlobFile(title=_(u"Video File"),
                                         description=u"",
                                         required=False,
                                         constraint=valid_video)

    form.omitted(IAddForm, 'video_file_ogv')
    form.omitted(IEditForm, 'video_file_ogv')
    form.widget(video_file_ogv=StreamNamedFileFieldWidget)
    video_file_ogv = namedfile.NamedBlobFile(required=False, )

    form.omitted(IAddForm, 'video_file_webm')
    form.omitted(IEditForm, 'video_file_webm')
    form.widget(video_file_webm=StreamNamedFileFieldWidget)
    video_file_webm = namedfile.NamedBlobFile(required=False, )

    youtube_url = schema.TextLine(
        title=_(u"Youtube URL"),
        description=_(u"Alternatively, you can provide a youtube video url. "
                      u"If this is specified, video file will be ignored."),
        required=False)

    @invariant
    def validate_videos(data):
        if not data.video_file and not data.youtube_url:
            raise Invalid("Must specify either a video file or youtube url")

    width = schema.Int(title=_(u"Width"), default=640)

    height = schema.Int(title=_(u"Height"), default=320)

    subtitle_file = namedfile.NamedBlobFile(
        title=_(u"Subtitle file"),
        description=_(u"Provide a file in srt format"),
        required=False)

    form.omitted('metadata')
    metadata = schema.Text(required=False)

    transcript = RichText(title=_(u"Transcript"),
                          default_mime_type='text/html',
                          output_mime_type='text/html',
                          allowed_mime_types=('text/html', 'text/plain'),
                          default=u"",
                          required=False)
Пример #5
0
class GlobalSettingsForm(group.GroupForm, form.EditForm):
    groups = (DefaultGroup, ConversionSettingsGroup)

    label = _(u"Media Settings")
    description = _(u'description_media_global_settings_form',
                    default=u"Configure the parameters for media.")

    @button.buttonAndHandler(pmf('Save'), name='apply')
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        self.applyChanges(data)

        self.status = pmf('Changes saved.')
Пример #6
0
class IGlobalMediaSettings(Interface):
    additional_video_formats = schema.List(
        title=_("Additional Video Formats"),
        description=_(
            'additional_video_formats_help',
            default=u"To provide better HTML5 support, different video "
            u"formats are generated via avconv (formerly ffmpeg). "
            u"If you'd prefer to save on disc space, but provide "
            u"less HTML5 support, change the additional video "
            u"formats that are generated here"),
        default=['ogg', 'webm'],
        value_type=schema.Choice(
            vocabulary=SimpleVocabulary(VIDEO_FORMATS_VOCAB)))
    async_quota_size = schema.Int(
        title=_("Async Quota Size"),
        description=_("Number of conversions to run at a time. "
                      "The quota name assigned is `wildcard.media`."),
        default=3)
Пример #7
0
class MediaViewTile(PersistentCoverTile):
    implements(IMediaViewTile)

    index = ViewPageTemplateFile('templates/mediaview.pt')

    is_configurable = True
    is_editable = True
    is_droppable = True
    short_name = _('msg_short_name_mediaview', default=u'Media View')

    def is_empty(self):
        return self.data.get('uuid', None) is None

    def populate_with_object(self, obj):
        super(MediaViewTile, self).populate_with_object(obj)

        if obj.portal_type not in self.accepted_ct():
            return

        title = safe_unicode(obj.Title())
        desc = safe_unicode(obj.Description())
        uuid = IUUID(obj)

        data_mgr = ITileDataManager(self)
        data_mgr.set({
            'title': title,
            'description': desc,
            'uuid': uuid,
        })

    def accepted_ct(self):
        return ['WildcardVideo', 'WildcardAudio']

    def media_absolute_url(self):
        uuid = self.data.get('uuid', None)
        if not uuid:
            return ''
        obj = uuidToObject(uuid)
        return obj.absolute_url()

    def media_context(self):
        uuid = self.data.get('uuid', None)
        if not uuid:
            return ''
        obj = uuidToObject(uuid)
        return obj

    def is_video(self):
        uuid = self.data.get('uuid', None)
        if not uuid:
            return ''
        obj = uuidToObject(uuid)
        return obj.portal_type == "WildcardVideo"
Пример #8
0
class IVideo(model.Schema):

    form.omitted('image')
    image = namedfile.NamedBlobImage(
        title=_(u"Cover Image"),
        description=u"",
        required=False,
    )

    # main file will always be converted to mp4
    form.widget(video_file=StreamNamedFileFieldWidget)
    model.primary('video_file')
    video_file = namedfile.NamedBlobFile(
        title=_(u"Video File"),
        description=u"",
        required=False,
        constraint=valid_video
    )

    if youtube:
        upload_video_to_youtube = schema.Bool(
            title=_(u'Upload to youtube'),
            description=_(u'Requires having youtube account connected. '
                          u'Videos that are private will remain unlisted on YouTube. '
                          u'Once published, video will be made public on YouTube. '),
            required=False,
            default=False)

    form.omitted(IAddForm, 'video_file_ogv')
    form.omitted(IEditForm, 'video_file_ogv')
    form.widget(video_file_ogv=StreamNamedFileFieldWidget)
    video_file_ogv = namedfile.NamedBlobFile(
        required=False,
    )

    form.omitted(IAddForm, 'video_file_webm')
    form.omitted(IEditForm, 'video_file_webm')
    form.widget(video_file_webm=StreamNamedFileFieldWidget)
    video_file_webm = namedfile.NamedBlobFile(
        required=False,
    )

    youtube_url = schema.TextLine(
        title=_(u"Youtube URL"),
        description=_(u"Alternatively, you can provide a youtube video url. "
                      u"If this is specified, video file will be ignored. "
                      u"If video was uploaded to youtube, this field will be filled "
                      u"with video url."),
        required=False
    )
    retrieve_thumb = schema.Bool(
        title=_(u'Retrieve original thumbnail from youtube'),
        description=_(u"If checked, try to download original thumbnail from "
                      u"youtube into this video."),
        required=False,
        default=False)

    @invariant
    def validate_videos(data):
        if not data.video_file and not data.youtube_url:
            raise Invalid("Must specify either a video file or youtube url")

    width = schema.Int(
        title=_(u"Width"),
        defaultFactory=getDefaultWidth
    )

    height = schema.Int(
        title=_(u"Height"),
        defaultFactory=getDefaultHeight
    )

    subtitle_file = namedfile.NamedBlobFile(
        title=_(u"Subtitle file"),
        description=_(u"Provide a file in srt format"),
        required=False
    )

    form.omitted('metadata')
    metadata = schema.Text(
        required=False
    )

    transcript = RichText(
        title=_(u"Transcript"),
        default_mime_type='text/html',
        output_mime_type='text/html',
        allowed_mime_types=('text/html', 'text/plain'),
        default=u"",
        required=False
    )
Пример #9
0
class IGlobalMediaSettings(Interface):
    additional_video_formats = schema.List(
        title=_("Additional Video Formats"),
        description=_('additional_video_formats_help',
                      default=u"To provide better HTML5 support, different video "
                              u"formats are generated via avconv (formerly ffmpeg). "
                              u"If you'd prefer to save on disc space, but provide "
                              u"less HTML5 support, change the additional video "
                              u"formats that are generated here"),
        default=['ogg', 'webm'],
        value_type=schema.Choice(
            vocabulary=SimpleVocabulary(VIDEO_FORMATS_VOCAB)
        )
    )
    async_quota_size = schema.Int(
        title=_("Async Quota Size"),
        description=_("Number of conversions to run at a time. "
                      "The quota name assigned is `wildcard.media`."),
        default=3)

    force = schema.Bool(
        title=_("Force video conversion"),
        description=_(
            "always_convert_help",
            default=u"Force the video through the full conversion "
                    u"process, even if it is already in the final video format."
                    u" This may be useful if you always want to transcode to a "
                    u"given video size."
        ),
        default=False,
    )

    avconv_in_mp4 = schema.TextLine(
        title=_("MP4: infile parameters"),
        description=_(
            'avconv_in_mp4_help',
            default=u"Pass optional infile parameters to aconv during the "
                    u"MP4 conversion process."
        ),
        default=u'',
        required=False,
    )

    avconv_out_mp4 = schema.TextLine(
        title=_("MP4: outfile parameters"),
        description=_(
            'avconv_out_mp4_help',
            default=u"Pass optional outfile parameters to aconv during the "
                    u"MP4 conversion process."
        ),
        default=u'',
        required=False,
    )

    avconv_in_webm = schema.TextLine(
        title=_("WebM: infile parameters"),
        description=_(
            'avconv_in_webm_help',
            default=u"Pass optional infile parameters to aconv during the "
                    u"WebM conversion process."
        ),
        default=u'',
        required=False,
    )

    avconv_out_webm = schema.TextLine(
        title=_("WebM: outfile parameters"),
        description=_(
            'avconv_out_webm_help',
            default=u"Pass optional outfile parameters to aconv during the "
                    u"WebM conversion process."
        ),
        default=u'-strict experimental',
        required=False,
    )

    avconv_in_ogg = schema.TextLine(
        title=_("OGG: infile parameters"),
        description=_(
            'avconv_in_ogg_help',
            default=u"Pass optional infile parameters to aconv during the "
                    u"OGG conversion process."
        ),
        default=u'',
        required=False,
    )

    avconv_out_ogg = schema.TextLine(
        title=_("OGG: outfile parameters"),
        description=_(
            'avconv_out_ogg_help',
            default=u"Pass optional outfile parameters to aconv during the "
                    u"OGG conversion process."
        ),
        default=u'',
        required=False,
    )


    default_video_width = schema.Int(
        title=_(u'Default video width'),
        default=720)

    default_video_height = schema.Int(
        title=_(u'Default video height'),
        default=400)