Esempio n. 1
0
    def delete(self, video):
        # remove the video from published collections
        for tag in video.tags:
            if tag.dolly_channel:
                get_dollyuser(current_user.account).remove_video(
                    tag.dolly_channel, dict(source_id=video.external_id))

        video.deleted = True
        return None, 204
Esempio n. 2
0
    def delete(self, video_id, tag_id):
        video = Video.query.filter_by(id=video_id, account_id=current_user.account_id).first_or_404()
        tag = VideoTag.query.filter_by(id=tag_id, account_id=current_user.account_id).first_or_404()
        tag_relation = VideoTagVideo.query.filter_by(video_id=video_id, tag_id=tag_id).first_or_404()

        if tag.dolly_channel and video.external_id:
            videodata = dict(source_id=video.external_id)
            get_dollyuser(current_user.account).remove_video(tag.dolly_channel, videodata)

        db.session.delete(tag_relation)

        return None, 204
Esempio n. 3
0
    def post(self, video):
        args = self.tag_parser.parse_args()
        tag_id = args['id']

        tag = VideoTag.query.filter_by(id=tag_id, account_id=video.account_id).first()
        if not tag:
            return dict(error='invalid_request', form_errors=dict(id=['Invalid tag id'])), 400

        if VideoTagVideo.query.filter_by(video_id=video.id, tag_id=tag.id).count():
            return None, 204

        if tag.dolly_channel and video.external_id:
            videodata = dict(source_id=video.external_id)
            instanceid = get_dollyuser(current_user.account).\
                publish_video(tag.dolly_channel, videodata)
            if video.status == 'ready':
                video.status = 'published'
                video.dolly_instance = instanceid
                if instanceid:
                    send_published_email(video.id, tag.dolly_channel, instanceid)

        video_tag_video = VideoTagVideo(video_id=video.id, tag_id=tag.id)
        db.session.add(video_tag_video)
        db.session.flush()

        return dict(href=video_tag_video.href), 201, {'Location': video_tag_video.href}
Esempio n. 4
0
    def put(self, tag):
        form = VideoTagForm(obj=tag)
        if not form.validate():
            return dict(error='invalid_request', form_errors=form.errors), 400

        tag = form.save()

        if tag.dolly_channel:
            channeldata = dict(title=tag.label, description=tag.description)
            try:
                get_dollyuser(current_user.account).update_channel(tag.dolly_channel, channeldata)
            except Exception as e:
                if hasattr(e, 'response'):
                    return e.response.json(), e.response.status_code
                else:
                    raise

        return None, 204
Esempio n. 5
0
def fixup_video_data():
    videos = {}
    for video in Video.query.filter_by(dolly_instance=None):
        channel = next((t.dolly_channel for t in video.tags if t.dolly_channel), None)
        if not channel:
            continue
        if channel not in videos:
            videos[channel] = get_dollyuser(video.account).get_channel_videos(channel)
        video.dolly_instance = next((v['id'] for v in videos[channel]
                                     if v['video']['source_id'] == video.external_id), None)
Esempio n. 6
0
    def get(self, video):
        if not video.dolly_instance:
            # Not published
            return dict(error='invalid_request'), 400

        url = get_dollyuser(video.account).get_share_link(video.dolly_instance)
        if request.args.get('target') in ('facebook', 'twitter'):
            url += '?utm_source=' + request.args['target']

        return dict(url=url), 302, {'Location': url}
Esempio n. 7
0
def _video_item(video, full=False, with_account=False, public=False):
    fields = ('id', 'status', 'date_added', 'date_updated', 'title')
    if full:
        fields += ('strapline', 'description', 'category', 'link_url', 'link_title', 'duration')
    data = {f: getattr(video, f) for f in fields}

    # Convert dates to strings:
    for f, v in data.items():
        if hasattr(v, 'isoformat'):
            data[f] = v.isoformat()

    if full:
        data['hosted_url'] = video.hosted_url
        data['search_keywords'] = video.search_keywords
        data['collaborators'] = dict(href=url_for(
            'api.videocollaborators', video_id=video.id) + '?public' if public else '')
        data['player_url'] = video.player_url
        data['player_logo_url'] = video.get_player_logo_url()
        thumbnails = sorted(video.thumbnails, key=lambda t: t.width, reverse=True)
        data['thumbnail_url'] = thumbnails[0].url if thumbnails else None
        data['thumbnails'] = dict(
            items=[
                {f: getattr(thumbnail, f) for f in ('url', 'width', 'height')}
                for thumbnail in thumbnails
            ]
        )
    else:
        data['thumbnail_url'] = video.thumbnail
        data['thumbnails'] = dict(
            items=[
                {'url': video.thumbnail, 'width': 0, 'height': 0}
            ] if video.thumbnail else []
        )

    if public:
        data['href'] = video.public_href
    else:
        data['href'] = video.href
        data['tags'] = dict(
            href=url_for('api.videotags', video_id=video.id),
            items=map(_tag_item, video.tags),
        )

    if with_account:
        data['account'] = account_item(video.account, get_dollyuser(video.account),
                                       full=False, public=public)

    return data
Esempio n. 8
0
 def delete(self, tag):
     if tag.dolly_channel:
         get_dollyuser(current_user.account).delete_channel(tag.dolly_channel)
     db.session.delete(tag)
     return None, 204