Exemple #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)
Exemple #2
0
 def update(self, file_path=None):
     if file_path is not None:
         self.name = os.path.basename(file_path)
         self.media_type, stream_type = guess_media_type(file_path)
         if not os.path.isfile(file_path):
             raise Exception(f"File does not exist: {file_path}")
         self.size = os.path.getsize(file_path)
         if self.size == 0:
             raise Exception(f"Cannot publish empty file: {file_path}")
         self.file_hash_bytes = calculate_sha384_file_hash(file_path)
         return stream_type
Exemple #3
0
    def update(self,
               file_path=None,
               stream_type=None,
               fee_currency=None,
               fee_amount=None,
               fee_address=None,
               **kwargs):

        duration_was_not_set = True
        sub_types = ('image', 'video', 'audio')
        for key in list(kwargs.keys()):
            for sub_type in sub_types:
                if key.startswith(f'{sub_type}_'):
                    stream_type = sub_type
                    sub_obj = getattr(self, sub_type)
                    sub_obj_attr = key[len(f'{sub_type}_'):]
                    setattr(sub_obj, sub_obj_attr, kwargs.pop(key))
                    if sub_obj_attr == 'duration':
                        duration_was_not_set = False
                    break

        if stream_type is not None:
            if stream_type not in sub_types:
                raise Exception(
                    f"stream_type of '{stream_type}' is not valid, must be one of: {sub_types}"
                )

            sub_obj = getattr(self, stream_type)
            if duration_was_not_set and file_path and isinstance(
                    sub_obj, Playable):
                sub_obj.set_duration_from_path(file_path)

        super().update(**kwargs)

        if file_path is not None:
            self.media_type = guess_media_type(file_path)
            if not os.path.isfile(file_path):
                raise Exception(f"File does not exist: {file_path}")
            self.file.size = os.path.getsize(file_path)
            if self.file.size == 0:
                raise Exception(f"Cannot publish empty file: {file_path}")

        if fee_amount and fee_currency:
            if fee_address:
                self.fee.address = fee_address
            if fee_currency.lower() == 'lbc':
                self.fee.lbc = Decimal(fee_amount)
            elif fee_currency.lower() == 'btc':
                self.fee.btc = Decimal(fee_amount)
            elif fee_currency.lower() == 'usd':
                self.fee.usd = Decimal(fee_amount)
            else:
                raise Exception(f'Unknown currency type: {fee_currency}')
Exemple #4
0
 def mime_type(self):
     return guess_media_type(
         os.path.basename(self.descriptor.suggested_file_name))[0]
Exemple #5
0
    def as_dict(self) -> typing.Dict:
        full_path = self.full_path if self.output_file_exists else None
        mime_type = guess_media_type(
            os.path.basename(self.descriptor.suggested_file_name))

        if self.downloader and self.downloader.written_bytes:
            written_bytes = self.downloader.written_bytes
        elif full_path:
            written_bytes = os.stat(full_path).st_size
        else:
            written_bytes = None
        return {
            'completed':
            self.finished,
            'file_name':
            self.file_name,
            'download_directory':
            self.download_directory,
            'points_paid':
            0.0,
            'tx':
            self.tx,
            'stopped':
            not self.running,
            'stream_hash':
            self.stream_hash,
            'stream_name':
            self.descriptor.stream_name,
            'suggested_file_name':
            self.descriptor.suggested_file_name,
            'sd_hash':
            self.descriptor.sd_hash,
            'download_path':
            full_path,
            'mime_type':
            mime_type,
            'key':
            self.descriptor.key,
            'total_bytes_lower_bound':
            self.descriptor.lower_bound_decrypted_length(),
            'total_bytes':
            self.descriptor.upper_bound_decrypted_length(),
            'written_bytes':
            written_bytes,
            'blobs_completed':
            self.blobs_completed,
            'blobs_in_stream':
            self.blobs_in_stream,
            'blobs_remaining':
            self.blobs_remaining,
            'status':
            self.status,
            'claim_id':
            self.claim_id,
            'txid':
            self.txid,
            'nout':
            self.nout,
            'outpoint':
            self.outpoint,
            'metadata':
            self.metadata,
            'channel_claim_id':
            self.channel_claim_id,
            'channel_name':
            self.channel_name,
            'claim_name':
            self.claim_name
        }
Exemple #6
0
 def test_x_ext_(self):
     self.assertEqual("application/x-ext-lbry", mime_types.guess_media_type("test.lbry"))
     self.assertEqual("application/x-ext-lbry", mime_types.guess_media_type("test.LBRY"))
Exemple #7
0
 def test_mp4_video(self):
     self.assertEqual("video/mp4", mime_types.guess_media_type("test.mp4"))
     self.assertEqual("video/mp4", mime_types.guess_media_type("test.MP4"))
Exemple #8
0
 def test_octet_stream(self):
     self.assertEqual("application/octet-stream", mime_types.guess_media_type("test."))
     self.assertEqual("application/octet-stream", mime_types.guess_media_type("test"))