Ticket #5212: share_image.diff

File share_image.diff, 6.0 KB (added by Jonas Öberg, 9 years ago)

Code diff

  • mediagoblin/config_spec.ini

    diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
    index f769e4e..04519d2 100644
    a b max_height = integer(default=640)  
    144144max_width = integer(default=180)
    145145max_height = integer(default=180)
    146146
     147[media:share]
     148# Dimensions used when creating media thumbnails for social media shareing
     149max_width = integer(default=600)
     150max_height = integer(default=315)
     151
    147152[celery]
    148153# default result stuff
    149154CELERY_RESULT_BACKEND = string(default="database")
  • mediagoblin/media_types/video/processing.py

    diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py
    index a85b232..29758c9 100644
    a b class CommonVideoProcessor(MediaProcessor):  
    215215        elif keyname == 'thumb':
    216216            if kwargs.get('thumb_size') != file_metadata.get('thumb_size'):
    217217                skip = False
     218        elif keyname == 'share':
     219            if kwargs.get('share_size') != file_metadata.get('share_size'):
     220                skip = False
    218221
    219222        return skip
    220223
    class CommonVideoProcessor(MediaProcessor):  
    298301            width=dst_dimensions[0],
    299302            height=dst_dimensions[1])
    300303
    301     def generate_thumb(self, thumb_size=None):
     304    def generate_image(self, size=None, magic='thumb', fname='thumbnail'):
    302305        # Temporary file for the video thumbnail (cleaned up with workbench)
    303         tmp_thumb = os.path.join(self.workbench.dir,
     306        tmp = os.path.join(self.workbench.dir,
    304307                                 self.name_builder.fill(
    305                                      '{basename}.thumbnail.jpg'))
     308                                     '{basename}.%s.jpg' % fname))
    306309
    307         if not thumb_size:
    308             thumb_size = (mgg.global_config['media:thumb']['max_width'],)
     310        if not size:
     311            size = (mgg.global_config['media:%s' % magic]['max_width'],)
    309312
    310         if self._skip_processing('thumb', thumb_size=thumb_size):
    311             return
     313        # How can this be more clever?
     314        if magic == 'thumb':
     315            if self._skip_processing(magic, thumb_size=size):
     316                return
     317        if magic == 'share':
     318            if self._skip_processing(magic, share_size=size):
     319                return
    312320
    313321        # We will only use the width so that the correct scale is kept
    314322        transcoders.capture_thumb(
    315323            self.process_filename,
    316             tmp_thumb,
    317             thumb_size[0])
     324            tmp,
     325            size[0])
    318326
    319327        # Checking if the thumbnail was correctly created.  If it was not,
    320328        # then just give up.
    321         if not os.path.exists (tmp_thumb):
     329        if not os.path.exists (tmp):
    322330            return
    323331
    324332        # Push the thumbnail to public storage
    325         _log.debug('Saving thumbnail...')
    326         store_public(self.entry, 'thumb', tmp_thumb,
    327                      self.name_builder.fill('{basename}.thumbnail.jpg'))
     333        _log.debug('Saving image (%s)...' % magic)
     334        store_public(self.entry, magic, tmp,
     335                     self.name_builder.fill('{basename}.%s.jpg' % fname))
    328336
    329         self.entry.set_file_metadata('thumb', thumb_size=thumb_size)
     337        if magic == 'thumb':
     338            self.entry.set_file_metadata(magic, thumb_size=size)
     339        if magic == 'share':
     340            self.entry.set_file_metadata(magic, share_size=size)
    330341
    331342class InitialProcessor(CommonVideoProcessor):
    332343    """
    class InitialProcessor(CommonVideoProcessor):  
    375386            metavar=('max_width', 'max_height'),
    376387            type=int)
    377388
     389        parser.add_argument(
     390            '--share_size',
     391            nargs=2,
     392            metavar=('max_width', 'max_height'),
     393            type=int)
     394
    378395        return parser
    379396
    380397    @classmethod
    381398    def args_to_request(cls, args):
    382399        return request_from_args(
    383400            args, ['medium_size', 'vp8_quality', 'vp8_threads',
    384                    'vorbis_quality', 'thumb_size'])
     401                   'vorbis_quality', 'thumb_size', 'share_size'])
    385402
    386403    def process(self, medium_size=None, vp8_threads=None, vp8_quality=None,
    387                 vorbis_quality=None, thumb_size=None):
     404                vorbis_quality=None, thumb_size=None, share_size=None):
    388405        self.common_setup()
    389406
    390407        self.transcode(medium_size=medium_size, vp8_quality=vp8_quality,
    391408                       vp8_threads=vp8_threads, vorbis_quality=vorbis_quality)
    392409
    393410        self.copy_original()
    394         self.generate_thumb(thumb_size=thumb_size)
     411        self.generate_image(size=thumb_size)
     412        self.generate_image(size=share_size, magic='share', fname='share')
    395413        self.delete_queue_file()
    396414
    397415
    class Resizer(CommonVideoProcessor):  
    400418    Video thumbnail resizing process steps for processed media
    401419    """
    402420    name = 'resize'
    403     description = 'Resize thumbnail'
     421    description = 'Resize thumbnails and other images'
    404422    thumb_size = 'thumb_size'
     423    share_size = 'share_size'
    405424
    406425    @classmethod
    407426    def media_is_eligible(cls, entry=None, state=None):
    class Resizer(CommonVideoProcessor):  
    421440            metavar=('max_width', 'max_height'),
    422441            type=int)
    423442
     443        parser.add_argument(
     444            '--share_size',
     445            nargs=2,
     446            metavar=('max_width', 'max_height'),
     447            type=int)
     448
    424449        # Needed for gmg reprocess thumbs to work
    425450        parser.add_argument(
    426451            'file',
    class Resizer(CommonVideoProcessor):  
    433458    @classmethod
    434459    def args_to_request(cls, args):
    435460        return request_from_args(
    436             args, ['thumb_size', 'file'])
     461            args, ['thumb_size',  'share_size', 'file'])
    437462
    438     def process(self, thumb_size=None, file=None):
     463    def process(self, thumb_size=None, share_size=None, file=None):
    439464        self.common_setup()
    440         self.generate_thumb(thumb_size=thumb_size)
     465        self.generate_image(size=thumb_size)
     466        self.generate_image(size=share_size, magic='share', fname='share')
    441467
    442468
    443469class Transcoder(CommonVideoProcessor):