From 8d25de542f569a2d6d568a7754352c7168a7863e Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Mon, 7 Oct 2019 22:39:05 +0200 Subject: [PATCH 1/4] Improvement: use file extension if filetype.guess fails --- instapy_cli/media.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/instapy_cli/media.py b/instapy_cli/media.py index 48df57d..1925920 100644 --- a/instapy_cli/media.py +++ b/instapy_cli/media.py @@ -25,15 +25,20 @@ def __init__(self, file, ratio='post'): # if file is a local file else: self.media_path = file - + self.check_type() - + def check_type(self): - self.media_ext = filetype.guess(self.media_path).extension - + ext = filetype.guess(self.media_path) + if None is self.media_ext: + absolute_path = os.path.abspath(self.media_path) + self.media_ext = os.path.splitext(absolute_path)[-1].replace(".", "") + else: + self.media_ext = ext.extension + def is_image(self): return True if self.media_ext in ['jpg', 'png', 'gif'] else False - + def is_video(self): return True if self.media_ext in ['mp4', 'mov', 'avi'] else False From b959c682684db9e675d30dc38ede5ca2c42acc99 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Sun, 13 Oct 2019 12:59:44 +0200 Subject: [PATCH 2/4] Improvement: use file extension if filetype.guess fails --- instapy_cli/media.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/instapy_cli/media.py b/instapy_cli/media.py index 1925920..3b76659 100644 --- a/instapy_cli/media.py +++ b/instapy_cli/media.py @@ -3,6 +3,9 @@ from instagram_private_api_extensions import media as IGMedia import filetype #import urlparse for Python2 and Python3 +import logging + +log = logging.getLogger("instapy") try: from urllib.parse import urlparse except ImportError: @@ -18,6 +21,7 @@ class Media(object): isLink = False def __init__(self, file, ratio='post'): + log.info("NEW instanceof MEDIA") # if file is link if urlparse(file).scheme in ('http', 'https'): self.media_path = self.downloadMediaFromLink(file) From 5082cf390a2cf4caad4b857d07194a3ccbc107d1 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Sun, 13 Oct 2019 13:21:24 +0200 Subject: [PATCH 3/4] Improvement: use file extension if filetype.guess fails --- instapy_cli/media.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/instapy_cli/media.py b/instapy_cli/media.py index 3b76659..1925920 100644 --- a/instapy_cli/media.py +++ b/instapy_cli/media.py @@ -3,9 +3,6 @@ from instagram_private_api_extensions import media as IGMedia import filetype #import urlparse for Python2 and Python3 -import logging - -log = logging.getLogger("instapy") try: from urllib.parse import urlparse except ImportError: @@ -21,7 +18,6 @@ class Media(object): isLink = False def __init__(self, file, ratio='post'): - log.info("NEW instanceof MEDIA") # if file is link if urlparse(file).scheme in ('http', 'https'): self.media_path = self.downloadMediaFromLink(file) From 70c479c4d0456029d6022d6c51bdc4c8e4325d1a Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Sun, 13 Oct 2019 13:35:41 +0200 Subject: [PATCH 4/4] Improvement: use file extension if filetype.guess fails --- instapy_cli/cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instapy_cli/cli.py b/instapy_cli/cli.py index d80382e..0bb6a10 100644 --- a/instapy_cli/cli.py +++ b/instapy_cli/cli.py @@ -138,9 +138,10 @@ def upload(self, file, caption='', story=False): except Exception as e: - print('Error is >>\n ' + str(e)) - print('\nSomething went bad.\nPlease retry or send an issue on https://github.com/b3nab/instapy-cli\n') + # print('Error is >>\n ' + str(e)) + # print('\nSomething went bad.\nPlease retry or send an issue on https://github.com/b3nab/instapy-cli\n') upload_completed = False + raise IOError(str(e), '\nSomething went bad.\nPlease retry or send an issue on https://github.com/b3nab/instapy-cli\n') finally: # media_status = 'YES' if media.isDownloaded() else 'NO'