예제 #1
0
    def _import_videos(self, form):
        for video in form.import_data.videos:
            video.rockpack_curated = True
            video.category = form.category.data
        count = Video.add_videos(form.import_data.videos, form.source.data)

        if not form.channel.data and not form.user.data:
            self._set_form_data_from_source(form)

        channelid = form.channel.data
        if channelid.startswith('_new:'):
            channel = Channel.create(
                title=channelid.split(':', 1)[1],
                owner=form.user.data,
                description=form.channel_description.data,
                cover=form.cover.data,
                category=form.category.data)
            self.record_action('created', channel)
        else:
            channel = Channel.query.get_or_404(channelid)
        channel.add_videos(
            form.import_data.videos,
            form.tags.data,
            category=form.category.data,
            date_added=form.date_added.data
        )
        self.record_action('imported', channel, '%d videos' % count)
        push_config = getattr(form.import_data, 'push_config', None)
        if push_config and channel.id:
            try:
                subscribe(push_config.hub, push_config.topic, channel.id)
            except Exception, e:
                flash('Unable to subscribe to channel: %s' % e.message, 'error')