예제 #1
0
    def update(self, file_path=None, height=None, width=None, duration=None, **kwargs):
        self.fee.update(
            kwargs.pop('fee_address', None),
            kwargs.pop('fee_currency', None),
            kwargs.pop('fee_amount', None)
        )

        if 'sd_hash' in kwargs:
            self.source.sd_hash = kwargs.pop('sd_hash')

        stream_type = None
        if file_path is not None:
            stream_type = self.source.update(file_path=file_path)
        elif self.source.name:
            self.source.media_type, stream_type = guess_media_type(self.source.name)
        elif self.source.media_type:
            stream_type = guess_stream_type(self.source.media_type)

        if stream_type in ('image', 'video', 'audio'):
            media = getattr(self, stream_type)
            media_args = {'file_metadata': None}
            try:
                media_args['file_metadata'] = binary_file_metadata(binary_file_parser(file_path))
            except:
                log.exception('Could not read file metadata.')
            if isinstance(media, Playable):
                media_args['duration'] = duration
            if isinstance(media, Dimmensional):
                media_args['height'] = height
                media_args['width'] = width
            media.update(**media_args)

        super().update(**kwargs)
예제 #2
0
    def update(self,
               file_path=None,
               height=None,
               width=None,
               duration=None,
               **kwargs):

        if kwargs.pop('clear_fee', False):
            self.message.ClearField('fee')
        else:
            self.fee.update(kwargs.pop('fee_address', None),
                            kwargs.pop('fee_currency', None),
                            kwargs.pop('fee_amount', None))

        self.none_check(kwargs)

        if 'sd_hash' in kwargs:
            self.source.sd_hash = kwargs.pop('sd_hash')
        elif 'bt_infohash' in kwargs:
            self.source.bt_infohash = kwargs.pop('bt_infohash')
        if 'file_name' in kwargs:
            self.source.name = kwargs.pop('file_name')
        if 'file_hash' in kwargs:
            self.source.file_hash = kwargs.pop('file_hash')

        stream_type = None
        if file_path is not None:
            stream_type = self.source.update(file_path=file_path)
        elif self.source.name:
            self.source.media_type, stream_type = guess_media_type(
                self.source.name)
        elif self.source.media_type:
            stream_type = guess_stream_type(self.source.media_type)

        if 'file_size' in kwargs:
            self.source.size = kwargs.pop('file_size')

        if self.stream_type is not None and self.stream_type != stream_type:
            self.message.ClearField(self.stream_type)

        if stream_type in ('image', 'video', 'audio'):
            media = getattr(self, stream_type)
            media_args = {'file_metadata': None}
            if file_path is not None and not all((duration, width, height)):
                try:
                    media_args['file_metadata'] = binary_file_metadata(
                        binary_file_parser(file_path))
                except:
                    log.exception('Could not read file metadata.')
            if isinstance(media, Playable):
                media_args['duration'] = duration
            if isinstance(media, Dimmensional):
                media_args['height'] = height
                media_args['width'] = width
            media.update(**media_args)

        super().update(**kwargs)
예제 #3
0
파일: claim.py 프로젝트: xuanduoc84/lbry
 def set_duration_from_path(self, file_path):
     try:
         file_metadata = binary_file_metadata(binary_file_parser(file_path))
         self.duration = file_metadata.getValues('duration')[0].seconds
     except:
         pass