def create_cover_thumbnails(video_id, cover_filename=None): def _thumbnail(label, size): return VideoThumbnail.from_cover_image(cover_filename, video.account_id, label, size) video = Video.query.get(video_id) assert video.external_id cover_filepath = urlparse(video.thumbnails[0].url).path if cover_filename != cover_filepath.rsplit('/', 1)[-1]: current_app.logger.warning('Unexpected cover image: %d: %s: %s', video_id, cover_filename, cover_filepath) return imgdata = StringIO(download_file(media_bucket, cover_filepath)) image = Image.open(imgdata) video.thumbnails = [_thumbnail(None, image.size)] sizes = [size for size in current_app.config['COVER_THUMBNAIL_SIZES'] if size < image.size] for size, buf in resize(image, sizes, save_to_buffer='jpeg'): thumbnail = _thumbnail(str(size[0]), size) upload_file(media_bucket, urlparse(thumbnail.url).path, buf, 'image/jpeg') video.thumbnails.append(thumbnail) imgdata = buf try: ooyala_request('assets', video.external_id, 'preview_image_files', method='post', data=imgdata.getvalue()) except Exception: current_app.logger.exception('Unable to set preview image for %d (%s)', video.id, video.external_id)
def _push_profile_changes_to_dolly(account_user_id, changes="ALL"): # TODO: assert first user in account only user = AccountUser.query.get(account_user_id) account = user and user.account if account and account.dolly_user: dolly_user = dolly.DollyUser(account.dolly_user, account.dolly_token) changed = lambda f: getattr(user, f, None) and (changes == "ALL" or f in changes) image_file = lambda filename, field: StringIO( download_file(media_bucket, user.get_image_filepath(account.id, filename, field)) ) if changed("display_name"): dolly_user.set_display_name(user.display_name) if changed("description"): dolly_user.set_description(user.description) if changed("avatar_filename"): dolly_user.set_avatar_image(image_file(user.avatar_filename, "avatar")) if changed("profile_cover_filename"): dolly_user.set_profile_image(image_file(user.profile_cover_filename, "profile_cover"))