From a930ca0631efa5c607277b653ad0c1e07fd1f202 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Tue, 8 Jan 2019 15:27:13 -0500 Subject: [PATCH] if media type is not listed, default to a type that includes the file extension --- lbrynet/extras/daemon/Daemon.py | 4 ++-- lbrynet/extras/daemon/Publisher.py | 4 ++-- lbrynet/extras/daemon/mime_types.py | 7 ++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index a306d012d..8ea445677 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -23,7 +23,7 @@ from lbrynet.extras.daemon.Components import EXCHANGE_RATE_MANAGER_COMPONENT, PA from lbrynet.extras.daemon.ComponentManager import RequiredCondition from lbrynet.extras.daemon.Downloader import GetStream from lbrynet.extras.daemon.Publisher import Publisher -from lbrynet.extras.daemon.mime_types import guess_mime_type +from lbrynet.extras.daemon.mime_types import guess_media_type from lbrynet.extras.wallet import LbryWalletManager from lbrynet.extras.wallet.account import Account as LBCAccount from lbrynet.extras.wallet.dewies import dewies_to_lbc, lbc_to_dewies @@ -817,7 +817,7 @@ class Daemon(metaclass=JSONRPCServerType): async def _get_lbry_file_dict(self, lbry_file): key = hexlify(lbry_file.key) if lbry_file.key else None full_path = os.path.join(lbry_file.download_directory, lbry_file.file_name) - mime_type = guess_mime_type(lbry_file.file_name) + mime_type = guess_media_type(lbry_file.file_name) if os.path.isfile(full_path): with open(full_path) as written_file: written_file.seek(0, os.SEEK_END) diff --git a/lbrynet/extras/daemon/Publisher.py b/lbrynet/extras/daemon/Publisher.py index 5846cb9a4..0c5e1b545 100644 --- a/lbrynet/extras/daemon/Publisher.py +++ b/lbrynet/extras/daemon/Publisher.py @@ -3,7 +3,7 @@ import logging import os from lbrynet.blob.EncryptedFileCreator import create_lbry_file -from lbrynet.extras.daemon.mime_types import guess_mime_type +from lbrynet.extras.daemon.mime_types import guess_media_type log = logging.getLogger(__name__) @@ -43,7 +43,7 @@ class Publisher: claim_dict['stream']['source'] = {} claim_dict['stream']['source']['source'] = self.lbry_file.sd_hash claim_dict['stream']['source']['sourceType'] = 'lbry_sd_hash' - claim_dict['stream']['source']['contentType'] = guess_mime_type(file_path) + claim_dict['stream']['source']['contentType'] = guess_media_type(file_path) claim_dict['stream']['source']['version'] = "_0_0_1" # need current version here tx = await self.wallet.claim_name( self.account, name, bid, claim_dict, self.certificate, holding_address diff --git a/lbrynet/extras/daemon/mime_types.py b/lbrynet/extras/daemon/mime_types.py index ac5c96033..e2c9667cd 100644 --- a/lbrynet/extras/daemon/mime_types.py +++ b/lbrynet/extras/daemon/mime_types.py @@ -151,9 +151,6 @@ types_map = { } -fallback_mime_type = 'application/octet-stream' - - -def guess_mime_type(path): +def guess_media_type(path): _, ext = os.path.splitext(path) - return types_map.get(ext, fallback_mime_type) + return types_map.get(ext, f'application/x-ext-{ext}')