Skip to content

Commit

Permalink
webhooks: use closest aspect ratio to transcode
Browse files Browse the repository at this point in the history
* When calling running the transcode task it can happen that the aspect
  ratio is not in the list and therefore needs to be change by the
  closest one.
  NOTE: this is a hack until CERNDocumentServer/cds-sorenson#37 is
  fixed.
  • Loading branch information
egabancho committed Feb 6, 2018
1 parent 4c5de22 commit e0a3907
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cds/modules/webhooks/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of CERN Document Server.
# Copyright (C) 2016, 2017 CERN.
# Copyright (C) 2016, 2017, 2018 CERN.
#
# CERN Document Server is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -36,8 +36,8 @@

import jsonpatch
import requests
from cds_sorenson.api import (get_encoding_status, get_preset_info,
start_encoding, stop_encoding)
from cds_sorenson.api import (get_closest_aspect_ratio, get_encoding_status,
get_preset_info, start_encoding, stop_encoding)
from cds_sorenson.error import InvalidResolutionError, TooHighResolutionError
from celery import current_app as celery_app
from celery import Task, shared_task
Expand Down Expand Up @@ -580,11 +580,14 @@ def run(self, preset_quality, sleep_time=5, *args, **kwargs):
master_key = self.object.key

tags = self.object.get_tags()
# Get master file's aspect ratio
aspect_ratio = tags['display_aspect_ratio']
# Get master file's width x height
width = int(tags['width']) if 'width' in tags else None
height = int(tags['height']) if 'height' in tags else None
# Get master file's aspect ratio
aspect_ratio = tags['display_aspect_ratio']
# HACK: correct aspect ratio in case not in the list
if width is not None and height is not None:
aspect_ratio = get_closest_aspect_ratio(width, height)

with db.session.begin_nested():
# Create FileInstance
Expand Down

0 comments on commit e0a3907

Please sign in to comment.